WxOpenController.php 23 KB

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