Wechat.php 23 KB

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