WxOpenController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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. //供货商使用 https://api.pt.hzghd.com/wx-open/bind-open?isOpen=2&actId=3
  214. //花店使用 https://api.pt.huaml.com/wx-open/bind-open?isOpen=1&actId=3
  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. util::stop('这步已经不需要做了');
  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. util::stop('这步已经不需要做了');
  273. $openAppId = $merchant['openAppId'];
  274. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true, $isOpen);
  275. //MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppBind' => 3, 'miniAuth' => 1]);
  276. print_r($r);
  277. }
  278. //查询公众号 小程序的绑定情况
  279. if ($id == 3) {
  280. Yii::info("查询公众号 小程序的绑定情况 wxAppId:{$wxAppId} isOpen:{$isOpen}");
  281. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
  282. echo "公众号绑定情况:<br />";
  283. print_r($return);
  284. $return = wxUtil::getOpenAccount($miniAppId, $merchant, true, $isOpen);
  285. echo "小程序绑定情况:<br />";
  286. print_r($return);
  287. }
  288. //设置小程序服务器域名
  289. if ($id == 4) {
  290. wxUtil::setDomain($merchant, $isOpen);
  291. wxUtil::setWebViewDomain($merchant, $isOpen);
  292. }
  293. //为授权的小程序帐号上传小程序代码
  294. if ($id == 5) {
  295. //模板id
  296. $tId = Yii::$app->request->get('tId');
  297. wxUtil::miniCommit($merchant, $tId, $isOpen);
  298. }
  299. //获取小程序体验码
  300. if ($id == 6) {
  301. wxUtil::getExperienceQrCode($merchant, '', $isOpen);
  302. }
  303. //获取授权小程序帐号已设置的类目
  304. if ($id == 7) {
  305. wxUtil::getMiniCategory($merchant, $isOpen);
  306. }
  307. //获取小程序的第三方提交代码的页面配置
  308. if ($id == 8) {
  309. wxUtil::getMiniPage($merchant, $isOpen);
  310. }
  311. //将第三方提交的代码包提交审核
  312. if ($id == 9) {
  313. wxUtil::miniSubmitAudit($merchant, '', $isOpen);
  314. }
  315. //查询最新一次提交的审核状态
  316. if ($id == 10) {
  317. wxUtil::miniGetLatestAuditStatus($merchant, $isOpen);
  318. }
  319. //发布已通过审核的小程序
  320. if ($id == 11) {
  321. $respond = wxUtil::miniRelease($merchant, $isOpen);
  322. dd($respond);
  323. }
  324. //撤回审核
  325. if ($id == 12) {
  326. wxUtil::rollbackCheck($merchant, $isOpen);
  327. }
  328. //生成 申请会员页 的小程序码
  329. if ($id == 13) {
  330. wxUtil::generateMemberCode($merchant, $isOpen);
  331. }
  332. //解绑小程序和公众号绑定的平台
  333. if ($id == 14) {
  334. echo '<pre>';
  335. Yii::info("解绑信息:" . json_encode($merchant));
  336. $r = wxUtil::unbindAccount($merchant, $isOpen);
  337. print_r($r);
  338. $r = wxUtil::unbindMiniProgram($merchant, $isOpen);
  339. print_r($r);
  340. Yii::$app->end();
  341. }
  342. Yii::$app->end();
  343. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true, $isOpen);
  344. print_r($r);
  345. echo $miniAppId . ' ' . $openAppId . ' ';
  346. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
  347. print_r($return);
  348. die;
  349. $return = wxUtil::createOpenAccount($wxAppId, $merchant, $isOpen);
  350. print_r($return);
  351. die;
  352. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, false, $isOpen);
  353. print_r($r);
  354. echo $miniAppId . ' ' . $openAppId . ' ';
  355. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
  356. print_r($return);
  357. $return = wxUtil::getOpenAccount($miniAppId, $merchant, false, $isOpen);
  358. print_r($return);
  359. }
  360. public function actionResult()
  361. {
  362. $get = Yii::$app->request->get();
  363. $id = isset($get['id']) ? $get['id'] : 0;
  364. $merchant = xhMerchantService::getById($id);
  365. $status = configDict::getConfig('merchantStatusName');
  366. $orMechantId = configDict::getConfig('merchantId');
  367. $originalMerchant = xhMerchantService::getById($orMechantId);
  368. return $this->renderPartial('result', ['originalMerchant' => $originalMerchant, 'merchant' => $merchant, 'status' => $status]);
  369. }
  370. public function actionCheckInviteCode()
  371. {
  372. $get = Yii::$app->request->get();
  373. $code = isset($get['code']) ? $get['code'] : '';
  374. $invite = xhInviteService::getByCode($code);
  375. if (empty($invite)) {
  376. util::fail('邀请码错误');
  377. }
  378. $now = time();
  379. if ($now > $invite['deadline']) {
  380. util::fail('邀请码已经失效');
  381. }
  382. if (!empty($invite['takeStatus'])) {
  383. util::fail('邀请码已经使用');
  384. }
  385. util::success($invite);
  386. }
  387. public function actionSelect()
  388. {
  389. $isWx = util::isWx();
  390. if ($isWx == false) {
  391. return $this->renderPartial('notWeixin');
  392. }
  393. return $this->renderPartial('select');
  394. }
  395. public function actionApi()
  396. {
  397. $get = Yii::$app->request->get();
  398. $style = $get['style'] ?? \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD;
  399. $openData = file_get_contents('php://input');
  400. if (isset ($openData) == false || empty($openData)) {
  401. util::stop('has no post data');
  402. }
  403. $wxSecret = Yii::getAlias("@vendor/weixinSecret");
  404. require_once($wxSecret . '/wxBizMsgCrypt.php');
  405. $encryptMsg = $openData;
  406. $open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => $style]);
  407. $openId = $open['id'];
  408. $encodingAesKey = $open['aesKey'];
  409. $token = $open['token'];
  410. $appId = $open['appId'];
  411. $appSecret = $open['appSecret'];
  412. $signature = isset($get['signature']) ? $get['signature'] : '';
  413. $timestamp = isset($get['timestamp']) ? $get['timestamp'] : '';
  414. $nonce = isset($get['nonce']) ? $get['nonce'] : '';
  415. $encrypt_type = isset($get['encrypt_type']) ? $get['encrypt_type'] : '';
  416. $msg_signature = isset($get['msg_signature']) ? $get['msg_signature'] : '';
  417. $xml_tree = new \DOMDocument();
  418. $xml_tree->loadXML($encryptMsg);
  419. $array_e = $xml_tree->getElementsByTagName('Encrypt');
  420. $encrypt = $array_e->item(0)->nodeValue;
  421. $format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%s]]></Encrypt></xml>";
  422. $from_xml = sprintf($format, $encrypt);
  423. $formString = " token:" . $token . "\n encodingAesKey:" . $encodingAesKey . "\n appId:" . $appId . "\n msg_signature:" . $msg_signature . "\n appSecret:" . $appSecret . "\n timestamp:" . $timestamp . "\n nonce:" . $nonce;
  424. Yii::warning($formString);
  425. $formString2 = "from_xml:" . $from_xml;
  426. Yii::warning($formString2);
  427. //第三方收到公众号平台发送的消息
  428. $pc = new \WXBizMsgCrypt($token, $encodingAesKey, $appId);
  429. $msg = '';//解密后的消息
  430. $errCode = $pc->decryptMsg($msg_signature, $timestamp, $nonce, $from_xml, $msg);
  431. if ($errCode != 0) {
  432. Yii::warning("解密未成功,错误代码:" . $errCode . "。(出现过的情况汇总:-40001 有可能token、encodingAesKey、appId等填写不对,请仔细核对每个值)");
  433. util::stop();
  434. }
  435. $postObj = simplexml_load_string($msg, 'SimpleXMLElement', LIBXML_NOCDATA);
  436. $infoType = $postObj->InfoType;
  437. switch ($infoType) {
  438. //推送 componentVerifyTicket
  439. case 'component_verify_ticket':
  440. $componentVerifyTicket = $postObj->ComponentVerifyTicket;
  441. if (!empty($componentVerifyTicket)) {
  442. $oData = [];
  443. $oData['verifyTicket'] = (string)$componentVerifyTicket;
  444. $oData['verifyTicketTime'] = date("Y-m-d H:i:s", $timestamp + 600);//每10分钟(600秒)推一次
  445. xhWxOpenService::updateById($openId, $oData);
  446. Yii::warning("component_verify_ticket:" . (string)$componentVerifyTicket);
  447. util::stop('success');
  448. }
  449. break;
  450. //取消授权通知
  451. case 'unauthorized':
  452. //这里没有往下操作,请看本文件callback()方法
  453. break;
  454. //授权成功通知
  455. case 'authorized':
  456. $AppId = $postObj->AppId;
  457. $authorizeAppId = $postObj->AuthorizerAppid;
  458. $CreateTime = $postObj->CreateTime;//公众号
  459. $authorizeAppId = $postObj->AuthorizerAppid;//授权码,可用于换取公众号的接口调用凭据,详细见上面的说明
  460. $AuthorizationCode = $postObj->AuthorizationCode;
  461. $AuthorizationCodeExpiredTime = $postObj->AuthorizationCodeExpiredTime;//授权码过期时间
  462. //这里没有往下操作,请看本文件callback()方法
  463. break;
  464. //授权更新通知
  465. case 'updateauthorized':
  466. $AppId = $postObj->AppId;
  467. $authorizeAppId = $postObj->AuthorizerAppid;
  468. $CreateTime = $postObj->CreateTime;
  469. $authorizeAppId = $postObj->AuthorizerAppid;
  470. $AuthorizationCode = $postObj->AuthorizationCode;
  471. $AuthorizationCodeExpiredTime = $postObj->AuthorizationCodeExpiredTime;
  472. //这里没有往下操作,请看本文件callback()方法
  473. break;
  474. default:
  475. }
  476. Yii::warning("---wx open data end--- \n");
  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. //获取平台信息 shish 2020.4.12
  509. public function actionGetWxOpen()
  510. {
  511. util::success([]);
  512. }
  513. }