MerchantController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace saas\controllers;
  3. use Yii;
  4. use biz\admin\services\AdminService;
  5. use biz\merchant\services\MerchantService;
  6. use common\components\util;
  7. use common\components\weixinUtil;
  8. use common\services\xhMerchantService;
  9. class MerchantController extends BaseController
  10. {
  11. //商家列表 shish 2019.12.20
  12. public function actionList()
  13. {
  14. $where = [];
  15. $list = MerchantService::getSaasMerchant($where);
  16. util::success($list);
  17. }
  18. //获取当前登陆老板的帐号详情,官网购买套餐时使用 shish 2020.1.11
  19. public function actionLoginAccount()
  20. {
  21. $userId = $this->userId;
  22. $admin = AdminService::getByCondition(['platUserId' => $userId]);
  23. if (empty($admin)) {
  24. util::fail('没有找到注册信息');
  25. }
  26. $merchantId = $admin['merchantId'];
  27. $merchant = MerchantService::getMerchantById($merchantId);
  28. util::success($merchant);
  29. }
  30. //商家信息 shish 2020.1.11
  31. public function actionDetail()
  32. {
  33. $id = Yii::$app->request->get('id');
  34. $merchant = MerchantService::getMerchantById(12358);
  35. util::success($merchant);
  36. }
  37. public function actionBindOpen()
  38. {
  39. $account = Yii::$app->request->get('account', 0);
  40. $merchant = MerchantService::getById($account);
  41. if (empty($merchant)) {
  42. util::fail('没有找到商家');
  43. }
  44. $wxAppId = $merchant['wxAppId'];
  45. $miniAppId = $merchant['miniAppId'];
  46. $openAppId = $merchant['openAppId'];
  47. echo "<pre>";
  48. $id = Yii::$app->request->get('id', 0);
  49. //创建平台,并将公众号绑定到平台
  50. if ($id == 1) {
  51. weixinUtil::createOpenAccount($wxAppId, $this->merchant);
  52. $return = weixinUtil::getOpenAccount($wxAppId, $this->merchant);
  53. print_r($return);
  54. if ($return['errcode'] == 0) {
  55. $openAppId = $return['open_appid'];
  56. xhMerchantService::updateById($this->merchantId, ['openAppId' => $openAppId]);
  57. }
  58. }
  59. //将小程序绑定到平台
  60. if ($id == 2) {
  61. $openAppId = $merchant['openAppId'];
  62. $r = weixinUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
  63. print_r($r);
  64. }
  65. //查询公众号 小程序的绑定情况
  66. if ($id == 3) {
  67. $return = weixinUtil::getOpenAccount($wxAppId, $this->merchant);
  68. print_r($return);
  69. $return = weixinUtil::getOpenAccount($miniAppId, $this->merchant, true);
  70. print_r($return);
  71. }
  72. //设置小程序服务器域名
  73. if ($id == 4) {
  74. weixinUtil::setDomain($this->merchant);
  75. weixinUtil::setWebViewDomain($this->merchant);
  76. }
  77. //为授权的小程序帐号上传小程序代码
  78. if ($id == 5) {
  79. $tId = $_GET['tId'];
  80. weixinUtil::miniCommit($this->merchant, $tId);
  81. }
  82. //获取小程序体验码
  83. if ($id == 6) {
  84. weixinUtil::getExperienceQrCode($this->merchant);
  85. }
  86. //获取授权小程序帐号已设置的类目
  87. if ($id == 7) {
  88. weixinUtil::getMiniCategory($this->merchant);
  89. }
  90. //获取小程序的第三方提交代码的页面配置
  91. if ($id == 8) {
  92. weixinUtil::getMiniPage($this->merchant);
  93. }
  94. //将第三方提交的代码包提交审核
  95. if ($id == 9) {
  96. weixinUtil::miniSubmitAudit($this->merchant);
  97. }
  98. //查询最新一次提交的审核状态
  99. if ($id == 10) {
  100. weixinUtil::miniGetLatestAuditStatus($this->merchant);
  101. }
  102. //发布已通过审核的小程序
  103. if ($id == 11) {
  104. weixinUtil::miniRelease($this->merchant);
  105. }
  106. //撤回审核
  107. if ($id == 12) {
  108. weixinUtil::rollbackCheck($this->merchant);
  109. }
  110. //生成 申请会员页 的小程序码
  111. if ($id == 13) {
  112. weixinUtil::generateMemberCode($this->merchant);
  113. }
  114. //解绑小程序和公众号绑定的平台
  115. if ($id == 14) {
  116. weixinUtil::unbindAccount($this->merchant);
  117. weixinUtil::unbindMiniProgram($this->merchant);
  118. }
  119. Yii::$app->end();
  120. $r = weixinUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
  121. print_r($r);
  122. echo $miniAppId . ' ' . $openAppId . ' ';
  123. $return = weixinUtil::getOpenAccount($wxAppId, $this->merchant);
  124. print_r($return);
  125. die;
  126. $return = weixinUtil::createOpenAccount($wxAppId, $this->merchant);
  127. print_r($return);
  128. die;
  129. $r = weixinUtil::bindOpenAccount($miniAppId, $openAppId, $merchant);
  130. print_r($r);
  131. echo $miniAppId . ' ' . $openAppId . ' ';
  132. $return = weixinUtil::getOpenAccount($wxAppId, $this->merchant);
  133. print_r($return);
  134. $return = weixinUtil::getOpenAccount($miniAppId, $this->merchant);
  135. print_r($return);
  136. die;
  137. if ($return['errcode'] == 0) {
  138. $openAppId = isset($return['open_appid']) ? $return['open_appid'] : '';
  139. } else {
  140. $return = weixinUtil::createOpenAccount($wxAppId, $this->merchant);
  141. if ($return['errcode'] == 0) {
  142. $openAppId = isset($return['open_appid']) ? $return['open_appid'] : '';
  143. }
  144. }
  145. echo "<br />openAppId:" . $openAppId . "<br />";
  146. if (!empty($openAppId)) {
  147. xhMerchantService::updateById($this->merchantId, ['openAppId' => $openAppId]);
  148. $r = weixinUtil::bindOpenAccount($miniAppId, $openAppId, $merchant);
  149. echo "绑定小程序结果:<br />";
  150. print_r($r);
  151. }
  152. echo "<br /><br />";
  153. $return = weixinUtil::getOpenAccount($wxAppId, $merchant);
  154. echo "微信appId:{$wxAppId}<br />";
  155. print_r($return);
  156. $return = weixinUtil::getOpenAccount($miniAppId, $merchant);
  157. echo "<br />小程序appId:{$miniAppId}<br />";
  158. print_r($return);
  159. }
  160. }