Wechat.php 23 KB

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