WxOpenController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace saas\controllers;
  3. use biz\merchant\services\MerchantExtendService;
  4. use biz\merchant\services\MerchantService;
  5. use biz\weixin\services\MiniProgramService;
  6. use common\components\util;
  7. use Yii;
  8. use common\components\wxUtil;
  9. class WxOpenController extends BaseController
  10. {
  11. public $withoutLogin = ['bind-open'];
  12. public function actionBindOpen()
  13. {
  14. $merchantId = Yii::$app->request->get('merchantId', 0);
  15. $merchant = MerchantService::getMerchantById($merchantId);
  16. if (empty($merchant)) {
  17. util::fail('没有找到商家');
  18. }
  19. $wxAppId = $merchant['wxAppId'];
  20. $miniAppId = $merchant['miniAppId'];
  21. $open_appid = $merchant['openAppId'];
  22. echo "<pre>";
  23. $id = Yii::$app->request->get('id', 0);
  24. //创建平台,并将公众号绑定到平台
  25. if ($id == 1) {
  26. wxUtil::createOpenAccount($wxAppId, $merchant);
  27. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  28. print_r($return);
  29. if ($return['errcode'] == 0) {
  30. $openAppId = $return['open_appid'];
  31. MerchantService::updateById($merchantId, ['openAppId' => $openAppId]);
  32. MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppId' => $openAppId, 'openAppBind' => 1, 'wxAuth' => 1]);
  33. }
  34. }
  35. //将小程序绑定到平台
  36. if ($id == 2) {
  37. $openAppId = $merchant['openAppId'];
  38. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
  39. MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppBind' => 3, 'miniAuth' => 1]);
  40. print_r($r);
  41. }
  42. //查询公众号 小程序的绑定情况
  43. if ($id == 3) {
  44. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  45. print_r($return);
  46. $return = wxUtil::getOpenAccount($miniAppId, $merchant, true);
  47. print_r($return);
  48. }
  49. //设置小程序服务器域名
  50. if ($id == 4) {
  51. wxUtil::setDomain($merchant);
  52. wxUtil::setWebViewDomain($merchant);
  53. }
  54. //为授权的小程序帐号上传小程序代码
  55. if ($id == 5) {
  56. $tId = $_GET['tId'];
  57. wxUtil::miniCommit($merchant, $tId);
  58. }
  59. //获取小程序体验码
  60. if ($id == 6) {
  61. wxUtil::getExperienceQrCode($merchant);
  62. }
  63. //获取授权小程序帐号已设置的类目
  64. if ($id == 7) {
  65. wxUtil::getMiniCategory($merchant);
  66. }
  67. //获取小程序的第三方提交代码的页面配置
  68. if ($id == 8) {
  69. wxUtil::getMiniPage($merchant);
  70. }
  71. //将第三方提交的代码包提交审核
  72. if ($id == 9) {
  73. wxUtil::miniSubmitAudit($merchant);
  74. }
  75. //查询最新一次提交的审核状态
  76. if ($id == 10) {
  77. wxUtil::miniGetLatestAuditStatus($merchant);
  78. }
  79. //发布已通过审核的小程序
  80. if ($id == 11) {
  81. MiniProgramService::release($merchant);
  82. }
  83. //撤回审核
  84. if ($id == 12) {
  85. wxUtil::rollbackCheck($merchant);
  86. }
  87. //生成 申请会员页 的小程序码
  88. if ($id == 13) {
  89. wxUtil::generateMemberCode($merchant);
  90. }
  91. //解绑小程序和公众号绑定的平台
  92. if ($id == 14) {
  93. wxUtil::unbindAccount($merchant);
  94. wxUtil::unbindMiniProgram($merchant);
  95. }
  96. Yii::$app->end();
  97. $r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant, true);
  98. print_r($r);
  99. echo $miniAppId . ' ' . $open_appid . ' ';
  100. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  101. print_r($return);
  102. die;
  103. $return = wxUtil::createOpenAccount($wxAppId, $merchant);
  104. print_r($return);
  105. die;
  106. $r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant);
  107. print_r($r);
  108. echo $miniAppId . ' ' . $open_appid . ' ';
  109. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  110. print_r($return);
  111. $return = wxUtil::getOpenAccount($miniAppId, $merchant);
  112. print_r($return);
  113. die;
  114. if ($return['errcode'] == 0) {
  115. $open_appid = isset($return['open_appid']) ? $return['open_appid'] : '';
  116. } else {
  117. $return = wxUtil::createOpenAccount($wxAppId, $merchant);
  118. if ($return['errcode'] == 0) {
  119. $open_appid = isset($return['open_appid']) ? $return['open_appid'] : '';
  120. }
  121. }
  122. echo "<br />open_appid:" . $open_appid . "<br />";
  123. if (!empty($open_appid)) {
  124. xhMerchantService::updateById($merchantId, ['openAppId' => $open_appid]);
  125. MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppId' => $open_appid, 'openAppBind' => 3, 'miniAuth' => 1]);
  126. $r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant);
  127. echo "绑定小程序结果:<br />";
  128. print_r($r);
  129. }
  130. echo "<br /><br />";
  131. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  132. echo "微信appId:{$wxAppId}<br />";
  133. print_r($return);
  134. $return = wxUtil::getOpenAccount($miniAppId, $merchant);
  135. echo "<br />小程序appId:{$miniAppId}<br />";
  136. print_r($return);
  137. }
  138. }