WxOpenController.php 4.1 KB

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