WxOpenController.php 23 KB

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