Wechat.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * ============================================================================
  12. * 数据层模型
  13. */
  14. class Wechat extends BaseModel
  15. {
  16. public $page_info;
  17. public $wxconfig;
  18. public $error_message = '';
  19. public $error_code = 0;
  20. /**
  21. * 获取公众号配置信息
  22. * @access public
  23. * @author csdeshang
  24. * @return type
  25. */
  26. public function getOneWxconfig()
  27. {
  28. $this->wxconfig = Db::name('wxconfig')->where('1=1')->find();
  29. return $this->wxconfig;
  30. }
  31. /**
  32. * 增加微信配置
  33. * @access public
  34. * @author csdeshang
  35. */
  36. public function addWxconfig($data)
  37. {
  38. return Db::name('wxconfig')->insert($data);
  39. }
  40. /**
  41. * 编辑微信配置
  42. * @access public
  43. * @author csdeshang
  44. */
  45. public function editWxconfig($condition, $data)
  46. {
  47. return Db::name('wxconfig')->where($condition)->update($data);
  48. }
  49. /**
  50. * 获取微信菜单列表
  51. * @access public
  52. * @author csdeshang
  53. */
  54. public function getWxmenuList($condition, $order = 'id asc', $field = '*')
  55. {
  56. return Db::name('wxmenu')->field($field)->where($condition)->order($order)->select()->toArray();
  57. }
  58. /**
  59. * 关键字查询
  60. * @access public
  61. * @author csdeshang
  62. * @param type $field 字段
  63. * @param type $wh 条件
  64. * @param type $order 排序
  65. * @return type
  66. */
  67. public function getOneJoinWxkeyword($condition, $field = '', $order = 't.createtime DESC')
  68. {
  69. $condition[] = array('k.type', '=', 'TEXT');
  70. $lists = Db::name('wxkeyword')->alias('k')->join('wxtext t', 't.id=k.pid', 'LEFT')->where($condition)->field($field)->order($order)->find();
  71. return $lists;
  72. }
  73. /**
  74. * 获取单个关键词回复
  75. * @param type $condition
  76. * @return type
  77. */
  78. public function getOneWxkeyword($condition)
  79. {
  80. return Db::name('wxkeyword')->where($condition)->find();
  81. }
  82. /**
  83. * 获取关键词回复列表
  84. * @param type $condition
  85. * @param type $field
  86. * @param type $pagesize
  87. * @param type $order
  88. * @return type
  89. */
  90. public function getWxkeywordList($condition, $field = '*', $pagesize = '', $order = 't.createtime DESC')
  91. {
  92. if ($pagesize) {
  93. $lists = Db::name('wxkeyword')->alias('k')->join('wxtext t', 't.id=k.pid', 'LEFT')->where($condition)->field($field)->order($order)->paginate(['list_rows' => 10, 'query' => request()->param()], false);
  94. $this->page_info = $lists;
  95. return $lists->items();
  96. } else {
  97. return $lists = Db::name('wxkeyword')->alias('k')->join('wxtext t', 't.id=k.pid', 'LEFT')->where($condition)->field($field)->order($order)->select()->toArray();
  98. }
  99. }
  100. /**
  101. * 新增关键词回复
  102. * @param type $add
  103. * @return type
  104. */
  105. public function addWxkeyword($add)
  106. {
  107. return Db::name('wxkeyword')->insert($add);
  108. }
  109. /**
  110. * 编辑关键词回复
  111. * @param type $condition
  112. * @param type $data
  113. * @return type
  114. */
  115. public function editWxkeyword($condition, $data)
  116. {
  117. return Db::name('wxkeyword')->where($condition)->update($data);
  118. }
  119. /**
  120. * 删除关键词回复
  121. * @param type $condition
  122. * @return type
  123. */
  124. public function delWxkeyword($condition)
  125. {
  126. return Db::name('wxkeyword')->where($condition)->delete();
  127. }
  128. /**
  129. * 新增文本回复
  130. * @param array $add
  131. * @return type
  132. */
  133. public function addWxtext($add)
  134. {
  135. return Db::name('wxtext')->insertGetId($add);
  136. }
  137. /**
  138. * 编辑文本回复
  139. * @param type $condition
  140. * @param type $data
  141. * @return type
  142. */
  143. public function editWxtext($condition, $data)
  144. {
  145. return Db::name('wxtext')->where($condition)->update($data);
  146. }
  147. /**
  148. * 删除文本回复
  149. * @param type $condition
  150. * @return type
  151. */
  152. public function delWxtext($condition)
  153. {
  154. return Db::name('wxtext')->where($condition)->delete();
  155. }
  156. /**
  157. * 会员查询
  158. * @access public
  159. * @author csdeshang
  160. * @return type
  161. */
  162. public function getWxmemberList()
  163. {
  164. $info = Db::name('member')->where('member_wxinfo', 'not null')->where('member_wxopenid', '<>', '')->where('member_wxunionid', '<>', '')->field('member_name,member_addtime,member_wxunionid,member_wxopenid,member_wxinfo,member_id')->paginate(['list_rows' => 8, 'query' => request()->param()], false);
  165. $this->page_info = $info;
  166. return $info->items();
  167. }
  168. /**
  169. * 增加
  170. * @access public
  171. * @author csdeshang
  172. * @param type $data 数据
  173. * @return type
  174. */
  175. public function addWxmsg($data)
  176. {
  177. Db::name('wxmsg')->insertGetId($data);
  178. }
  179. /**
  180. * 获取列表
  181. * @access public
  182. * @author csdeshang
  183. * @param type $where 条件
  184. * @return type
  185. */
  186. public function getWxmsgList($where = '')
  187. {
  188. $res = Db::name('wxmsg')->alias('w')->join('member m', 'w.member_id=m.member_id', 'LEFT')->where($where)->field('w.*,m.member_name')->order('createtime DESC')->paginate(['list_rows' => 10, 'query' => request()->param()], false);
  189. $this->page_info = $res;
  190. return $res->items();
  191. }
  192. /**
  193. * 删除消息推送
  194. * @param type $condition
  195. * @return type
  196. */
  197. public function delWxmsg($condition)
  198. {
  199. return Db::name('wxmsg')->where($condition)->delete();
  200. }
  201. /**
  202. * 获取单个微信菜单
  203. * @param type $condition
  204. * @return type
  205. */
  206. public function getOneWxmenu($condition)
  207. {
  208. return Db::name('wxmenu')->where($condition)->find();
  209. }
  210. /**
  211. * 获取微信菜单数量
  212. * @param type $condition
  213. * @return type
  214. */
  215. public function getWxmenuCount($condition)
  216. {
  217. return Db::name('wxmenu')->where($condition)->count();
  218. }
  219. /**
  220. * 编辑微信菜单
  221. * @param type $condition
  222. * @param type $data
  223. * @return type
  224. */
  225. public function editWxmenu($condition, $data)
  226. {
  227. return Db::name('wxmenu')->where($condition)->update($data);
  228. }
  229. /**
  230. * 新增微信菜单
  231. * @param type $data
  232. * @return type
  233. */
  234. public function addWxmenu($data)
  235. {
  236. return Db::name('wxmenu')->insert($data);
  237. }
  238. /**
  239. * 删除微信菜单
  240. * @param type $condition
  241. * @return type
  242. */
  243. public function delWxmenu($condition)
  244. {
  245. return Db::name('wxmenu')->where($condition)->delete();
  246. }
  247. /**
  248. * 获取微信菜单列表
  249. * @param type $condition
  250. * @return type
  251. */
  252. public function getMenulist($condition)
  253. {
  254. return Db::name('wxmenu')->where($condition)->select()->toArray();
  255. }
  256. //校验AccessToken 是否可用及返回新的
  257. public function getAccessToken($from = '', $force = 0)
  258. {
  259. if ($from == 'miniprogram') {
  260. $expires_in = $this->wxconfig['xcx_expires_in'];
  261. $appid = $this->wxconfig['xcx_appid'];
  262. $appsecret = $this->wxconfig['xcx_appsecret'];
  263. $access_token = $this->wxconfig['xcx_access_token'];
  264. } else {
  265. $expires_in = $this->wxconfig['expires_in'];
  266. $appid = $this->wxconfig['appid'];
  267. $appsecret = $this->wxconfig['appsecret'];
  268. $access_token = $this->wxconfig['access_token'];
  269. }
  270. //token过期,重新拉去
  271. if ($expires_in < TIMESTAMP + 7200) {
  272. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
  273. $res = json_decode(http_request($url));
  274. if (isset($res->access_token)) {
  275. $access_token = $res->access_token;
  276. $this->error_message = '';
  277. $this->error_code = 0;
  278. $expire_time = TIMESTAMP + 7000;
  279. if ($from == 'miniprogram') {
  280. $data = array('xcx_access_token' => $access_token, 'xcx_expires_in' => $expire_time);
  281. } else {
  282. $data = array('access_token' => $access_token, 'expires_in' => $expire_time);
  283. }
  284. Db::name('wxconfig')->where(array('id' => $this->wxconfig['id']))->update($data);
  285. } else {
  286. $this->error_message = $res->errmsg;
  287. $this->error_code = $res->errcode;
  288. }
  289. }
  290. return $access_token;
  291. }
  292. function getMiniProCode($scene, $page = 'pages/index/index')
  293. {
  294. $accessToken = $this->getAccessToken('miniprogram', 0);
  295. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $accessToken;
  296. $data = http_request($url, 'POST', json_encode(array(
  297. 'scene' => $scene,
  298. 'page' => $page,
  299. )));
  300. if (isset($data->errcode) && $data->errcode == '42001') {
  301. $accessToken = $this->getAccessToken('miniprogram', 0);
  302. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $accessToken;
  303. $data = http_request($url, 'POST', json_encode(array(
  304. 'scene' => $scene,
  305. 'page' => $page,
  306. )));
  307. }
  308. return $data;
  309. }
  310. function getJsapiTicket()
  311. {
  312. $ticket = $this->wxconfig['ticket'];
  313. if ($this->wxconfig['ticket_expires_in'] < TIMESTAMP) {
  314. $accessToken = $this->getAccessToken();
  315. $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" . $accessToken . "&type=jsapi";
  316. $data = http_request($url);
  317. $data = json_decode($data, true);
  318. if (isset($data['ticket'])) {
  319. Db::name('wxconfig')->where(array('id' => $this->wxconfig['id']))->update(array('ticket' => $data['ticket'], 'ticket_expires_in' => (TIMESTAMP + $data['expires_in'])));
  320. $ticket = $data['ticket'];
  321. } else {
  322. $this->error_message = $data['errmsg'];
  323. $this->error_code = $data['errcode'];
  324. }
  325. }
  326. return $ticket;
  327. }
  328. public function getSignPackage($url = '')
  329. {
  330. $jsapiTicket = $this->getJsapiTicket();
  331. // 注意 URL 一定要动态获取,不能 hardcode.
  332. $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
  333. if (!$url) {
  334. $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  335. }
  336. $timestamp = TIMESTAMP;
  337. $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  338. $nonceStr = "";
  339. for ($i = 0; $i < 16; $i++) {
  340. $nonceStr .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
  341. }
  342. // 这里参数的顺序要按照 key 值 ASCII 码升序排序
  343. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  344. $signature = sha1($string);
  345. $signPackage = array(
  346. "appId" => $this->wxconfig['appid'],
  347. "nonceStr" => $nonceStr,
  348. "timestamp" => $timestamp,
  349. "url" => $url,
  350. "signature" => $signature,
  351. "rawString" => $string
  352. );
  353. return $signPackage;
  354. }
  355. /**
  356. * 发送模板消息
  357. * @param type $accessToken
  358. * @param type $openid
  359. * @param type $template_id
  360. * @param type $url
  361. * @param type $data
  362. * @param type $topcolor
  363. */
  364. function sendMessageTemplate($openid, $template_id, $url, $data, $topcolor = '#333')
  365. {
  366. $accessToken = $this->getAccessToken();
  367. if ($this->error_code) {
  368. return ds_callback(false, $this->error_message);
  369. }
  370. $template = array(
  371. 'touser' => $openid,
  372. 'template_id' => $template_id,
  373. 'url' => $url,
  374. 'topcolor' => $topcolor,
  375. 'data' => $data
  376. );
  377. $json_template = json_encode($template);
  378. $post_url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $accessToken;
  379. $dataRes = http_request($post_url, 'POST', $json_template);
  380. $dataRes = json_decode($dataRes, true);
  381. if ($dataRes['errcode'] == 0) {
  382. return ds_callback(true);
  383. } else {
  384. return ds_callback(false, $dataRes['errmsg']);
  385. }
  386. }
  387. /*
  388. * 新增临时素材
  389. * @param type $type 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)
  390. * @param type $type 文件路径
  391. * @param type $type 文件类型
  392. * @param type $type 文件名称
  393. */
  394. function uploadMedia($type, $file_path, $file_tpe, $file_name)
  395. {
  396. $accessToken = $this->getAccessToken('miniprogram', 0);
  397. if ($this->error_code) {
  398. return ds_callback(false, $this->error_message);
  399. }
  400. // 创建一个 CURLFile 对象
  401. $cfile = curl_file_create($file_path, $file_tpe, $file_name);
  402. // 设置 POST 数据
  403. $param = array(
  404. 'media' => $cfile,
  405. );
  406. $url = 'https://api.weixin.qq.com/cgi-bin/media/upload?access_token=' . $accessToken . '&type=' . $type;
  407. $oCurl = curl_init();
  408. curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
  409. curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
  410. curl_setopt($oCurl, CURLOPT_URL, $url);
  411. curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
  412. curl_setopt($oCurl, CURLOPT_POST, true);
  413. curl_setopt($oCurl, CURLOPT_POSTFIELDS, $param);
  414. $sContent = curl_exec($oCurl);
  415. $aStatus = curl_getinfo($oCurl);
  416. curl_close($oCurl);
  417. $res = json_decode($sContent, true);
  418. if (isset($res['errcode']) && $res['errcode']) {
  419. return ds_callback(false, $res['errmsg']);
  420. } else {
  421. return ds_callback(true, '', $res['media_id']);
  422. }
  423. }
  424. function addMaterial($template)
  425. {
  426. $accessToken = $this->getAccessToken();
  427. if ($this->error_code) {
  428. return ds_callback(false, $this->error_message);
  429. }
  430. $json_template = json_encode($template);
  431. $post_url = "https://api.weixin.qq.com/cgi-bin/draft/add?access_token=" . $accessToken;
  432. $dataRes = http_request($post_url, 'POST', $json_template);
  433. $dataRes = json_decode($dataRes, true);
  434. if (!isset($dataRes['errcode']) || !$dataRes['errcode']) {
  435. return ds_callback(true, '', $dataRes['media_id']);
  436. } else {
  437. return ds_callback(false, $dataRes['errmsg']);
  438. }
  439. }
  440. function uploadMaterialImage($file, $media_type = 1)
  441. {
  442. $accessToken = $this->getAccessToken();
  443. if ($this->error_code) {
  444. return ds_callback(false, $this->error_message);
  445. }
  446. // 创建一个 CURLFile 对象
  447. $cfile = curl_file_create($file['tmp_name'], $file['type'], $file['name']);
  448. switch ($media_type) {
  449. case 1:
  450. $param = array(
  451. 'media' => $cfile,
  452. );
  453. $url = 'https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=' . $accessToken . '&type=image';
  454. break;
  455. case 2:
  456. $param = array(
  457. 'media' => $cfile,
  458. );
  459. $url = 'https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=' . $accessToken;
  460. break;
  461. }
  462. $oCurl = curl_init();
  463. curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
  464. curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
  465. curl_setopt($oCurl, CURLOPT_URL, $url);
  466. curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
  467. curl_setopt($oCurl, CURLOPT_POST, true);
  468. curl_setopt($oCurl, CURLOPT_POSTFIELDS, $param);
  469. $sContent = curl_exec($oCurl);
  470. $aStatus = curl_getinfo($oCurl);
  471. curl_close($oCurl);
  472. $res = json_decode($sContent, true);
  473. if (!isset($res['errcode']) || !$res['errcode']) {
  474. return ds_callback(true, '', $res);
  475. } else {
  476. return ds_callback(false, $res['errmsg']);
  477. }
  478. }
  479. function editMaterial($template)
  480. {
  481. $accessToken = $this->getAccessToken();
  482. if ($this->error_code) {
  483. return ds_callback(false, $this->error_message);
  484. }
  485. $json_template = json_encode($template);
  486. $post_url = "https://api.weixin.qq.com/cgi-bin/draft/update?access_token=" . $accessToken;
  487. $dataRes = http_request($post_url, 'POST', $json_template);
  488. $dataRes = json_decode($dataRes, true);
  489. if (!isset($dataRes['errcode']) || !$dataRes['errcode']) {
  490. return ds_callback(true);
  491. } else {
  492. return ds_callback(false, $dataRes['errmsg']);
  493. }
  494. }
  495. function getMaterialInfo($media_id)
  496. {
  497. $accessToken = $this->getAccessToken();
  498. if ($this->error_code) {
  499. return ds_callback(false, $this->error_message);
  500. }
  501. $template = array(
  502. 'media_id' => $media_id
  503. );
  504. $json_template = json_encode($template);
  505. $post_url = "https://api.weixin.qq.com/cgi-bin/draft/get?access_token=" . $accessToken;
  506. $dataRes = http_request($post_url, 'POST', $json_template);
  507. $dataRes = json_decode($dataRes, true);
  508. if (!isset($dataRes['errcode']) || !$dataRes['errcode']) {
  509. return ds_callback(true, '', $dataRes);
  510. } else {
  511. return ds_callback(false, $dataRes['errmsg']);
  512. }
  513. }
  514. function getImage($media_id)
  515. {
  516. $accessToken = $this->getAccessToken();
  517. if ($this->error_code) {
  518. return ds_callback(false, $this->error_message);
  519. }
  520. $template = array(
  521. 'media_id' => $media_id
  522. );
  523. $json_template = json_encode($template);
  524. $post_url = "https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=" . $accessToken;
  525. $dataRes = http_request($post_url, 'POST', $json_template);
  526. return $dataRes;
  527. }
  528. function getMaterialList($template)
  529. {
  530. $accessToken = $this->getAccessToken();
  531. if ($this->error_code) {
  532. return ds_callback(false, $this->error_message);
  533. }
  534. $json_template = json_encode($template);
  535. $post_url = "https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token=" . $accessToken;
  536. $dataRes = http_request($post_url, 'POST', $json_template);
  537. $dataRes = json_decode($dataRes, true);
  538. if (!isset($dataRes['errcode']) || !$dataRes['errcode']) {
  539. return ds_callback(true, '', $dataRes);
  540. } else {
  541. return ds_callback(false, $dataRes['errmsg']);
  542. }
  543. }
  544. function delMaterial($media_id)
  545. {
  546. $accessToken = $this->getAccessToken();
  547. if ($this->error_code) {
  548. return ds_callback(false, $this->error_message);
  549. }
  550. $template = array(
  551. 'media_id' => $media_id
  552. );
  553. $json_template = json_encode($template);
  554. $post_url = "https://api.weixin.qq.com/cgi-bin/draft/delete?access_token=" . $accessToken;
  555. $dataRes = http_request($post_url, 'POST', $json_template);
  556. $dataRes = json_decode($dataRes, true);
  557. if (!isset($dataRes['errcode']) || !$dataRes['errcode']) {
  558. return ds_callback(true);
  559. } else {
  560. return ds_callback(false, $dataRes['errmsg']);
  561. }
  562. }
  563. function submitFreepublish($media_id)
  564. {
  565. $accessToken = $this->getAccessToken();
  566. if ($this->error_code) {
  567. return ds_callback(false, $this->error_message);
  568. }
  569. $template = array(
  570. 'media_id' => $media_id
  571. );
  572. $json_template = json_encode($template);
  573. $post_url = "https://api.weixin.qq.com/cgi-bin/freepublish/submit?access_token=" . $accessToken;
  574. $dataRes = http_request($post_url, 'POST', $json_template);
  575. $dataRes = json_decode($dataRes, true);
  576. if (!isset($dataRes['errcode']) || !$dataRes['errcode']) {
  577. return ds_callback(true);
  578. } else {
  579. return ds_callback(false, $dataRes['errmsg']);
  580. }
  581. }
  582. function delFreepublish($template)
  583. {
  584. $accessToken = $this->getAccessToken();
  585. if ($this->error_code) {
  586. return ds_callback(false, $this->error_message);
  587. }
  588. $template = array(
  589. 'article_id' => $article_id
  590. );
  591. $json_template = json_encode($template);
  592. $post_url = "https://api.weixin.qq.com/cgi-bin/freepublish/delete?access_token=" . $accessToken;
  593. $dataRes = http_request($post_url, 'POST', $json_template);
  594. $dataRes = json_decode($dataRes, true);
  595. if (!isset($dataRes['errcode']) || !$dataRes['errcode']) {
  596. return ds_callback(true, '', $dataRes);
  597. } else {
  598. return ds_callback(false, $dataRes['errmsg']);
  599. }
  600. }
  601. function getFreepublishList($template)
  602. {
  603. $accessToken = $this->getAccessToken();
  604. if ($this->error_code) {
  605. return ds_callback(false, $this->error_message);
  606. }
  607. $json_template = json_encode($template);
  608. $post_url = "https://api.weixin.qq.com/cgi-bin/freepublish/batchget?access_token=" . $accessToken;
  609. $dataRes = http_request($post_url, 'POST', $json_template);
  610. $dataRes = json_decode($dataRes, true);
  611. if (!isset($dataRes['errcode']) || !$dataRes['errcode']) {
  612. return ds_callback(true, '', $dataRes);
  613. } else {
  614. return ds_callback(false, $dataRes['errmsg']);
  615. }
  616. }
  617. function getFreepublishInfo($article_id)
  618. {
  619. $accessToken = $this->getAccessToken();
  620. if ($this->error_code) {
  621. return ds_callback(false, $this->error_message);
  622. }
  623. $template = array(
  624. 'article_id' => $article_id
  625. );
  626. $json_template = json_encode($template);
  627. $post_url = "https://api.weixin.qq.com/cgi-bin/freepublish/getarticle?access_token=" . $accessToken;
  628. $dataRes = http_request($post_url, 'POST', $json_template);
  629. $dataRes = json_decode($dataRes, true);
  630. if (!isset($dataRes['errcode']) || !$dataRes['errcode']) {
  631. return ds_callback(true, '', $dataRes);
  632. } else {
  633. return ds_callback(false, $dataRes['errmsg']);
  634. }
  635. }
  636. }