| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- namespace saas\controllers;
- use biz\merchant\services\MerchantExtendService;
- use biz\merchant\services\MerchantService;
- use common\components\util;
- use Yii;
- use common\components\wxUtil;
- class WxOpenController extends BaseController
- {
-
- public $withoutLogin = ['bind-open'];
-
- public function actionBindOpen()
- {
- $merchantId = Yii::$app->request->get('merchantId', 0);
- $merchant = MerchantService::getMerchantById($merchantId);
- if (empty($merchant)) {
- util::fail('没有找到商家');
- }
- $wxAppId = $merchant['wxAppId'];
- $miniAppId = $merchant['miniAppId'];
- $open_appid = $merchant['openAppId'];
- echo "<pre>";
-
- $id = Yii::$app->request->get('id', 0);
- //创建平台,并将公众号绑定到平台
- if ($id == 1) {
- wxUtil::createOpenAccount($wxAppId, $merchant);
- $return = wxUtil::getOpenAccount($wxAppId, $merchant);
- print_r($return);
- if ($return['errcode'] == 0) {
- $openAppId = $return['open_appid'];
- MerchantService::updateById($merchantId, ['openAppId' => $openAppId]);
- MerchantExtendService::updateByCondition(['merchantId'=>$merchantId],['openAppId'=>$openAppId,'openAppBind'=>1,'wxAuth'=>1]);
- }
- }
- //将小程序绑定到平台
- if ($id == 2) {
- $openAppId = $merchant['openAppId'];
- $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
- MerchantExtendService::updateByCondition(['merchantId'=>$merchantId],['openAppBind'=>3,'miniAuth'=>1]);
- print_r($r);
- }
- //查询公众号 小程序的绑定情况
- if ($id == 3) {
- $return = wxUtil::getOpenAccount($wxAppId, $merchant);
- print_r($return);
- $return = wxUtil::getOpenAccount($miniAppId, $merchant, true);
- print_r($return);
- }
-
- //设置小程序服务器域名
- if ($id == 4) {
- wxUtil::setDomain($merchant);
- wxUtil::setWebViewDomain($merchant);
- }
-
- //为授权的小程序帐号上传小程序代码
- if ($id == 5) {
- $tId = $_GET['tId'];
- wxUtil::miniCommit($merchant, $tId);
- }
-
- //获取小程序体验码
- if ($id == 6) {
- wxUtil::getExperienceQrCode($merchant);
- }
-
- //获取授权小程序帐号已设置的类目
- if ($id == 7) {
- wxUtil::getMiniCategory($merchant);
- }
-
- //获取小程序的第三方提交代码的页面配置
- if ($id == 8) {
- wxUtil::getMiniPage($merchant);
- }
-
- //将第三方提交的代码包提交审核
- if ($id == 9) {
- wxUtil::miniSubmitAudit($merchant);
- }
-
- //查询最新一次提交的审核状态
- if ($id == 10) {
- wxUtil::miniGetLatestAuditStatus($merchant);
- }
-
- //发布已通过审核的小程序
- if ($id == 11) {
- wxUtil::miniRelease($merchant);
- }
-
- //撤回审核
- if ($id == 12) {
- wxUtil::rollbackCheck($merchant);
- }
- //生成 申请会员页 的小程序码
- if ($id == 13) {
- wxUtil::generateMemberCode($merchant);
- }
- //解绑小程序和公众号绑定的平台
- if ($id == 14) {
- wxUtil::unbindAccount($merchant);
- wxUtil::unbindMiniProgram($merchant);
- }
- Yii::$app->end();
-
- $r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant, true);
- print_r($r);
- echo $miniAppId . ' ' . $open_appid . ' ';
-
- $return = wxUtil::getOpenAccount($wxAppId, $merchant);
- print_r($return);
- die;
-
- $return = wxUtil::createOpenAccount($wxAppId, $merchant);
- print_r($return);
- die;
-
- $r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant);
- print_r($r);
- echo $miniAppId . ' ' . $open_appid . ' ';
-
- $return = wxUtil::getOpenAccount($wxAppId, $merchant);
- print_r($return);
- $return = wxUtil::getOpenAccount($miniAppId, $merchant);
- print_r($return);
- die;
-
- if ($return['errcode'] == 0) {
- $open_appid = isset($return['open_appid']) ? $return['open_appid'] : '';
- } else {
- $return = wxUtil::createOpenAccount($wxAppId, $merchant);
- if ($return['errcode'] == 0) {
- $open_appid = isset($return['open_appid']) ? $return['open_appid'] : '';
- }
- }
- echo "<br />open_appid:" . $open_appid . "<br />";
- if (!empty($open_appid)) {
- xhMerchantService::updateById($merchantId, ['openAppId' => $open_appid]);
- MerchantExtendService::updateByCondition(['merchantId'=>$merchantId],['openAppId'=>$open_appid,'openAppBind'=>3,'miniAuth'=>1]);
- $r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant);
- echo "绑定小程序结果:<br />";
- print_r($r);
- }
- echo "<br /><br />";
- $return = wxUtil::getOpenAccount($wxAppId, $merchant);
- echo "微信appId:{$wxAppId}<br />";
- print_r($return);
- $return = wxUtil::getOpenAccount($miniAppId, $merchant);
- echo "<br />小程序appId:{$miniAppId}<br />";
- print_r($return);
- }
-
- }
|