WxOpenController.php 23 KB

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