WxOpenController.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <?php
  2. namespace saas\controllers;
  3. use biz\merchant\services\MerchantExtendService;
  4. use biz\merchant\services\MerchantService;
  5. use biz\wx\services\MiniProgramService;
  6. use biz\wx\services\WxBaseService;
  7. use biz\wx\services\WxMiniBaseService;
  8. use common\components\util;
  9. use Yii;
  10. use common\components\wxUtil;
  11. use biz\ad\classes\AdClass;
  12. use biz\merchant\classes\MerchantExtendClass;
  13. use biz\wx\classes\WxBaseClass;
  14. use biz\wx\services\WxOpenService;
  15. use common\services\xhMerchantExtendService;
  16. use common\services\xhMerchantService;
  17. use common\services\xhInviteService;
  18. use common\components\configDict;
  19. use common\services\xhWxOpenService;
  20. class WxOpenController extends PublicController
  21. {
  22. public $withoutLogin = ['bind-open'];
  23. public function actionBindOpen()
  24. {
  25. $merchantId = Yii::$app->request->get('merchantId', 0);
  26. $isOpen = Yii::$app->request->get('isOpen', 0);
  27. if ($isOpen == 1) {
  28. $merchant = WxOpenService::getWxInfo();
  29. } else {
  30. $merchant = MerchantService::getMerchantById($merchantId);
  31. if (empty($merchant)) {
  32. util::fail('没有找到商家');
  33. }
  34. }
  35. $wxAppId = $merchant['wxAppId'];
  36. $miniAppId = $merchant['miniAppId'];
  37. $open_appid = $merchant['openAppId'];
  38. echo "<pre>";
  39. //小程序入口路径
  40. $firstPage = $isOpen == 1 ? "admin/home/console" : "pages/home/index";
  41. $id = Yii::$app->request->get('id', 0);
  42. //创建平台,并将公众号绑定到平台
  43. if ($id == 1) {
  44. wxUtil::createOpenAccount($wxAppId, $merchant, $isOpen);
  45. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
  46. print_r($return);
  47. if ($return['errcode'] == 0) {
  48. $openAppId = $return['open_appid'];
  49. if ($isOpen == 1) {
  50. WxOpenService::updateOpen(['appIdCreated' => $openAppId, 'openAppBind' => 1]);
  51. } else {
  52. MerchantService::updateById($merchantId, ['openAppId' => $openAppId]);
  53. MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppId' => $openAppId, 'openAppBind' => 1, 'wxAuth' => 1]);
  54. }
  55. }
  56. }
  57. //将小程序绑定到平台
  58. if ($id == 2) {
  59. $openAppId = $merchant['openAppId'];
  60. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true, $isOpen);
  61. if ($isOpen == 1) {
  62. WxOpenService::updateOpen(['appIdCreated' => $openAppId, 'openAppBind' => 3]);
  63. } else {
  64. MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppBind' => 3, 'miniAuth' => 1]);
  65. }
  66. print_r($r);
  67. }
  68. //查询公众号 小程序的绑定情况
  69. if ($id == 3) {
  70. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
  71. print_r($return);
  72. $return = wxUtil::getOpenAccount($miniAppId, $merchant, true, $isOpen);
  73. print_r($return);
  74. }
  75. //设置小程序服务器域名
  76. if ($id == 4) {
  77. wxUtil::setDomain($merchant, $isOpen);
  78. wxUtil::setWebViewDomain($merchant, $isOpen);
  79. }
  80. //为授权的小程序帐号上传小程序代码
  81. if ($id == 5) {
  82. $tId = $_GET['tId'];
  83. wxUtil::miniCommit($merchant, $tId, $isOpen);
  84. }
  85. //获取小程序体验码
  86. if ($id == 6) {
  87. wxUtil::getExperienceQrCode($merchant, $firstPage, $isOpen);
  88. }
  89. //获取授权小程序帐号已设置的类目
  90. if ($id == 7) {
  91. wxUtil::getMiniCategory($merchant, $isOpen);
  92. }
  93. //获取小程序的第三方提交代码的页面配置
  94. if ($id == 8) {
  95. wxUtil::getMiniPage($merchant, $isOpen);
  96. }
  97. //将第三方提交的代码包提交审核
  98. if ($id == 9) {
  99. wxUtil::miniSubmitAudit($merchant, $firstPage, $isOpen);
  100. }
  101. //查询最新一次提交的审核状态
  102. if ($id == 10) {
  103. wxUtil::miniGetLatestAuditStatus($merchant, $isOpen);
  104. }
  105. //发布已通过审核的小程序
  106. if ($id == 11) {
  107. $r = MiniProgramService::release($merchant, $isOpen);
  108. print_r($r);
  109. }
  110. //撤回审核
  111. if ($id == 12) {
  112. wxUtil::rollbackCheck($merchant, $isOpen);
  113. }
  114. //生成 申请会员页 的小程序码
  115. if ($id == 13) {
  116. //wxUtil::generateMemberCode($merchant,$shopId ,$isOpen);
  117. }
  118. //解绑小程序和公众号绑定的平台
  119. if ($id == 14) {
  120. wxUtil::unbindAccount($merchant, $isOpen);
  121. wxUtil::unbindMiniProgram($merchant, $isOpen);
  122. }
  123. if ($id = 15) {
  124. //审核单ID
  125. $checkId = Yii::$app->request->get('checkId', 0);
  126. if (!empty($checkId)) {
  127. wxUtil::speedupAudit($merchant, $checkId, $isOpen);
  128. }
  129. }
  130. Yii::$app->end();
  131. $r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant, true, $isOpen);
  132. print_r($r);
  133. echo $miniAppId . ' ' . $open_appid . ' ';
  134. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
  135. print_r($return);
  136. die;
  137. $return = wxUtil::createOpenAccount($wxAppId, $merchant);
  138. print_r($return);
  139. die;
  140. $r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant, false, $isOpen);
  141. print_r($r);
  142. echo $miniAppId . ' ' . $open_appid . ' ';
  143. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
  144. print_r($return);
  145. $return = wxUtil::getOpenAccount($miniAppId, $merchant, false, $isOpen);
  146. print_r($return);
  147. die;
  148. if ($return['errcode'] == 0) {
  149. $open_appid = isset($return['open_appid']) ? $return['open_appid'] : '';
  150. } else {
  151. $return = wxUtil::createOpenAccount($wxAppId, $merchant);
  152. if ($return['errcode'] == 0) {
  153. $open_appid = isset($return['open_appid']) ? $return['open_appid'] : '';
  154. }
  155. }
  156. echo "<br />open_appid:" . $open_appid . "<br />";
  157. if (!empty($open_appid)) {
  158. xhMerchantService::updateById($merchantId, ['openAppId' => $open_appid]);
  159. MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppId' => $open_appid, 'openAppBind' => 3, 'miniAuth' => 1]);
  160. $r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant, false, $isOpen);
  161. echo "绑定小程序结果:<br />";
  162. print_r($r);
  163. }
  164. echo "<br /><br />";
  165. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
  166. echo "微信appId:{$wxAppId}<br />";
  167. print_r($return);
  168. $return = wxUtil::getOpenAccount($miniAppId, $merchant, false, $isOpen);
  169. echo "<br />小程序appId:{$miniAppId}<br />";
  170. print_r($return);
  171. }
  172. //开放平台开始授权 shish 2020.1.16
  173. public function actionBeginAuth()
  174. {
  175. $merchantId = Yii::$app->request->get('id', 0);
  176. $open = WxOpenService::getOpen();
  177. //1只显示公众号 2只显示小程序 3显示公众号和小程序
  178. $authType = Yii::$app->request->get('authType', 3);
  179. $pre = wxUtil::getPreAuthCode($open);
  180. $appId = $open['appId'];
  181. $oData = [];
  182. $oData['preAuthCodeTime'] = date("Y-m-d H:i:s");
  183. //设置预授码过期,让下个用户可以获取新的预授码
  184. xhWxOpenService::updateById(1, $oData);
  185. $url = Yii::$app->params['saasHost'] . '/wx-open-callback/' . $merchantId;
  186. echo "<a href='https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid={$appId}&pre_auth_code={$pre}&redirect_uri={$url}&auth_type={$authType}'>授权</a>";
  187. }
  188. //平台没有绑定商家公众号时初始化一个商家 shish 2020.2.11
  189. public function actionAddMerchant()
  190. {
  191. AdClass::initAdd(12362);
  192. $return = MerchantService::initOpenMerchant();
  193. dd($return);
  194. }
  195. public function actionCheckMerchantName()
  196. {
  197. $get = Yii::$app->request->get();
  198. $merchantName = isset($get['merchantName']) ? $get['merchantName'] : '';
  199. $m = xhMerchantService::getByMerchantName($merchantName);
  200. if (!empty($m)) {
  201. util::fail('公众号名称已经使用');
  202. }
  203. util::complete();
  204. }
  205. /**
  206. * 下载微信里的图片到服务器
  207. */
  208. public function actionDownloadWxImg()
  209. {
  210. $get = Yii::$app->request->get();
  211. $mediaId = isset($get['mediaId']) ? $get['mediaId'] : '';
  212. $imgList = wxUtil::downloadmediaIdImg($this->merchant, $mediaId);
  213. if (!empty($imgList)) {
  214. util::success($imgList);
  215. }
  216. util::fail();
  217. }
  218. //创建平台使用的公众号
  219. public function actionCallback()
  220. {
  221. $get = Yii::$app->request->get();
  222. if (isset($get['auth_code']) == false) {
  223. util::stop('公众号授权回调未成功');
  224. }
  225. $id = isset($get['id']) ? $get['id'] : 0;
  226. $code = $get['auth_code'];
  227. //使用授权码换取公众号的接口调用凭据和授权信息
  228. $authorize = wxUtil::getAuthorizer($code);
  229. if (isset($authorize['authorization_info']) == false) {
  230. util::stop('未换取公众号的接口调用凭据和授权信息');
  231. }
  232. $info = $authorize['authorization_info'];
  233. $authorizeAppId = $info['authorizer_appid'];
  234. $authorize_access_token = $info['authorizer_access_token'];
  235. $expires_in = $info['expires_in'];//7200
  236. $authorize_refresh_token = $info['authorizer_refresh_token'];
  237. //获取授权方的公众号帐号基本信息
  238. $authorizeDetailInfo = wxUtil::getAuthorizerInfo($authorizeAppId);
  239. if (isset($authorizeDetailInfo['authorizer_info']) == false) {
  240. util::stop('没有获取到公众号帐号基本信息');
  241. }
  242. $authorize_info = $authorizeDetailInfo['authorizer_info'];
  243. //$nick_name = $authorize_info['nick_name'];
  244. $head_img = $authorize_info['head_img'];
  245. $service_type_info = $authorize_info['service_type_info'];
  246. if ($service_type_info['id'] != 2) {
  247. if (isset($authorize_info['MiniProgramInfo']) == false || empty($authorize_info['MiniProgramInfo'])) {
  248. util::stop('公众号不是服务号');
  249. }
  250. }
  251. $verify_type_info = $authorize_info['verify_type_info'];
  252. if ($verify_type_info['id'] != 0) {
  253. if (isset($authorize_info['MiniProgramInfo']) == false || empty($authorize_info['MiniProgramInfo'])) {
  254. util::stop('公众号还没有认证哦');
  255. }
  256. }
  257. $user_name = $authorize_info['user_name'];
  258. $alias = $authorize_info['alias'];
  259. $qrCodeUrl = $authorize_info['qrcode_url'];
  260. $accessTokenTime = date("Y-m-d H:i:s", (time() + $expires_in - 100));//安全起见,将过期时间设置得比微信里还短100秒
  261. $extend = MerchantExtendClass::getByMerchantId($id);
  262. $open = WxOpenService::getOpen();
  263. $time = time();
  264. //小程序
  265. if (isset($authorize_info['MiniProgramInfo']) && !empty($authorize_info['MiniProgramInfo'])) {
  266. $miniData = [
  267. 'miniAppId' => $authorizeAppId,
  268. 'miniAuth' => 1,
  269. 'miniAccessToken' => $authorize_access_token,
  270. 'miniAccessTokenTime' => $accessTokenTime,
  271. 'miniRefreshToken' => $authorize_refresh_token,
  272. ];
  273. //开放平台没有小程序先绑定开放平台要用的小程序
  274. if (isset($open['wx_mini_base_id']) == false || empty($open['wx_mini_base_id'])) {
  275. $miniData['addTime'] = $time;
  276. //花卉宝
  277. $miniAppSecret = 'f1ae43c87080da21ac631609b0dbb147';
  278. if (getenv('YII_ENV') == 'dev') {
  279. //花美玲
  280. $miniAppSecret = '12f90039b1245ba6abf2e4184462fb30';
  281. }elseif(getenv('YII_ENV') == 'test'){
  282. //花掌柜
  283. $miniAppSecret = 'fd21ef3ebbc70e89d5c3a5a3c013edb6';
  284. }else{
  285. echo '未知平台';
  286. Yii::$app->end();
  287. }
  288. $miniData['miniAppSecret'] = $miniAppSecret;
  289. $wxMiniBaseRespond = WxMiniBaseService::add($miniData);
  290. $wxMiniBaseId = $wxMiniBaseRespond['id'];
  291. WxOpenService::updateOpen(['wx_mini_base_id' => $wxMiniBaseId]);
  292. util::stop('开放平台成功绑定小程序');
  293. }
  294. if (isset($extend['miniAppId']) && !empty($extend['miniAppId'])) {
  295. if ($extend['miniAppId'] != $authorizeAppId) {
  296. util::stop('授权的小程序与商家已绑定的小程序不一致');
  297. }
  298. } else {
  299. util::stop('数据库请先填写小程序 miniAppId miniAppSecret');
  300. }
  301. xhMerchantExtendService::updateByMerchantId($id, $miniData);
  302. MerchantService::updateById($id, ['miniAppId' => $authorizeAppId]);
  303. Yii::info('小程序信息更新成功:' . json_encode($authorize_info));
  304. util::stop("小程序信息更新成功");
  305. } else {
  306. if (isset($extend['wxAppId']) && !empty($extend['wxAppId'])) {
  307. if ($extend['wxAppId'] != $authorizeAppId) {
  308. util::stop('授权的公众号与商家已绑定的公众号不一致');
  309. }
  310. }
  311. }
  312. $wxData = [];
  313. $appData['wxUserName'] = $user_name;
  314. $appData['wxAliasName'] = $alias;
  315. //公众号logo
  316. $wxData['logo'] = WxBaseClass::saveLogo($head_img, $id);
  317. //公众号二维码
  318. $wxData['wxQrCodeUrl'] = WxBaseClass::saveQrCode($qrCodeUrl, $id);
  319. $wxData['wxAppId'] = $authorizeAppId;
  320. $wxData['wxAccessToken'] = $authorize_access_token;
  321. $wxData['wxAccessTokenTime'] = $accessTokenTime;
  322. $wxData['wxRefreshToken'] = $authorize_refresh_token;
  323. //开放平台还没有公众号先绑定开放平台的公众号
  324. if (isset($open['wx_base_id']) == false || empty($open['wx_base_id'])) {
  325. $wxData['addTime'] = $time;
  326. $wxBaseRespond = WxBaseService::add($wxData);
  327. $wxBaseId = $wxBaseRespond['id'];
  328. WxOpenService::updateOpen(['wx_base_id' => $wxBaseId]);
  329. util::stop('开放平台成功绑定公众号');
  330. }
  331. $wxData['status'] = 1;//审核通过
  332. xhMerchantService::updateById($id, $wxData);
  333. MerchantExtendClass::updateByCondition(['merchantId' => $id], ['wxAppId' => $authorizeAppId, 'wxAuth' => 1]);
  334. //还没有完成初始化先进行初始化
  335. if (isset($extend['init']) && $extend['init'] == 0) {
  336. $data = ['merchantId' => $id];
  337. $producer = Yii::$app->rabbitmq->getProducer('openShopInitProducer');
  338. $msg = serialize($data);
  339. $producer->publish($msg, 'openShopInitExchange', 'openShopInitRoute');
  340. }
  341. echo 'ok';
  342. }
  343. public function actionResult()
  344. {
  345. $get = Yii::$app->request->get();
  346. $id = isset($get['id']) ? $get['id'] : 0;
  347. $merchant = xhMerchantService::getById($id);
  348. $status = configDict::getConfig('merchantStatusName');
  349. $orMechantId = configDict::getConfig('merchantId');
  350. $originalMerchant = xhMerchantService::getById($orMechantId);
  351. return $this->renderPartial('result', ['originalMerchant' => $originalMerchant, 'merchant' => $merchant, 'status' => $status]);
  352. }
  353. public function actionCheckInviteCode()
  354. {
  355. $get = Yii::$app->request->get();
  356. $code = isset($get['code']) ? $get['code'] : '';
  357. $invite = xhInviteService::getByCode($code);
  358. if (empty($invite)) {
  359. util::fail('邀请码错误');
  360. }
  361. $now = time();
  362. if ($now > $invite['deadline']) {
  363. util::fail('邀请码已经失效');
  364. }
  365. if (!empty($invite['takeStatus'])) {
  366. util::fail('邀请码已经使用');
  367. }
  368. util::success($invite);
  369. }
  370. public function actionSelect()
  371. {
  372. $isWx = util::isWx();
  373. if ($isWx == false) {
  374. return $this->renderPartial('notWeixin');
  375. }
  376. return $this->renderPartial('select');
  377. }
  378. public function actionApi()
  379. {
  380. $openData = file_get_contents('php://input');
  381. if (isset ($openData) == false || empty($openData)) {
  382. util::stop('has no post data');
  383. }
  384. $weixinSecret = Yii::getAlias("@vendor/weixinSecret");
  385. require_once($weixinSecret . '/wxBizMsgCrypt.php');
  386. $get = Yii::$app->request->get();
  387. $encryptMsg = $openData;
  388. $openId = configDict::getConfig('openId');
  389. $open = xhWxOpenService::getById($openId);
  390. $encodingAesKey = $open['aesKey'];
  391. $token = $open['token'];
  392. $appId = $open['appId'];
  393. $appSecret = $open['appSecret'];
  394. $signature = isset($get['signature']) ? $get['signature'] : '';
  395. $timestamp = isset($get['timestamp']) ? $get['timestamp'] : '';
  396. $nonce = isset($get['nonce']) ? $get['nonce'] : '';
  397. $encrypt_type = isset($get['encrypt_type']) ? $get['encrypt_type'] : '';
  398. $msg_signature = isset($get['msg_signature']) ? $get['msg_signature'] : '';
  399. $xml_tree = new \DOMDocument();
  400. $xml_tree->loadXML($encryptMsg);
  401. $array_e = $xml_tree->getElementsByTagName('Encrypt');
  402. $encrypt = $array_e->item(0)->nodeValue;
  403. $format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%s]]></Encrypt></xml>";
  404. $from_xml = sprintf($format, $encrypt);
  405. $formString = " token:" . $token . "\n encodingAesKey:" . $encodingAesKey . "\n appId:" . $appId . "\n msg_signature:" . $msg_signature . "\n appSecret:" . $appSecret . "\n timestamp:" . $timestamp . "\n nonce:" . $nonce;
  406. Yii::warning($formString);
  407. $formString2 = "from_xml:" . $from_xml;
  408. Yii::warning($formString2);
  409. //第三方收到公众号平台发送的消息
  410. $pc = new \WXBizMsgCrypt($token, $encodingAesKey, $appId);
  411. $msg = '';//解密后的消息
  412. $errCode = $pc->decryptMsg($msg_signature, $timestamp, $nonce, $from_xml, $msg);
  413. if ($errCode != 0) {
  414. Yii::warning("解密未成功,错误代码:" . $errCode . "。(出现过的情况汇总:-40001 有可能token、encodingAesKey、appId等填写不对,请仔细核对每个值)");
  415. util::stop();
  416. }
  417. $postObj = simplexml_load_string($msg, 'SimpleXMLElement', LIBXML_NOCDATA);
  418. $infoType = $postObj->InfoType;
  419. switch ($infoType) {
  420. //推送 componentVerifyTicket
  421. case 'component_verify_ticket':
  422. $componentVerifyTicket = $postObj->ComponentVerifyTicket;
  423. if (!empty($componentVerifyTicket)) {
  424. $oData = [];
  425. $oData['verifyTicket'] = (string)$componentVerifyTicket;
  426. $oData['verifyTicketTime'] = date("Y-m-d H:i:s", $timestamp + 600);//每10分钟(600秒)推一次
  427. xhWxOpenService::updateById($openId, $oData);
  428. Yii::warning("component_verify_ticket:" . (string)$componentVerifyTicket);
  429. util::stop('success');
  430. }
  431. break;
  432. //取消授权通知
  433. case 'unauthorized':
  434. $AppId = $postObj->AppId;
  435. $authorizeAppid = $postObj->AuthorizerAppid;
  436. $merchant = xhMerchantService::getByAppId($authorizeAppid);
  437. if (!empty($merchant)) {
  438. $merchantId = $merchant['id'];
  439. //自主冻结
  440. xhMerchantService::updateById($merchantId, ['status' => 5]);
  441. }
  442. break;
  443. //授权成功通知
  444. case 'authorized':
  445. $AppId = $postObj->AppId;//第三方平台appid
  446. $CreateTime = $postObj->CreateTime;//公众号
  447. $authorizeAppid = $postObj->AuthorizerAppid;//授权码,可用于换取公众号的接口调用凭据,详细见上面的说明
  448. $AuthorizationCode = $postObj->AuthorizationCode;
  449. $AuthorizationCodeExpiredTime = $postObj->AuthorizationCodeExpiredTime;//授权码过期时间
  450. break;
  451. //授权更新通知
  452. case 'updateauthorized':
  453. $AppId = $postObj->AppId;
  454. $CreateTime = $postObj->CreateTime;
  455. $authorizeAppid = $postObj->AuthorizerAppid;
  456. $AuthorizationCode = $postObj->AuthorizationCode;
  457. $AuthorizationCodeExpiredTime = $postObj->AuthorizationCodeExpiredTime;
  458. util::stop();
  459. $authorize = wxUtil::getAuthorizer($AuthorizationCode);
  460. if (isset($authorize['authorization_info']) == false) {
  461. $msg = '授权回调获取到auth_code,但未换取公众号的接口调用凭据和授权信息!!';
  462. Yii::warning($msg, __METHOD__);
  463. Yii::$app->end();
  464. }
  465. $info = $authorize['authorization_info'];
  466. $authorizeAppId = $info['authorizer_appid'];
  467. $authorize_access_token = $info['authorizer_access_token'];
  468. $expires_in = $info['expires_in'];//7200
  469. $authorize_refresh_token = $info['authorizer_refresh_token'];
  470. $merchant = xhMerchantService::getByAppId($authorizeAppId);
  471. if (empty($merchant)) {
  472. return false;
  473. }
  474. $merchantId = $merchant['id'];
  475. $wxData = [];
  476. $wxData['wxAccessToken'] = $authorize_access_token;
  477. $wxData['wxRefreshToken'] = $authorize_refresh_token;
  478. $wxData['wxAccessTokenTime'] = date("Y-m-d H:i:s", (time() + $expires_in - 100));
  479. $wxData['status'] = 1;
  480. xhMerchantService::updateById($merchantId, $wxData);
  481. break;
  482. default:
  483. }
  484. Yii::warning("---wx open data end--- \n");
  485. }
  486. //获取平台信息 shish 2020.4.12
  487. public function actionGetWxOpen()
  488. {
  489. $open = WxOpenService::getOpen();
  490. util::success($open);
  491. }
  492. }