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