WxOpenController.php 19 KB

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