PerfectMiniForm.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\models\v1\third\wechat;
  8. use app\models\StoreMini;
  9. use EasyWeChat\BasicService\Media\Client;
  10. use EasyWeChat\Kernel\BaseClient;
  11. use yii\base\Model;
  12. class PerfectMiniForm extends Model
  13. {
  14. /**
  15. * 完善小程序
  16. */
  17. //easyWechat配置
  18. public $openPlatform;
  19. //商城ID
  20. public $store_id;
  21. //小程序ID
  22. public $mini_id;
  23. //easyWechat接口配置
  24. public $miniProgram;
  25. //获取小程序
  26. public $store_mini;
  27. //名称审核资料
  28. public $name_data;
  29. //小程序信息
  30. public $mini_info;
  31. public function rules()
  32. {
  33. return [
  34. [['store_id', 'mini_id'], 'integer'],
  35. [['name_data', 'mini_info'], 'array']
  36. ];
  37. }
  38. public function inits()
  39. {
  40. try {
  41. //商城ID
  42. $store_id = $this->store_id;
  43. //小程序ID
  44. $mini_id = $this->mini_id;
  45. //获取配置信息
  46. $form = new BaseForm();
  47. $form->store_id = $store_id;
  48. $form->mini_id = $mini_id;
  49. //获取easyWechat配置信息
  50. $this->openPlatform = $form->openPlatform;
  51. //判断商城ID 或 小程序ID是否不为空,不为空则获取请求微信的配置信息
  52. if (!empty($store_id) || !empty($mini_id)) {
  53. //获取请求微信的配置信息
  54. $result = $form->miniProgram();
  55. //获取小程序信息
  56. $this->store_mini = StoreMini::find()->where(['or', ['id' => $mini_id], ['store_id' => $store_id]])->andWhere(['is_cancle' => 0])->orderBy('id desc')->one();
  57. if ($result['code'] === 1) {
  58. return $result;
  59. }
  60. $this->miniProgram = $result;
  61. }
  62. } catch (\Exception $e) {
  63. return [
  64. 'code' => 1,
  65. 'msg' => $e->getMessage()
  66. ];
  67. }
  68. }
  69. //修改小程序名称
  70. public function setMiniName()
  71. {
  72. try {
  73. $result = $this->inits();
  74. if ($result['code'] === 1) {
  75. return $result;
  76. }
  77. //判断小程序是否存在
  78. $store_mini = $this->store_mini;
  79. if (empty($store_mini)) {
  80. throw new \Exception("查找不到小程序信息");
  81. }
  82. //获取接口配置信息
  83. $miniProgram = $this->miniProgram;
  84. $media = new Client($miniProgram);
  85. //判断是get方式请求
  86. // if (\Yii::$app->request->isGet) {
  87. // //营业执照信息
  88. // $license_pic = $store_mini->license_pic ?: "";
  89. // $name_data['license'] = $license_pic;
  90. //
  91. // //名称审核资料
  92. // $name_data = $store_mini->nickname_audit_data;
  93. // $name_data = json_decode($name_data, true);
  94. //
  95. // //小程序名称
  96. // $nickname = $store_mini->mini_nickname;
  97. //
  98. // return [
  99. // 'code' => 0,
  100. // 'msg' => "获取成功",
  101. // 'data' => [
  102. // 'mini_info' => [
  103. // 'nickname' => $nickname
  104. // ],
  105. // 'name_data' => $name_data
  106. // ]
  107. // ];
  108. //
  109. // }
  110. //获取请求信息
  111. //post方式请求
  112. //获取小程序名称
  113. $mini_info = $this->mini_info;
  114. //获取名称审核资料
  115. $name_data = $this->name_data;
  116. //保存名称审核资料
  117. $store_mini->nickname_audit_data = json_encode($name_data);
  118. //保存小程序名称
  119. $store_mini->mini_nickname = $mini_info['nickname'] ?: '';
  120. //重新填充营业执照信息
  121. $name_data['license'] = $store_mini->license_pic;
  122. if (!empty($name_data)) {
  123. //循环 ,将数据保存到本地
  124. foreach ($name_data as &$item) {
  125. if (!empty($item)) {
  126. //保存数据到本地
  127. $local_item = (new BaseForm())->saveTempImage($item);
  128. //从微信获取media_id
  129. $result = $media->uploadImage($local_item);
  130. //判断media信息是否正确
  131. if (empty($result['media_id'])) {
  132. throw new \Exception($this->getZnMsg($result));
  133. }
  134. $item = $result['media_id'];
  135. }
  136. }
  137. }
  138. $license_media_id = $name_data['license'];
  139. //剔除营业执照 个人身份证信息
  140. unset($name_data['license']);
  141. unset($name_data['id_card']);
  142. //请求微信审核名称接口
  143. $result = $miniProgram->setting->setNickname($mini_info['nickname'], '', $license_media_id, $name_data);
  144. if ($result['errcode'] == 0) {
  145. self::addMiniCategory();
  146. }
  147. //判断审核名称是否存在audit_id;如果存在则进入审核阶段
  148. if ($result['errcode'] == 0 && !empty($result['audit_id'])) {
  149. $store_mini->apply_name_status = 1;
  150. $store_mini->nickname_audit_id = $result['audit_id'];
  151. $msg = "开始审核!";
  152. //判断审核名称是否存在audit_id;如果不存在则不需要审核
  153. } elseif ($result['errcode'] == 0 && empty($result['audit_id'])) {
  154. $store_mini->apply_name_status = 3;
  155. $msg = "审核通过!";
  156. //判断是否存在错误信息
  157. } elseif ($result['errcode'] !== 0) {
  158. $msg = (new BaseForm())->getZnMsg($result);
  159. throw new \Exception($msg);
  160. } else {
  161. throw new \Exception("参数错误");
  162. }
  163. //判断是否保存成功
  164. if (!$store_mini->save()) {
  165. throw new \Exception(json_encode($store_mini->errors));
  166. }
  167. return [
  168. 'code' => 0,
  169. 'msg' => $msg
  170. ];
  171. } catch (\Exception $e) {
  172. return [
  173. 'code' => 1,
  174. 'msg' => $e->getMessage()
  175. ];
  176. }
  177. }
  178. //微信名称检测 检测名称是否可用 需要mini_id
  179. public function checkNickname()
  180. {
  181. try {
  182. $result = $this->inits();
  183. if ($result['code'] === 1) {
  184. return $result;
  185. }
  186. //获取小程序名称
  187. $mini_info = $this->mini_info;
  188. $nickname = $mini_info['nickname'];
  189. //判断名称是否为空
  190. if (empty($nickname)) {
  191. throw new \Exception("名称不能为空");
  192. }
  193. //请求微信接口获取检测结果
  194. $miniProgram = $this->miniProgram;
  195. $result = $miniProgram->setting->isAvailableNickname($nickname);
  196. //请求成功,判断是否存在敏感字段 如果存在则返回说明描述
  197. if ($result['errcode'] == 0) {
  198. return [
  199. 'code' => 0,
  200. 'hit_condition' => $result['hit_condition'],
  201. 'msg' => $result['wording']
  202. ];
  203. //返回信息错误,则返回错误信息
  204. } elseif ($result['errcode'] !== 0) {
  205. $msg = (new BaseForm())->getZnMsg($result);
  206. throw new \Exception($msg);
  207. } else {
  208. throw new \Exception("参数错误");
  209. }
  210. } catch (\Exception $e) {
  211. return [
  212. 'code' => 0,
  213. 'msg' => $e->getMessage()
  214. ];
  215. }
  216. }
  217. //查询.小程序名称审核状态
  218. public function getMiniStatus()
  219. {
  220. try {
  221. $result = $this->inits();
  222. if ($result['code'] === 1) {
  223. return $result;
  224. }
  225. //获取小程序信息
  226. $store_mini = $this->store_mini;
  227. //判断小程序是否已经审核通过(不请求接口)
  228. if (isset($store_mini->apply_name_status) && ($store_mini->apply_name_status == 0) && !empty($store_mini->mini_nickname)) {
  229. return [
  230. 'code' => 0,
  231. 'msg' => "审核已经通过"
  232. ];
  233. }
  234. //获取审核单ID
  235. $audit_id = $store_mini->nickname_audit_id;
  236. if (empty($audit_id)) {
  237. throw new \Exception("参数获取失败");
  238. }
  239. //通过审核单ID请求微信接口
  240. $miniProgram = $this->miniProgram;
  241. $result = $miniProgram->setting->getNicknameAuditStatus($audit_id);
  242. if ($result['errcode'] === 0) {
  243. //审核中
  244. if ($result['audit_stat'] == 1) {
  245. $status = "名称审核中";
  246. $store_mini->apply_name_status = 1;
  247. //审核失败
  248. } elseif ($result['audit_stat'] == 2) {
  249. $status = "名称审核失败:" . $result['fail_reason'];
  250. $store_mini->apply_name_error = $result['fail_reason'];
  251. $store_mini->apply_name_status = 2;
  252. //审核成功
  253. } else {
  254. $status = "名称审核成功";
  255. $store_mini->apply_name_status = 3;
  256. }
  257. //保存小程序名称审核信息
  258. if (!$store_mini->save()) {
  259. throw new \Exception(json_encode($store_mini->errors));
  260. }
  261. return [
  262. 'code' => 0,
  263. 'msg' => $status,
  264. 'status' => $result['audit_stat']
  265. ];
  266. } elseif($result['errcode'] !== 0) {
  267. $msg = (new BaseForm())->getZnMsg($result);
  268. throw new \Exception($msg);
  269. } else {
  270. throw new \Exception("参数错误");
  271. }
  272. } catch (\Exception $e) {
  273. return [
  274. 'code' => 0,
  275. 'msg' => $e->getMessage()
  276. ];
  277. }
  278. }
  279. //修改头像
  280. public function setHeadImg()
  281. {
  282. try {
  283. $result = $this->inits();
  284. if ($result['code'] === 1) {
  285. return $result;
  286. }
  287. $store_mini = $this->store_mini;
  288. //获取小程序头像
  289. $mini_info = $this->mini_info;
  290. $head_image = $mini_info['mini_url'];
  291. $store_mini->mini_url = $head_image;
  292. //将头像地址保存本地
  293. $img_url = (new BaseForm())->saveTempImage($head_image);
  294. //获取微信配置信息
  295. $miniProgram = $this->miniProgram;
  296. //获取微信上传图片配置
  297. $media = new Client($miniProgram);
  298. //上传缩略图,获取media_id
  299. $head_image = $media->uploadThumb($img_url);
  300. //判断上传缩略图时是否报错
  301. if (empty($head_image['thumb_media_id'])) {
  302. $msg = (new BaseForm())->getZnMsg($head_image);
  303. throw new \Exception($msg);
  304. }
  305. //使用生成的media_id 上传头像
  306. $result = $miniProgram->account->updateAvatar($head_image['thumb_media_id'], 0, 0, 1, 1);
  307. if ($result['errcode'] === 0) {
  308. //保存头像信息
  309. if (!$store_mini->save()) {
  310. throw new \Exception($store_mini->errors);
  311. }
  312. return [
  313. 'code' => 0,
  314. 'msg' => "保存成功"
  315. ];
  316. } elseif ($result['errcode'] != 0) {
  317. //获取错误信息
  318. $msg = (new BaseForm())->getZnMsg($result);
  319. throw new \Exception($msg);
  320. } else {
  321. throw new \Exception("参数错误");
  322. }
  323. } catch (\Exception $e) {
  324. //返回错误信息
  325. return [
  326. 'code' => 1,
  327. 'msg' => $e->getMessage()
  328. ];
  329. }
  330. }
  331. //查询所有可设置的小程序类目 //获取mini_id
  332. public function getAllCategory()
  333. {
  334. try {
  335. $result = $this->inits();
  336. if ($result['code'] === 1) {
  337. return $result;
  338. }
  339. //获取微信配置信息
  340. $miniProgram = $this->miniProgram;
  341. //获取所有可用的类目
  342. $result = $miniProgram->setting->getAllCategories();
  343. if ($result['errcode'] === 0) {
  344. $old_data = $result['categories_list']['categories'];
  345. //使用递归处理数据 返回父子数据
  346. $data = (new BaseForm())->getdata($old_data);
  347. return [
  348. 'code' => 0,
  349. 'msg' => "获取成功",
  350. 'data' => $data,
  351. 'old_data' => $old_data
  352. ];
  353. //微信错误信息
  354. } elseif ($result['errcode'] != 0) {
  355. $msg = (new BaseForm())->getZnMsg($result);
  356. throw new \Exception($msg);
  357. } else {
  358. throw new \Exception("数据错误");
  359. }
  360. } catch (\Exception $e) {
  361. return [
  362. 'code' => 1,
  363. 'msg' => $e->getMessage()
  364. ];
  365. }
  366. }
  367. //添加小程序类目 (带资质的类目需要审核,申请只能被动推送) 需要mini_id 不设置类目到数据库
  368. public function addMiniCategory()
  369. {
  370. try {
  371. $result = $this->inits();
  372. if ($result['code'] === 1) {
  373. return $result;
  374. }
  375. //获取微信请求配置
  376. $miniProgram = $this->miniProgram;
  377. //获取添加的分类信息
  378. // $mini_info = $this->mini_info;
  379. // $data = $mini_info['category'];
  380. //
  381. // //获取微信media处理配置
  382. // $media = new Client($miniProgram);
  383. //
  384. // foreach ($data as &$item) {
  385. // //判断分类是否为空
  386. // if (!empty($item['certicates'])) {
  387. //
  388. // //遍历类目
  389. // foreach ($item['certicates'] as &$cate) {
  390. //
  391. // //保存图片到本地
  392. // $url = (new BaseForm())->saveTempImage($cate['value']);
  393. //
  394. // //获取media_id
  395. // $cate['value'] = $media->uploadImage($url)['media_id'];
  396. // }
  397. // }
  398. // }
  399. $data = [
  400. [
  401. "first"=>304,
  402. "second"=> 1309
  403. ]
  404. ];
  405. $result = $miniProgram->setting->addCategories($data);
  406. if ($result['errcode'] === 0) {
  407. $result = $this->getMiniCategory();
  408. if ($result['code'] != 0) {
  409. throw new \Exception($result['msg']);
  410. }
  411. return [
  412. 'code' => 0,
  413. 'msg' => "操作成功"
  414. ];
  415. } elseif ($result['errcode'] != 0) {
  416. $msg = (new BaseForm())->getZnMsg($result);
  417. throw new \Exception($msg);
  418. } else {
  419. throw new \Exception("数据错误");
  420. }
  421. } catch (\Exception $e) {
  422. return [
  423. 'code' => 1,
  424. 'msg' => $e->getMessage()
  425. ];
  426. }
  427. }
  428. //查询已经设置的小程序类目
  429. public function getMiniCategory()
  430. {
  431. try {
  432. $result = $this->inits();
  433. if ($result['code'] === 1) {
  434. return $result;
  435. }
  436. //获取微信请求配置
  437. $miniProgram = $this->miniProgram;
  438. //获取小程序信息
  439. $store_mini = $this->store_mini;
  440. //请求微信接口
  441. $result = $miniProgram->setting->getCategories();
  442. if ($result['errcode'] === 0) {
  443. //保存分类信息
  444. $store_mini->categories = json_encode($result['categories']) ?: "";
  445. //保存失败
  446. if (!$store_mini->save()) {
  447. throw new \Exception(json_encode($store_mini->errors));
  448. }
  449. //保存成功
  450. return [
  451. 'code' => 0,
  452. 'msg' => "获取成功",
  453. 'data' => $result['categories']
  454. ];
  455. } elseif (empty($result)) {
  456. throw new \Exception("数据错误");
  457. } else {
  458. $msg = (new BaseForm())->getZnMsg($result);
  459. throw new \Exception($msg);
  460. }
  461. } catch (\Exception $e) {
  462. return [
  463. 'code' => 1,
  464. 'msg' => $e->getMessage()
  465. ];
  466. }
  467. }
  468. //删除类目
  469. public function delMiniCategory()
  470. {
  471. try {
  472. $result = $this->inits();
  473. if ($result['code'] === 1) {
  474. return $result;
  475. }
  476. //获取微信请求配置
  477. $miniProgram = $this->miniProgram;
  478. //获取分类信息
  479. $mini_info = $this->mini_info;
  480. $category = $mini_info['category'];
  481. //请求微信删除类目接口
  482. $result = $miniProgram->setting->deleteCategories($category['cate_first'], $category['cate_second']);
  483. //请求成功
  484. if ($result['errcode'] === 0) {
  485. $result = $this->getMiniCategory();
  486. if ($result['code'] != 0) {
  487. throw new \Exception($result['msg']);
  488. }
  489. return [
  490. 'code' => 0,
  491. 'msg' => "删除成功"
  492. ];
  493. //请求微信返回错误信息
  494. } elseif ($result['errcode'] != 0) {
  495. $msg = (new BaseForm())->getZnMsg($result);
  496. throw new \Exception($msg);
  497. //请求失败
  498. } else {
  499. throw new \Exception("数据错误");
  500. }
  501. } catch (\Exception $e) {
  502. return [
  503. 'code' => 1,
  504. 'msg' => $e->getMessage()
  505. ];
  506. }
  507. }
  508. //修改小程序简介
  509. public function setSignature()
  510. {
  511. $t = \Yii::$app->db->beginTransaction();
  512. try {
  513. $result = $this->inits();
  514. if ($result['code'] === 1) {
  515. return $result;
  516. }
  517. //获取微信请求配置
  518. $miniProgram = $this->miniProgram;
  519. //获取简介
  520. $mini_info = $this->mini_info;
  521. $signature = $mini_info['signature'];
  522. //获取小程序model
  523. $store_mini = $this->store_mini;
  524. //设置简介
  525. $store_mini->signature = $signature;
  526. if (!$store_mini->save()) {
  527. throw new \Exception($store_mini->errors);
  528. }
  529. //请求微信接口
  530. $result = $miniProgram->account->updateSignature($signature);
  531. if ($result['errcode'] === 0) {
  532. $t->commit();
  533. return [
  534. 'code' => 0,
  535. 'msg' => "保存成功"
  536. ];
  537. } elseif ($result['errcode'] != 0) {
  538. $msg = (new BaseForm())->getZnMsg($result);
  539. throw new \Exception($msg);
  540. } else {
  541. throw new \Exception("数据错误");
  542. }
  543. } catch (\Exception $e) {
  544. $t->rollBack();
  545. return [
  546. 'code' => 1,
  547. 'msg' => $e->getMessage()
  548. ];
  549. }
  550. }
  551. //修改设置小程序隐私设置
  552. public function setPrivacyForm()
  553. {
  554. try {
  555. $result = $this->inits();
  556. if ($result['code'] === 1) {
  557. return $result;
  558. }
  559. $data = [
  560. "privacy_ver" => 2,
  561. "owner_setting" => [
  562. "contact_phone" => "17090402350",
  563. "notice_method" => "短信"
  564. ],
  565. "setting_list" => [
  566. [
  567. "privacy_key" => "UserInfo",
  568. "privacy_text" => "统计订单"
  569. ],
  570. [
  571. "privacy_key" => "Location",
  572. "privacy_text" => "显示附近自提点"
  573. ],
  574. [
  575. "privacy_key" => "Address",
  576. "privacy_text" => "显示附近自提点"
  577. ],
  578. [
  579. "privacy_key" => "RunData",
  580. "privacy_text" => "消费步数兑换商品"
  581. ],
  582. [
  583. "privacy_key" => "Record",
  584. "privacy_text" => "售后咨询"
  585. ],
  586. [
  587. "privacy_key" => "Camera",
  588. "privacy_text" => "提交订单备注资料"
  589. ],
  590. [
  591. "privacy_key" => "AlbumWriteOnly",
  592. "privacy_text" => "保存海报"
  593. ],
  594. [
  595. "privacy_key" => "PhoneNumber",
  596. "privacy_text" => "多端口数据统一"
  597. ],
  598. [
  599. "privacy_key" => "Album",
  600. "privacy_text" => "审核资质"
  601. ]
  602. ],
  603. ];
  604. $miniProgram = $this->miniProgram;
  605. //创建请求方式
  606. $client = new BaseClient($miniProgram);
  607. //请求设置隐私保护指引接口
  608. $result = $client->httpPostJson('cgi-bin/component/setprivacysetting', $data);
  609. if ($result['errcode'] === 0) {
  610. return [
  611. 'code' => 0,
  612. 'msg' => "设置成功"
  613. ];
  614. } elseif ($result['errcode'] != 0) {
  615. $msg = (new BaseForm())->getZnMsg($result);
  616. throw new \Exception($msg);
  617. } else {
  618. throw new \Exception("数据错误");
  619. }
  620. } catch (\Exception $e) {
  621. return [
  622. 'code' => 1,
  623. 'msg' => $e->getMessage()
  624. ];
  625. }
  626. }
  627. //修改小程序服务器域名
  628. public function setDomainName()
  629. {
  630. try {
  631. $result = $this->inits();
  632. if ($result['code'] === 1) {
  633. return $result;
  634. }
  635. //获取微信请求配置
  636. $miniProgram = $this->miniProgram;
  637. //设置配置服务器域名资料信息
  638. $data = [
  639. 'action' => 'set',//操作类型 add添加 delete删除 set覆盖 get获取
  640. 'requestdomain' => ["https://" . \Yii::$app->request->hostName],
  641. "wsrequestdomain" => ["wss://" . \Yii::$app->request->hostName],
  642. "uploaddomain" => ["https://" . \Yii::$app->request->hostName],
  643. "downloaddomain" => ["https://" . \Yii::$app->request->hostName],
  644. "udpdomain" => ["udp://" . \Yii::$app->request->hostName],
  645. "tcpdomain" => ["tcp://" . \Yii::$app->request->hostName]
  646. ];
  647. //请求微信
  648. $result = $miniProgram->domain->modify($data);
  649. //返回成功
  650. if ($result['errcode'] === 0) {
  651. return [
  652. 'code' => 0,
  653. 'msg' => "设置成功"
  654. ];
  655. //返回失败输出错误信息
  656. } elseif ($result['errcode'] != 0) {
  657. $msg = (new BaseForm())->getZnMsg($result);
  658. throw new \Exception($msg);
  659. } else {
  660. throw new \Exception("数据错误");
  661. }
  662. } catch (\Exception $e) {
  663. return [
  664. 'code' => 1,
  665. 'msg' => $e->getMessage()
  666. ];
  667. }
  668. }
  669. //修改小程序业务域名
  670. public function setWebviewDomain()
  671. {
  672. try {
  673. $result = $this->inits();
  674. if ($result['code'] === 1) {
  675. return $result;
  676. }
  677. $store_mini = $this->store_mini;
  678. //获取微信请求配置
  679. $miniProgram = $this->miniProgram;
  680. $result = $miniProgram->domain->setWebviewDomain([
  681. 'https://' . \Yii::$app->request->hostName,
  682. 'https://' . \Yii::$app->params['ws_url'],
  683. ], 'set');
  684. //返回成功
  685. if ($result['errcode'] === 0) {
  686. return [
  687. 'code' => 0,
  688. 'msg' => "设置成功"
  689. ];
  690. //返回失败输出错误信息
  691. } elseif ($result['errcode'] != 0) {
  692. $msg = (new BaseForm())->getZnMsg($result);
  693. throw new \Exception($msg);
  694. } else {
  695. throw new \Exception("数据错误");
  696. }
  697. } catch (\Exception $e) {
  698. return [
  699. 'code' => 1,
  700. 'msg' => $e->getMessage()
  701. ];
  702. }
  703. }
  704. //查询最后一次审核状态
  705. public function getLastAuditStatus()
  706. {
  707. try {
  708. $result = $this->inits();
  709. if ($result['code'] === 1) {
  710. return $result;
  711. }
  712. $miniProgram = $this->miniProgram;
  713. $result = $miniProgram->code->getLatestAuditStatus();
  714. if ($result['errcode'] === 0) {
  715. switch ($result['status']) {
  716. case 1:
  717. $msg = "审核被拒绝";
  718. break;
  719. case 2:
  720. $msg = "审核中";
  721. break;
  722. case 3:
  723. $msg = "已撤回";
  724. break;
  725. default:
  726. $msg = "审核成功";
  727. break;
  728. }
  729. return [
  730. 'code' => 0,
  731. 'msg' => $msg,
  732. 'data' => [
  733. 'reason' => $result
  734. ]
  735. ];
  736. } elseif ($result['errcode'] != 0) {
  737. $msg = (new BaseForm())->getZnMsg($result);
  738. throw new \Exception($msg);
  739. } else {
  740. throw new \Exception("数据错误");
  741. }
  742. } catch (\Exception $e) {
  743. return [
  744. 'code' => 1,
  745. 'msg' => $e->getMessage()
  746. ];
  747. }
  748. }
  749. }