WxOpenController.php 23 KB

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