GhsController.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. namespace pt\controllers;
  3. use biz\sj\services\MerchantExtendService;
  4. use Yii;
  5. use bizHd\admin\services\AdminService;
  6. use biz\sj\services\MerchantService;
  7. use common\components\util;
  8. use common\components\wxUtil;
  9. use common\services\xhMerchantService;
  10. class GhsController extends BaseController
  11. {
  12. public $guestAccessAction = ['bind-open'];
  13. //商家列表 shish 2019.12.20
  14. public function actionList()
  15. {
  16. $where = [];
  17. $list = MerchantService::getSaasMerchant($where);
  18. util::success($list);
  19. }
  20. //获取当前登陆老板的帐号详情,官网购买套餐时使用 shish 2020.1.11
  21. public function actionLoginAccount()
  22. {
  23. $userId = $this->userId;
  24. $admin = AdminService::getByCondition(['platUserId' => $userId]);
  25. if (empty($admin)) {
  26. util::fail('没有找到注册信息');
  27. }
  28. $merchantId = $admin['merchantId'];
  29. $merchant = MerchantService::getMerchantById($merchantId);
  30. util::success($merchant);
  31. }
  32. //商家信息 shish 2020.1.11
  33. public function actionDetail()
  34. {
  35. $id = Yii::$app->request->get('id');
  36. $merchant = MerchantService::getMerchantById(12358);
  37. util::success($merchant);
  38. }
  39. //开放平台设置相关操作 shish 2020.1.18
  40. public function actionBindOpen()
  41. {
  42. $merchantId = Yii::$app->request->get('account', 0);
  43. $merchant = MerchantService::getById($merchantId);
  44. if (empty($merchant)) {
  45. util::fail('没有找到商家');
  46. }
  47. $wxAppId = $merchant['wxAppId'];
  48. $miniAppId = $merchant['miniAppId'];
  49. $openAppId = $merchant['openAppId'];
  50. echo "<pre>";
  51. $id = Yii::$app->request->get('id', 0);
  52. //创建平台,并将公众号绑定到平台
  53. if ($id == 1) {
  54. wxUtil::createOpenAccount($wxAppId, $merchant);
  55. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false);
  56. print_r($return);
  57. if ($return['errcode'] == 0) {
  58. $openAppId = $return['open_appid'];
  59. xhMerchantService::updateById($merchantId, ['openAppId' => $openAppId]);
  60. MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppId' => $openAppId, 'openAppBind' => 1, 'wxAuth' => 1]);
  61. }
  62. }
  63. //将小程序绑定到平台
  64. if ($id == 2) {
  65. $openAppId = $merchant['openAppId'];
  66. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
  67. MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppBind' => 3, 'miniAuth' => 1]);
  68. print_r($r);
  69. }
  70. //查询公众号 小程序的绑定情况
  71. if ($id == 3) {
  72. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false);
  73. echo "公众号绑定情况:<br />";
  74. print_r($return);
  75. $return = wxUtil::getOpenAccount($miniAppId, $merchant, true);
  76. echo "小程序绑定情况:<br />";
  77. print_r($return);
  78. }
  79. //设置小程序服务器域名
  80. if ($id == 4) {
  81. wxUtil::setDomain($merchant, 2);
  82. wxUtil::setWebViewDomain($merchant, 2);
  83. }
  84. //为授权的小程序帐号上传小程序代码
  85. if ($id == 5) {
  86. //模板id
  87. $tId = Yii::$app->request->get('tId');
  88. wxUtil::miniCommit($merchant, $tId);
  89. }
  90. //获取小程序体验码
  91. if ($id == 6) {
  92. wxUtil::getExperienceQrCode($merchant);
  93. }
  94. //获取授权小程序帐号已设置的类目
  95. if ($id == 7) {
  96. wxUtil::getMiniCategory($merchant);
  97. }
  98. //获取小程序的第三方提交代码的页面配置
  99. if ($id == 8) {
  100. wxUtil::getMiniPage($merchant);
  101. }
  102. //将第三方提交的代码包提交审核
  103. if ($id == 9) {
  104. wxUtil::miniSubmitAudit($merchant);
  105. }
  106. //查询最新一次提交的审核状态
  107. if ($id == 10) {
  108. wxUtil::miniGetLatestAuditStatus($merchant);
  109. }
  110. //发布已通过审核的小程序
  111. if ($id == 11) {
  112. wxUtil::miniRelease($merchant);
  113. }
  114. //撤回审核
  115. if ($id == 12) {
  116. wxUtil::rollbackCheck($merchant);
  117. }
  118. //生成 申请会员页 的小程序码
  119. if ($id == 13) {
  120. wxUtil::generateMemberCode($merchant);
  121. }
  122. //解绑小程序和公众号绑定的平台
  123. if ($id == 14) {
  124. wxUtil::unbindAccount($merchant);
  125. wxUtil::unbindMiniProgram($merchant);
  126. }
  127. Yii::$app->end();
  128. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
  129. print_r($r);
  130. echo $miniAppId . ' ' . $openAppId . ' ';
  131. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false);
  132. print_r($return);
  133. die;
  134. $return = wxUtil::createOpenAccount($wxAppId, $merchant);
  135. print_r($return);
  136. die;
  137. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, false);
  138. print_r($r);
  139. echo $miniAppId . ' ' . $openAppId . ' ';
  140. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false);
  141. print_r($return);
  142. $return = wxUtil::getOpenAccount($miniAppId, $merchant, false);
  143. print_r($return);
  144. die;
  145. if ($return['errcode'] == 0) {
  146. $openAppId = isset($return['open_appid']) ? $return['open_appid'] : '';
  147. } else {
  148. $return = wxUtil::createOpenAccount($wxAppId, $merchant);
  149. if ($return['errcode'] == 0) {
  150. $openAppId = isset($return['open_appid']) ? $return['open_appid'] : '';
  151. }
  152. }
  153. echo "<br />openAppId:" . $openAppId . "<br />";
  154. if (!empty($openAppId)) {
  155. xhMerchantService::updateById($merchantId, ['openAppId' => $openAppId]);
  156. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, false);
  157. echo "绑定小程序结果:<br />";
  158. print_r($r);
  159. }
  160. echo "<br /><br />";
  161. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false);
  162. echo "微信appId:{$wxAppId}<br />";
  163. print_r($return);
  164. $return = wxUtil::getOpenAccount($miniAppId, $merchant, false);
  165. echo "<br />小程序appId:{$miniAppId}<br />";
  166. print_r($return);
  167. }
  168. //平台帐号激活 shish 2020.2.15
  169. public function actionAddPlatformMerchant()
  170. {
  171. MerchantService::initOpenMerchant();
  172. echo 'ok';
  173. }
  174. //注释商家 shish 2020.3.4
  175. public function actionCancel()
  176. {
  177. if (getenv('YII_ENV') != 'test') {
  178. util::fail('只有测试环境才能操作');
  179. }
  180. $id = Yii::$app->request->get('id', 0);
  181. $merchant = MerchantService::getById($id, true);
  182. if (isset($merchant->wxAppId) && empty($merchant->wxAppId)) {
  183. util::fail('已注销/未授权');
  184. }
  185. $merchant->wxAppId = '';
  186. $merchant->miniAppId = '';
  187. $merchant->save();
  188. $extend = MerchantExtendService::getByMerchantId($id, true);
  189. $extend->miniAppId = '';
  190. $extend->wxAppId = '';
  191. $extend->save();
  192. util::complete();
  193. }
  194. //商家h5商城二维码 shish 2020.4.30
  195. public function actionGetH5MallQrCode()
  196. {
  197. $id = Yii::$app->request->get('id', 0);
  198. $imgUrl = MerchantService::getH5MallQrCode($id);
  199. util::success(['imgUrl' => $imgUrl]);
  200. }
  201. }