WxOpenController.php 4.5 KB

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