WxOpenController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. $r = MiniProgramService::release($merchant);
  82. print_r($r);
  83. }
  84. //撤回审核
  85. if ($id == 12) {
  86. wxUtil::rollbackCheck($merchant);
  87. }
  88. //生成 申请会员页 的小程序码
  89. if ($id == 13) {
  90. wxUtil::generateMemberCode($merchant);
  91. }
  92. //解绑小程序和公众号绑定的平台
  93. if ($id == 14) {
  94. wxUtil::unbindAccount($merchant);
  95. wxUtil::unbindMiniProgram($merchant);
  96. }
  97. Yii::$app->end();
  98. $r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant, true);
  99. print_r($r);
  100. echo $miniAppId . ' ' . $open_appid . ' ';
  101. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  102. print_r($return);
  103. die;
  104. $return = wxUtil::createOpenAccount($wxAppId, $merchant);
  105. print_r($return);
  106. die;
  107. $r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant);
  108. print_r($r);
  109. echo $miniAppId . ' ' . $open_appid . ' ';
  110. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  111. print_r($return);
  112. $return = wxUtil::getOpenAccount($miniAppId, $merchant);
  113. print_r($return);
  114. die;
  115. if ($return['errcode'] == 0) {
  116. $open_appid = isset($return['open_appid']) ? $return['open_appid'] : '';
  117. } else {
  118. $return = wxUtil::createOpenAccount($wxAppId, $merchant);
  119. if ($return['errcode'] == 0) {
  120. $open_appid = isset($return['open_appid']) ? $return['open_appid'] : '';
  121. }
  122. }
  123. echo "<br />open_appid:" . $open_appid . "<br />";
  124. if (!empty($open_appid)) {
  125. xhMerchantService::updateById($merchantId, ['openAppId' => $open_appid]);
  126. MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppId' => $open_appid, 'openAppBind' => 3, 'miniAuth' => 1]);
  127. $r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant);
  128. echo "绑定小程序结果:<br />";
  129. print_r($r);
  130. }
  131. echo "<br /><br />";
  132. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  133. echo "微信appId:{$wxAppId}<br />";
  134. print_r($return);
  135. $return = wxUtil::getOpenAccount($miniAppId, $merchant);
  136. echo "<br />小程序appId:{$miniAppId}<br />";
  137. print_r($return);
  138. }
  139. }