WxOpenController.php 4.0 KB

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