浏览代码

开放平台

shish 6 年之前
父节点
当前提交
e30cb2144e
共有 2 个文件被更改,包括 2033 次插入2033 次删除
  1. 515 515
      app/saas/controllers/WxOpenController.php
  2. 1518 1518
      common/components/wxUtil.php

+ 515 - 515
app/saas/controllers/WxOpenController.php

@@ -22,519 +22,519 @@ use common\services\xhWxOpenService;
 
 class WxOpenController extends BaseController
 {
-	
-	public $withoutLogin = ['bind-open'];
-	
-	public function actionBindOpen()
-	{
-		$merchantId = Yii::$app->request->get('merchantId', 0);
-		$isOpen = Yii::$app->request->get('isOpen', 0);
-		if ($isOpen == 1) {
-			$merchant = WxOpenService::getWxInfo();
-		} else {
-			$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, false, $isOpen);
-			print_r($return);
-			if ($return['errcode'] == 0) {
-				$openAppId = $return['open_appid'];
-				
-				if ($isOpen == 1) {
-					WxOpenService::updateOpen(['appIdCreated' => $openAppId, 'openAppBind' => 1]);
-				} else {
-					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, $isOpen);
-			
-			if ($isOpen == 1) {
-				WxOpenService::updateOpen(['appIdCreated' => $openAppId, 'openAppBind' => 3]);
-			} else {
-				MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppBind' => 3, 'miniAuth' => 1]);
-			}
-			
-			
-			print_r($r);
-		}
-		//查询公众号 小程序的绑定情况
-		if ($id == 3) {
-			$return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
-			print_r($return);
-			$return = wxUtil::getOpenAccount($miniAppId, $merchant, true, $isOpen);
-			print_r($return);
-		}
-		
-		//设置小程序服务器域名
-		if ($id == 4) {
-			wxUtil::setDomain($merchant, $isOpen);
-			wxUtil::setWebViewDomain($merchant, $isOpen);
-		}
-		
-		//为授权的小程序帐号上传小程序代码
-		if ($id == 5) {
-			$tId = $_GET['tId'];
-			wxUtil::miniCommit($merchant, $tId, $isOpen);
-		}
-		
-		//获取小程序体验码
-		if ($id == 6) {
-			wxUtil::getExperienceQrCode($merchant, $isOpen);
-		}
-		
-		//获取授权小程序帐号已设置的类目
-		if ($id == 7) {
-			wxUtil::getMiniCategory($merchant, $isOpen);
-		}
-		
-		//获取小程序的第三方提交代码的页面配置
-		if ($id == 8) {
-			wxUtil::getMiniPage($merchant, $isOpen);
-		}
-		
-		//将第三方提交的代码包提交审核
-		if ($id == 9) {
-			wxUtil::miniSubmitAudit($merchant);
-		}
-		
-		//查询最新一次提交的审核状态
-		if ($id == 10) {
-			wxUtil::miniGetLatestAuditStatus($merchant);
-		}
-		
-		//发布已通过审核的小程序
-		if ($id == 11) {
-			$r = MiniProgramService::release($merchant, $isOpen);
-			print_r($r);
-		}
-		
-		//撤回审核
-		if ($id == 12) {
-			wxUtil::rollbackCheck($merchant, $isOpen);
-		}
-		//生成 申请会员页 的小程序码
-		if ($id == 13) {
-			//wxUtil::generateMemberCode($merchant,$shopId ,$isOpen);
-		}
-		//解绑小程序和公众号绑定的平台
-		if ($id == 14) {
-			wxUtil::unbindAccount($merchant, $isOpen);
-			wxUtil::unbindMiniProgram($merchant, $isOpen);
-		}
-		Yii::$app->end();
-		
-		$r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant, true, $isOpen);
-		print_r($r);
-		echo $miniAppId . ' ' . $open_appid . ' ';
-		
-		$return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
-		print_r($return);
-		die;
-		
-		$return = wxUtil::createOpenAccount($wxAppId, $merchant);
-		print_r($return);
-		die;
-		
-		$r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant, false, $isOpen);
-		print_r($r);
-		echo $miniAppId . ' ' . $open_appid . ' ';
-		
-		$return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
-		print_r($return);
-		$return = wxUtil::getOpenAccount($miniAppId, $merchant, false, $isOpen);
-		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, false, $isOpen);
-			echo "绑定小程序结果:<br />";
-			print_r($r);
-		}
-		echo "<br /><br />";
-		$return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
-		echo "微信appId:{$wxAppId}<br />";
-		print_r($return);
-		$return = wxUtil::getOpenAccount($miniAppId, $merchant, false, $isOpen);
-		echo "<br />小程序appId:{$miniAppId}<br />";
-		print_r($return);
-	}
-	
-	//开放平台开始授权 shish 2020.1.16
-	public function actionBeginAuth()
-	{
-		$merchantId = Yii::$app->request->get('id', 0);
-		$open = WxOpenService::getOpen();
-		//1只显示公众号 2只显示小程序  3显示公众号和小程序
-		$authType = Yii::$app->request->get('authType', 3);
-		$pre = wxUtil::getPreAuthCode($open);
-		$appId = $open['appId'];
-		$oData = [];
-		$oData['preAuthCodeTime'] = date("Y-m-d H:i:s");
-		//设置预授码过期,让下个用户可以获取新的预授码
-		xhWxOpenService::updateById(1, $oData);
-		$url = Yii::$app->params['saasHost'] . '/wx-open-callback/' . $merchantId;
-		echo "<a href='https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid={$appId}&pre_auth_code={$pre}&redirect_uri={$url}&auth_type={$authType}'>授权</a>";
-	}
-	
-	//平台没有绑定商家公众号时初始化一个商家 shish 2020.2.11
-	public function actionAddMerchant()
-	{
-		AdClass::initAdd(12362);
-		$return = MerchantService::initOpenMerchant();
-		dd($return);
-	}
-	
-	public function actionCheckMerchantName()
-	{
-		$get = Yii::$app->request->get();
-		$merchantName = isset($get['merchantName']) ? $get['merchantName'] : '';
-		$m = xhMerchantService::getByMerchantName($merchantName);
-		if (!empty($m)) {
-			util::fail('公众号名称已经使用');
-		}
-		util::complete();
-	}
-	
-	/**
-	 * 下载微信里的图片到服务器
-	 */
-	public function actionDownloadWxImg()
-	{
-		$get = Yii::$app->request->get();
-		$mediaId = isset($get['mediaId']) ? $get['mediaId'] : '';
-		$imgList = wxUtil::downloadmediaIdImg($this->merchant, $mediaId);
-		if (!empty($imgList)) {
-			util::success($imgList);
-		}
-		util::fail();
-	}
-	
-	//创建平台使用的公众号
-	public function actionCallback()
-	{
-		$get = Yii::$app->request->get();
-		if (isset($get['auth_code']) == false) {
-			util::stop('公众号授权回调未成功');
-		}
-		$id = isset($get['id']) ? $get['id'] : 0;
-		$code = $get['auth_code'];
-		//使用授权码换取公众号的接口调用凭据和授权信息
-		$authorize = wxUtil::getAuthorizer($code);
-		if (isset($authorize['authorization_info']) == false) {
-			util::stop('未换取公众号的接口调用凭据和授权信息');
-		}
-		$info = $authorize['authorization_info'];
-		$authorizeAppId = $info['authorizer_appid'];
-		$authorize_access_token = $info['authorizer_access_token'];
-		$expires_in = $info['expires_in'];//7200
-		$authorize_refresh_token = $info['authorizer_refresh_token'];
-		//获取授权方的公众号帐号基本信息
-		$authorizeDetailInfo = wxUtil::getAuthorizerInfo($authorizeAppId);
-		if (isset($authorizeDetailInfo['authorizer_info']) == false) {
-			util::stop('没有获取到公众号帐号基本信息');
-		}
-		$authorize_info = $authorizeDetailInfo['authorizer_info'];
-		//$nick_name = $authorize_info['nick_name'];
-		$head_img = $authorize_info['head_img'];
-		$service_type_info = $authorize_info['service_type_info'];
-		if ($service_type_info['id'] != 2) {
-			if (isset($authorize_info['MiniProgramInfo']) == false || empty($authorize_info['MiniProgramInfo'])) {
-				util::stop('公众号不是服务号');
-			}
-		}
-		$verify_type_info = $authorize_info['verify_type_info'];
-		if ($verify_type_info['id'] != 0) {
-			if (isset($authorize_info['MiniProgramInfo']) == false || empty($authorize_info['MiniProgramInfo'])) {
-				util::stop('公众号还没有认证哦');
-			}
-		}
-		$user_name = $authorize_info['user_name'];
-		$alias = $authorize_info['alias'];
-		$qrCodeUrl = $authorize_info['qrcode_url'];
-		$accessTokenTime = date("Y-m-d H:i:s", (time() + $expires_in - 100));//安全起见,将过期时间设置得比微信里还短100秒
-		
-		//开放平台还没有关联公众号,先将开放平台关联公众号
-		$open = WxOpenService::getOpen();
-		if (isset($open['merchantId']) && empty($open['merchantId'])) {
-			WxOpenService::updateById(1, ['merchantId' => $id]);
-		}
-		
-		$extend = MerchantExtendClass::getByMerchantId($id);
-		
-		$open = WxOpenService::getOpen();
-		$time = time();
-		
-		//小程序
-		if (isset($authorize_info['MiniProgramInfo']) && !empty($authorize_info['MiniProgramInfo'])) {
-			$miniData = [
-				'miniAppId' => $authorizeAppId,
-				'miniAuth' => 1,
-				'miniAccessToken' => $authorize_access_token,
-				'miniAccessTokenTime' => $accessTokenTime,
-				'miniRefreshToken' => $authorize_refresh_token,
-			];
-			
-			//开放平台没有小程序先绑定开放平台要用的小程序
-			if (isset($open['wx_mini_base_id']) == false || empty($open['wx_mini_base_id'])) {
-				$miniData['addTime'] = $time;
-				
-				//花卉宝
-				$miniAppSecret = 'f1ae43c87080da21ac631609b0dbb147';
-				if (getenv('YII_ENV') == 'dev') {
-					//花美玲
-					$miniAppSecret = '12f90039b1245ba6abf2e4184462fb30';
-				}
-				$miniData['miniAppSecret'] = $miniAppSecret;
-				
-				$wxMiniBaseRespond = WxMiniBaseService::add($miniData);
-				$wxMiniBaseId = $wxMiniBaseRespond['id'];
-				WxOpenService::updateOpen(['wx_mini_base_id' => $wxMiniBaseId]);
-				util::stop('开放平台成功绑定小程序');
-			}
-			
-			
-			if (isset($extend['miniAppId']) && !empty($extend['miniAppId'])) {
-				if ($extend['miniAppId'] != $authorizeAppId) {
-					util::stop('授权的小程序与商家已绑定的小程序不一致');
-				}
-			} else {
-				util::stop('数据库请先填写小程序 miniAppId miniAppSecret');
-			}
-			
-			xhMerchantExtendService::updateByMerchantId($id, $miniData);
-			MerchantService::updateById($id, ['miniAppId' => $authorizeAppId]);
-			Yii::info('小程序信息更新成功:' . json_encode($authorize_info));
-			util::stop("小程序信息更新成功");
-			
-		} else {
-			if (isset($extend['wxAppId']) && !empty($extend['wxAppId'])) {
-				if ($extend['wxAppId'] != $authorizeAppId) {
-					util::stop('授权的公众号与商家已绑定的公众号不一致');
-				}
-			}
-		}
-		
-		$wxData = [];
-		$appData['wxUserName'] = $user_name;
-		$appData['wxAliasName'] = $alias;
-		//公众号logo
-		$wxData['logo'] = WxBaseClass::saveLogo($head_img, $id);
-		//公众号二维码
-		$wxData['wxQrCodeUrl'] = WxBaseClass::saveQrCode($qrCodeUrl, $id);
-		$wxData['wxAppId'] = $authorizeAppId;
-		$wxData['wxAccessToken'] = $authorize_access_token;
-		$wxData['wxAccessTokenTime'] = $accessTokenTime;
-		$wxData['wxRefreshToken'] = $authorize_refresh_token;
-		//开放平台还没有公众号先绑定开放平台的公众号
-		if (isset($open['wx_base_id']) == false || empty($open['wx_base_id'])) {
-			$wxData['addTime'] = $time;
-			$wxBaseRespond = WxBaseService::add($wxData);
-			$wxBaseId = $wxBaseRespond['id'];
-			WxOpenService::updateOpen(['wx_base_id' => $wxBaseId]);
-			util::stop('开放平台成功绑定公众号');
-		}
-		$wxData['status'] = 1;//审核通过
-		xhMerchantService::updateById($id, $wxData);
-		MerchantExtendClass::updateByCondition(['merchantId' => $id], ['wxAppId' => $authorizeAppId, 'wxAuth' => 1]);
-		
-		//还没有完成初始化先进行初始化
-		if (isset($extend['init']) && $extend['init'] == 0) {
-			$data = ['merchantId' => $id];
-			$producer = Yii::$app->rabbitmq->getProducer('openShopInitProducer');
-			$msg = serialize($data);
-			$producer->publish($msg, 'openShopInitExchange', 'openShopInitRoute');
-		}
-		echo 'ok';
-	}
-	
-	public function actionResult()
-	{
-		$get = Yii::$app->request->get();
-		$id = isset($get['id']) ? $get['id'] : 0;
-		$merchant = xhMerchantService::getById($id);
-		$status = configDict::getConfig('merchantStatusName');
-		$orMechantId = configDict::getConfig('merchantId');
-		$originalMerchant = xhMerchantService::getById($orMechantId);
-		return $this->renderPartial('result', ['originalMerchant' => $originalMerchant, 'merchant' => $merchant, 'status' => $status]);
-	}
-	
-	public function actionCheckInviteCode()
-	{
-		$get = Yii::$app->request->get();
-		$code = isset($get['code']) ? $get['code'] : '';
-		$invite = xhInviteService::getByCode($code);
-		if (empty($invite)) {
-			util::fail('邀请码错误');
-		}
-		$now = time();
-		if ($now > $invite['deadline']) {
-			util::fail('邀请码已经失效');
-		}
-		if (!empty($invite['takeStatus'])) {
-			util::fail('邀请码已经使用');
-		}
-		util::success($invite);
-	}
-	
-	public function actionSelect()
-	{
-		$isWx = util::isWx();
-		if ($isWx == false) {
-			return $this->renderPartial('notWeixin');
-		}
-		return $this->renderPartial('select');
-	}
-	
-	public function actionApi()
-	{
-		$openData = file_get_contents('php://input');
-		if (isset ($openData) == false || empty($openData)) {
-			util::stop('has no post data');
-		}
-		$weixinSecret = Yii::getAlias("@vendor/weixinSecret");
-		require_once($weixinSecret . '/wxBizMsgCrypt.php');
-		$get = Yii::$app->request->get();
-		$encryptMsg = $openData;
-		$openId = configDict::getConfig('openId');
-		$open = xhWxOpenService::getById($openId);
-		$encodingAesKey = $open['aesKey'];
-		$token = $open['token'];
-		$appId = $open['appId'];
-		$appSecret = $open['appSecret'];
-		$signature = isset($get['signature']) ? $get['signature'] : '';
-		$timestamp = isset($get['timestamp']) ? $get['timestamp'] : '';
-		$nonce = isset($get['nonce']) ? $get['nonce'] : '';
-		$encrypt_type = isset($get['encrypt_type']) ? $get['encrypt_type'] : '';
-		$msg_signature = isset($get['msg_signature']) ? $get['msg_signature'] : '';
-		$xml_tree = new \DOMDocument();
-		$xml_tree->loadXML($encryptMsg);
-		$array_e = $xml_tree->getElementsByTagName('Encrypt');
-		$encrypt = $array_e->item(0)->nodeValue;
-		$format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%s]]></Encrypt></xml>";
-		$from_xml = sprintf($format, $encrypt);
-		
-		$formString = " token:" . $token . "\n encodingAesKey:" . $encodingAesKey . "\n appId:" . $appId . "\n msg_signature:" . $msg_signature . "\n appSecret:" . $appSecret . "\n timestamp:" . $timestamp . "\n nonce:" . $nonce;
-		Yii::warning($formString);
-		
-		$formString2 = "from_xml:" . $from_xml;
-		Yii::warning($formString2);
-		
-		//第三方收到公众号平台发送的消息
-		$pc = new \WXBizMsgCrypt($token, $encodingAesKey, $appId);
-		$msg = '';//解密后的消息
-		$errCode = $pc->decryptMsg($msg_signature, $timestamp, $nonce, $from_xml, $msg);
-		if ($errCode != 0) {
-			Yii::warning("解密未成功,错误代码:" . $errCode . "。(出现过的情况汇总:-40001 有可能token、encodingAesKey、appId等填写不对,请仔细核对每个值)");
-			util::stop();
-		}
-		$postObj = simplexml_load_string($msg, 'SimpleXMLElement', LIBXML_NOCDATA);
-		$infoType = $postObj->InfoType;
-		switch ($infoType) {
-			//推送 componentVerifyTicket
-			case 'component_verify_ticket':
-				$componentVerifyTicket = $postObj->ComponentVerifyTicket;
-				if (!empty($componentVerifyTicket)) {
-					$oData = [];
-					$oData['verifyTicket'] = (string)$componentVerifyTicket;
-					$oData['verifyTicketTime'] = date("Y-m-d H:i:s", $timestamp + 600);//每10分钟(600秒)推一次
-					xhWxOpenService::updateById($openId, $oData);
-					Yii::warning("component_verify_ticket:" . (string)$componentVerifyTicket);
-					util::stop('success');
-				}
-				break;
-			//取消授权通知
-			case 'unauthorized':
-				$AppId = $postObj->AppId;
-				$authorizeAppid = $postObj->AuthorizerAppid;
-				$merchant = xhMerchantService::getByAppId($authorizeAppid);
-				if (!empty($merchant)) {
-					$merchantId = $merchant['id'];
-					//自主冻结
-					xhMerchantService::updateById($merchantId, ['status' => 5]);
-				}
-				break;
-			//授权成功通知
-			case 'authorized':
-				$AppId = $postObj->AppId;//第三方平台appid
-				$CreateTime = $postObj->CreateTime;//公众号
-				$authorizeAppid = $postObj->AuthorizerAppid;//授权码,可用于换取公众号的接口调用凭据,详细见上面的说明
-				$AuthorizationCode = $postObj->AuthorizationCode;
-				$AuthorizationCodeExpiredTime = $postObj->AuthorizationCodeExpiredTime;//授权码过期时间
-				break;
-			//授权更新通知
-			case 'updateauthorized':
-				$AppId = $postObj->AppId;
-				$CreateTime = $postObj->CreateTime;
-				$authorizeAppid = $postObj->AuthorizerAppid;
-				$AuthorizationCode = $postObj->AuthorizationCode;
-				$AuthorizationCodeExpiredTime = $postObj->AuthorizationCodeExpiredTime;
-				
-				util::stop();
-				
-				$authorize = wxUtil::getAuthorizer($AuthorizationCode);
-				if (isset($authorize['authorization_info']) == false) {
-					$msg = '授权回调获取到auth_code,但未换取公众号的接口调用凭据和授权信息!!';
-					Yii::warning($msg, __METHOD__);
-					Yii::$app->end();
-				}
-				$info = $authorize['authorization_info'];
-				$authorizeAppId = $info['authorizer_appid'];
-				$authorize_access_token = $info['authorizer_access_token'];
-				$expires_in = $info['expires_in'];//7200
-				$authorize_refresh_token = $info['authorizer_refresh_token'];
-				$merchant = xhMerchantService::getByAppId($authorizeAppId);
-				if (empty($merchant)) {
-					return false;
-				}
-				$merchantId = $merchant['id'];
-				$wxData = [];
-				$wxData['wxAccessToken'] = $authorize_access_token;
-				$wxData['wxRefreshToken'] = $authorize_refresh_token;
-				$wxData['wxAccessTokenTime'] = date("Y-m-d H:i:s", (time() + $expires_in - 100));
-				$wxData['status'] = 1;
-				xhMerchantService::updateById($merchantId, $wxData);
-				break;
-			default:
-		}
-		Yii::warning("---wx open data end--- \n");
-	}
-	
-	//获取平台信息 shish 2020.4.12
-	public function actionGetWxOpen()
-	{
-		$open = WxOpenService::getOpen();
-		util::success($open);
-	}
-	
+
+    public $withoutLogin = ['bind-open'];
+
+    public function actionBindOpen()
+    {
+        $merchantId = Yii::$app->request->get('merchantId', 0);
+        $isOpen = Yii::$app->request->get('isOpen', 0);
+        if ($isOpen == 1) {
+            $merchant = WxOpenService::getWxInfo();
+        } else {
+            $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, $isOpen);
+            $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
+            print_r($return);
+            if ($return['errcode'] == 0) {
+                $openAppId = $return['open_appid'];
+
+                if ($isOpen == 1) {
+                    WxOpenService::updateOpen(['appIdCreated' => $openAppId, 'openAppBind' => 1]);
+                } else {
+                    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, $isOpen);
+
+            if ($isOpen == 1) {
+                WxOpenService::updateOpen(['appIdCreated' => $openAppId, 'openAppBind' => 3]);
+            } else {
+                MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppBind' => 3, 'miniAuth' => 1]);
+            }
+
+
+            print_r($r);
+        }
+        //查询公众号 小程序的绑定情况
+        if ($id == 3) {
+            $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
+            print_r($return);
+            $return = wxUtil::getOpenAccount($miniAppId, $merchant, true, $isOpen);
+            print_r($return);
+        }
+
+        //设置小程序服务器域名
+        if ($id == 4) {
+            wxUtil::setDomain($merchant, $isOpen);
+            wxUtil::setWebViewDomain($merchant, $isOpen);
+        }
+
+        //为授权的小程序帐号上传小程序代码
+        if ($id == 5) {
+            $tId = $_GET['tId'];
+            wxUtil::miniCommit($merchant, $tId, $isOpen);
+        }
+
+        //获取小程序体验码
+        if ($id == 6) {
+            wxUtil::getExperienceQrCode($merchant, $isOpen);
+        }
+
+        //获取授权小程序帐号已设置的类目
+        if ($id == 7) {
+            wxUtil::getMiniCategory($merchant, $isOpen);
+        }
+
+        //获取小程序的第三方提交代码的页面配置
+        if ($id == 8) {
+            wxUtil::getMiniPage($merchant, $isOpen);
+        }
+
+        //将第三方提交的代码包提交审核
+        if ($id == 9) {
+            wxUtil::miniSubmitAudit($merchant);
+        }
+
+        //查询最新一次提交的审核状态
+        if ($id == 10) {
+            wxUtil::miniGetLatestAuditStatus($merchant);
+        }
+
+        //发布已通过审核的小程序
+        if ($id == 11) {
+            $r = MiniProgramService::release($merchant, $isOpen);
+            print_r($r);
+        }
+
+        //撤回审核
+        if ($id == 12) {
+            wxUtil::rollbackCheck($merchant, $isOpen);
+        }
+        //生成 申请会员页 的小程序码
+        if ($id == 13) {
+            //wxUtil::generateMemberCode($merchant,$shopId ,$isOpen);
+        }
+        //解绑小程序和公众号绑定的平台
+        if ($id == 14) {
+            wxUtil::unbindAccount($merchant, $isOpen);
+            wxUtil::unbindMiniProgram($merchant, $isOpen);
+        }
+        Yii::$app->end();
+
+        $r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant, true, $isOpen);
+        print_r($r);
+        echo $miniAppId . ' ' . $open_appid . ' ';
+
+        $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
+        print_r($return);
+        die;
+
+        $return = wxUtil::createOpenAccount($wxAppId, $merchant);
+        print_r($return);
+        die;
+
+        $r = wxUtil::bindOpenAccount($miniAppId, $open_appid, $merchant, false, $isOpen);
+        print_r($r);
+        echo $miniAppId . ' ' . $open_appid . ' ';
+
+        $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
+        print_r($return);
+        $return = wxUtil::getOpenAccount($miniAppId, $merchant, false, $isOpen);
+        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, false, $isOpen);
+            echo "绑定小程序结果:<br />";
+            print_r($r);
+        }
+        echo "<br /><br />";
+        $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
+        echo "微信appId:{$wxAppId}<br />";
+        print_r($return);
+        $return = wxUtil::getOpenAccount($miniAppId, $merchant, false, $isOpen);
+        echo "<br />小程序appId:{$miniAppId}<br />";
+        print_r($return);
+    }
+
+    //开放平台开始授权 shish 2020.1.16
+    public function actionBeginAuth()
+    {
+        $merchantId = Yii::$app->request->get('id', 0);
+        $open = WxOpenService::getOpen();
+        //1只显示公众号 2只显示小程序  3显示公众号和小程序
+        $authType = Yii::$app->request->get('authType', 3);
+        $pre = wxUtil::getPreAuthCode($open);
+        $appId = $open['appId'];
+        $oData = [];
+        $oData['preAuthCodeTime'] = date("Y-m-d H:i:s");
+        //设置预授码过期,让下个用户可以获取新的预授码
+        xhWxOpenService::updateById(1, $oData);
+        $url = Yii::$app->params['saasHost'] . '/wx-open-callback/' . $merchantId;
+        echo "<a href='https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid={$appId}&pre_auth_code={$pre}&redirect_uri={$url}&auth_type={$authType}'>授权</a>";
+    }
+
+    //平台没有绑定商家公众号时初始化一个商家 shish 2020.2.11
+    public function actionAddMerchant()
+    {
+        AdClass::initAdd(12362);
+        $return = MerchantService::initOpenMerchant();
+        dd($return);
+    }
+
+    public function actionCheckMerchantName()
+    {
+        $get = Yii::$app->request->get();
+        $merchantName = isset($get['merchantName']) ? $get['merchantName'] : '';
+        $m = xhMerchantService::getByMerchantName($merchantName);
+        if (!empty($m)) {
+            util::fail('公众号名称已经使用');
+        }
+        util::complete();
+    }
+
+    /**
+     * 下载微信里的图片到服务器
+     */
+    public function actionDownloadWxImg()
+    {
+        $get = Yii::$app->request->get();
+        $mediaId = isset($get['mediaId']) ? $get['mediaId'] : '';
+        $imgList = wxUtil::downloadmediaIdImg($this->merchant, $mediaId);
+        if (!empty($imgList)) {
+            util::success($imgList);
+        }
+        util::fail();
+    }
+
+    //创建平台使用的公众号
+    public function actionCallback()
+    {
+        $get = Yii::$app->request->get();
+        if (isset($get['auth_code']) == false) {
+            util::stop('公众号授权回调未成功');
+        }
+        $id = isset($get['id']) ? $get['id'] : 0;
+        $code = $get['auth_code'];
+        //使用授权码换取公众号的接口调用凭据和授权信息
+        $authorize = wxUtil::getAuthorizer($code);
+        if (isset($authorize['authorization_info']) == false) {
+            util::stop('未换取公众号的接口调用凭据和授权信息');
+        }
+        $info = $authorize['authorization_info'];
+        $authorizeAppId = $info['authorizer_appid'];
+        $authorize_access_token = $info['authorizer_access_token'];
+        $expires_in = $info['expires_in'];//7200
+        $authorize_refresh_token = $info['authorizer_refresh_token'];
+        //获取授权方的公众号帐号基本信息
+        $authorizeDetailInfo = wxUtil::getAuthorizerInfo($authorizeAppId);
+        if (isset($authorizeDetailInfo['authorizer_info']) == false) {
+            util::stop('没有获取到公众号帐号基本信息');
+        }
+        $authorize_info = $authorizeDetailInfo['authorizer_info'];
+        //$nick_name = $authorize_info['nick_name'];
+        $head_img = $authorize_info['head_img'];
+        $service_type_info = $authorize_info['service_type_info'];
+        if ($service_type_info['id'] != 2) {
+            if (isset($authorize_info['MiniProgramInfo']) == false || empty($authorize_info['MiniProgramInfo'])) {
+                util::stop('公众号不是服务号');
+            }
+        }
+        $verify_type_info = $authorize_info['verify_type_info'];
+        if ($verify_type_info['id'] != 0) {
+            if (isset($authorize_info['MiniProgramInfo']) == false || empty($authorize_info['MiniProgramInfo'])) {
+                util::stop('公众号还没有认证哦');
+            }
+        }
+        $user_name = $authorize_info['user_name'];
+        $alias = $authorize_info['alias'];
+        $qrCodeUrl = $authorize_info['qrcode_url'];
+        $accessTokenTime = date("Y-m-d H:i:s", (time() + $expires_in - 100));//安全起见,将过期时间设置得比微信里还短100秒
+
+        //开放平台还没有关联公众号,先将开放平台关联公众号
+        $open = WxOpenService::getOpen();
+        if (isset($open['merchantId']) && empty($open['merchantId'])) {
+            WxOpenService::updateById(1, ['merchantId' => $id]);
+        }
+
+        $extend = MerchantExtendClass::getByMerchantId($id);
+
+        $open = WxOpenService::getOpen();
+        $time = time();
+
+        //小程序
+        if (isset($authorize_info['MiniProgramInfo']) && !empty($authorize_info['MiniProgramInfo'])) {
+            $miniData = [
+                'miniAppId' => $authorizeAppId,
+                'miniAuth' => 1,
+                'miniAccessToken' => $authorize_access_token,
+                'miniAccessTokenTime' => $accessTokenTime,
+                'miniRefreshToken' => $authorize_refresh_token,
+            ];
+
+            //开放平台没有小程序先绑定开放平台要用的小程序
+            if (isset($open['wx_mini_base_id']) == false || empty($open['wx_mini_base_id'])) {
+                $miniData['addTime'] = $time;
+
+                //花卉宝
+                $miniAppSecret = 'f1ae43c87080da21ac631609b0dbb147';
+                if (getenv('YII_ENV') == 'dev') {
+                    //花美玲
+                    $miniAppSecret = '12f90039b1245ba6abf2e4184462fb30';
+                }
+                $miniData['miniAppSecret'] = $miniAppSecret;
+
+                $wxMiniBaseRespond = WxMiniBaseService::add($miniData);
+                $wxMiniBaseId = $wxMiniBaseRespond['id'];
+                WxOpenService::updateOpen(['wx_mini_base_id' => $wxMiniBaseId]);
+                util::stop('开放平台成功绑定小程序');
+            }
+
+
+            if (isset($extend['miniAppId']) && !empty($extend['miniAppId'])) {
+                if ($extend['miniAppId'] != $authorizeAppId) {
+                    util::stop('授权的小程序与商家已绑定的小程序不一致');
+                }
+            } else {
+                util::stop('数据库请先填写小程序 miniAppId miniAppSecret');
+            }
+
+            xhMerchantExtendService::updateByMerchantId($id, $miniData);
+            MerchantService::updateById($id, ['miniAppId' => $authorizeAppId]);
+            Yii::info('小程序信息更新成功:' . json_encode($authorize_info));
+            util::stop("小程序信息更新成功");
+
+        } else {
+            if (isset($extend['wxAppId']) && !empty($extend['wxAppId'])) {
+                if ($extend['wxAppId'] != $authorizeAppId) {
+                    util::stop('授权的公众号与商家已绑定的公众号不一致');
+                }
+            }
+        }
+
+        $wxData = [];
+        $appData['wxUserName'] = $user_name;
+        $appData['wxAliasName'] = $alias;
+        //公众号logo
+        $wxData['logo'] = WxBaseClass::saveLogo($head_img, $id);
+        //公众号二维码
+        $wxData['wxQrCodeUrl'] = WxBaseClass::saveQrCode($qrCodeUrl, $id);
+        $wxData['wxAppId'] = $authorizeAppId;
+        $wxData['wxAccessToken'] = $authorize_access_token;
+        $wxData['wxAccessTokenTime'] = $accessTokenTime;
+        $wxData['wxRefreshToken'] = $authorize_refresh_token;
+        //开放平台还没有公众号先绑定开放平台的公众号
+        if (isset($open['wx_base_id']) == false || empty($open['wx_base_id'])) {
+            $wxData['addTime'] = $time;
+            $wxBaseRespond = WxBaseService::add($wxData);
+            $wxBaseId = $wxBaseRespond['id'];
+            WxOpenService::updateOpen(['wx_base_id' => $wxBaseId]);
+            util::stop('开放平台成功绑定公众号');
+        }
+        $wxData['status'] = 1;//审核通过
+        xhMerchantService::updateById($id, $wxData);
+        MerchantExtendClass::updateByCondition(['merchantId' => $id], ['wxAppId' => $authorizeAppId, 'wxAuth' => 1]);
+
+        //还没有完成初始化先进行初始化
+        if (isset($extend['init']) && $extend['init'] == 0) {
+            $data = ['merchantId' => $id];
+            $producer = Yii::$app->rabbitmq->getProducer('openShopInitProducer');
+            $msg = serialize($data);
+            $producer->publish($msg, 'openShopInitExchange', 'openShopInitRoute');
+        }
+        echo 'ok';
+    }
+
+    public function actionResult()
+    {
+        $get = Yii::$app->request->get();
+        $id = isset($get['id']) ? $get['id'] : 0;
+        $merchant = xhMerchantService::getById($id);
+        $status = configDict::getConfig('merchantStatusName');
+        $orMechantId = configDict::getConfig('merchantId');
+        $originalMerchant = xhMerchantService::getById($orMechantId);
+        return $this->renderPartial('result', ['originalMerchant' => $originalMerchant, 'merchant' => $merchant, 'status' => $status]);
+    }
+
+    public function actionCheckInviteCode()
+    {
+        $get = Yii::$app->request->get();
+        $code = isset($get['code']) ? $get['code'] : '';
+        $invite = xhInviteService::getByCode($code);
+        if (empty($invite)) {
+            util::fail('邀请码错误');
+        }
+        $now = time();
+        if ($now > $invite['deadline']) {
+            util::fail('邀请码已经失效');
+        }
+        if (!empty($invite['takeStatus'])) {
+            util::fail('邀请码已经使用');
+        }
+        util::success($invite);
+    }
+
+    public function actionSelect()
+    {
+        $isWx = util::isWx();
+        if ($isWx == false) {
+            return $this->renderPartial('notWeixin');
+        }
+        return $this->renderPartial('select');
+    }
+
+    public function actionApi()
+    {
+        $openData = file_get_contents('php://input');
+        if (isset ($openData) == false || empty($openData)) {
+            util::stop('has no post data');
+        }
+        $weixinSecret = Yii::getAlias("@vendor/weixinSecret");
+        require_once($weixinSecret . '/wxBizMsgCrypt.php');
+        $get = Yii::$app->request->get();
+        $encryptMsg = $openData;
+        $openId = configDict::getConfig('openId');
+        $open = xhWxOpenService::getById($openId);
+        $encodingAesKey = $open['aesKey'];
+        $token = $open['token'];
+        $appId = $open['appId'];
+        $appSecret = $open['appSecret'];
+        $signature = isset($get['signature']) ? $get['signature'] : '';
+        $timestamp = isset($get['timestamp']) ? $get['timestamp'] : '';
+        $nonce = isset($get['nonce']) ? $get['nonce'] : '';
+        $encrypt_type = isset($get['encrypt_type']) ? $get['encrypt_type'] : '';
+        $msg_signature = isset($get['msg_signature']) ? $get['msg_signature'] : '';
+        $xml_tree = new \DOMDocument();
+        $xml_tree->loadXML($encryptMsg);
+        $array_e = $xml_tree->getElementsByTagName('Encrypt');
+        $encrypt = $array_e->item(0)->nodeValue;
+        $format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%s]]></Encrypt></xml>";
+        $from_xml = sprintf($format, $encrypt);
+
+        $formString = " token:" . $token . "\n encodingAesKey:" . $encodingAesKey . "\n appId:" . $appId . "\n msg_signature:" . $msg_signature . "\n appSecret:" . $appSecret . "\n timestamp:" . $timestamp . "\n nonce:" . $nonce;
+        Yii::warning($formString);
+
+        $formString2 = "from_xml:" . $from_xml;
+        Yii::warning($formString2);
+
+        //第三方收到公众号平台发送的消息
+        $pc = new \WXBizMsgCrypt($token, $encodingAesKey, $appId);
+        $msg = '';//解密后的消息
+        $errCode = $pc->decryptMsg($msg_signature, $timestamp, $nonce, $from_xml, $msg);
+        if ($errCode != 0) {
+            Yii::warning("解密未成功,错误代码:" . $errCode . "。(出现过的情况汇总:-40001 有可能token、encodingAesKey、appId等填写不对,请仔细核对每个值)");
+            util::stop();
+        }
+        $postObj = simplexml_load_string($msg, 'SimpleXMLElement', LIBXML_NOCDATA);
+        $infoType = $postObj->InfoType;
+        switch ($infoType) {
+            //推送 componentVerifyTicket
+            case 'component_verify_ticket':
+                $componentVerifyTicket = $postObj->ComponentVerifyTicket;
+                if (!empty($componentVerifyTicket)) {
+                    $oData = [];
+                    $oData['verifyTicket'] = (string)$componentVerifyTicket;
+                    $oData['verifyTicketTime'] = date("Y-m-d H:i:s", $timestamp + 600);//每10分钟(600秒)推一次
+                    xhWxOpenService::updateById($openId, $oData);
+                    Yii::warning("component_verify_ticket:" . (string)$componentVerifyTicket);
+                    util::stop('success');
+                }
+                break;
+            //取消授权通知
+            case 'unauthorized':
+                $AppId = $postObj->AppId;
+                $authorizeAppid = $postObj->AuthorizerAppid;
+                $merchant = xhMerchantService::getByAppId($authorizeAppid);
+                if (!empty($merchant)) {
+                    $merchantId = $merchant['id'];
+                    //自主冻结
+                    xhMerchantService::updateById($merchantId, ['status' => 5]);
+                }
+                break;
+            //授权成功通知
+            case 'authorized':
+                $AppId = $postObj->AppId;//第三方平台appid
+                $CreateTime = $postObj->CreateTime;//公众号
+                $authorizeAppid = $postObj->AuthorizerAppid;//授权码,可用于换取公众号的接口调用凭据,详细见上面的说明
+                $AuthorizationCode = $postObj->AuthorizationCode;
+                $AuthorizationCodeExpiredTime = $postObj->AuthorizationCodeExpiredTime;//授权码过期时间
+                break;
+            //授权更新通知
+            case 'updateauthorized':
+                $AppId = $postObj->AppId;
+                $CreateTime = $postObj->CreateTime;
+                $authorizeAppid = $postObj->AuthorizerAppid;
+                $AuthorizationCode = $postObj->AuthorizationCode;
+                $AuthorizationCodeExpiredTime = $postObj->AuthorizationCodeExpiredTime;
+
+                util::stop();
+
+                $authorize = wxUtil::getAuthorizer($AuthorizationCode);
+                if (isset($authorize['authorization_info']) == false) {
+                    $msg = '授权回调获取到auth_code,但未换取公众号的接口调用凭据和授权信息!!';
+                    Yii::warning($msg, __METHOD__);
+                    Yii::$app->end();
+                }
+                $info = $authorize['authorization_info'];
+                $authorizeAppId = $info['authorizer_appid'];
+                $authorize_access_token = $info['authorizer_access_token'];
+                $expires_in = $info['expires_in'];//7200
+                $authorize_refresh_token = $info['authorizer_refresh_token'];
+                $merchant = xhMerchantService::getByAppId($authorizeAppId);
+                if (empty($merchant)) {
+                    return false;
+                }
+                $merchantId = $merchant['id'];
+                $wxData = [];
+                $wxData['wxAccessToken'] = $authorize_access_token;
+                $wxData['wxRefreshToken'] = $authorize_refresh_token;
+                $wxData['wxAccessTokenTime'] = date("Y-m-d H:i:s", (time() + $expires_in - 100));
+                $wxData['status'] = 1;
+                xhMerchantService::updateById($merchantId, $wxData);
+                break;
+            default:
+        }
+        Yii::warning("---wx open data end--- \n");
+    }
+
+    //获取平台信息 shish 2020.4.12
+    public function actionGetWxOpen()
+    {
+        $open = WxOpenService::getOpen();
+        util::success($open);
+    }
+
 }

+ 1518 - 1518
common/components/wxUtil.php

@@ -19,1522 +19,1522 @@ use common\components\configDict;
  */
 class wxUtil
 {
-	public $access_token;
-	
-	public function __construct($merchant = '')
-	{
-		$this->access_token = !empty($merchant) ? self::getAuthorizerAccessToken($merchant) : '';
-	}
-	
-	//获取用户基本信息
-	public static function userInfo($openId, $merchant)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$accessToken&openid=$openId";
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$result = Json::decode($result);
-		if (isset($result['errcode'])) {
-		
-		} else {
-			return $result;
-		}
-	}
-	
-	//创建开放平台帐号
-	public static function createOpenAccount($appId, $merchant)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/open/create?access_token=" . $accessToken;
-		$curl = new curl\Curl();
-		$data = ['appid' => $appId];
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	//绑定到开放平台
-	public static function bindOpenAccount($appId, $openAppId, $merchant, $isMiniProgram, $isOpen = 0)
-	{
-		if ($isMiniProgram) {
-			$accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
-		} else {
-			$accessToken = self::getAuthorizerAccessToken($merchant, $isOpen);
-		}
-		$url = 'https://api.weixin.qq.com/cgi-bin/open/bind?access_token=' . $accessToken;
-		$curl = new curl\Curl();
-		$data = ['appid' => $appId, 'open_appid' => $openAppId];
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	//获取公众号、小程序绑定的开放平台帐号
-	public static function getOpenAccount($appId, $merchant, $isMiniProgram, $isOpen = 0)
-	{
-		if ($isMiniProgram) {
-			$accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
-		} else {
-			$accessToken = self::getAuthorizerAccessToken($merchant, $isOpen);
-		}
-		$url = "https://api.weixin.qq.com/cgi-bin/open/get?access_token=" . $accessToken;
-		$curl = new curl\Curl();
-		$data = ['appid' => $appId];
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	//解绑公众号绑定的平台 shish 2019.9.15
-	public static function unbindAccount($merchant, $isOpen = 0)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant, $isOpen);
-		$url = "https://api.weixin.qq.com/cgi-bin/open/unbind?access_token=" . $accessToken;
-		$curl = new curl\Curl();
-		$openAppId = $merchant['openAppId'];
-		$appId = $merchant['wxAppId'];
-		$data = ['appid' => $appId, 'open_appid' => $openAppId];
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	//解绑小程序绑定的平台 shish 2019.9.15
-	public static function unbindMiniProgram($merchant, $isOpen = 0)
-	{
-		$accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
-		$url = "https://api.weixin.qq.com/cgi-bin/open/unbind?access_token=" . $accessToken;
-		$curl = new curl\Curl();
-		$openAppId = $merchant['openAppId'];
-		$appId = $merchant['miniAppId'];
-		$data = ['appid' => $appId, 'open_appid' => $openAppId];
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	public static function getSubscribeUserList($merchant, $nextOpenId = '')
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=$accessToken&next_openid=$nextOpenId";
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		return Json::decode($result);
-	}
-	
-	public static function batchGetUserInfo($merchant, $openIdList)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=" . $accessToken;
-		$format = [];
-		foreach ($openIdList as $val) {
-			$format[] = ['openid' => $val, 'lang' => "zh-CN"];
-		}
-		$newOpenIdList = ["user_list" => $format];
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($newOpenIdList))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	//查询所有分组
-	public static function groupList($accessToken)
-	{
-		$url = "https://api.weixin.qq.com/cgi-bin/groups/get?access_token=$accessToken";
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$result = Json::decode($result);
-		if (isset($result['errcode'])) {
-			return null;
-		} else {
-			return $result;
-		}
-	}
-	
-	/**
-	 * 提交自定义菜单到微信平台
-	 */
-	public function userMenuToWeiXin($menu)
-	{
-		$jsonData = urldecode(json_encode($menu, JSON_UNESCAPED_UNICODE));
-		$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		$response = $curl->setOption(CURLOPT_POSTFIELDS, $jsonData)->post($url);
-		return $response;
-	}
-	
-	/**
-	 * 上传图片多媒体文件
-	 */
-	public static function uploadImgMedia($merchant, $fullFile)
-	{
-		$access_token = self::getAuthorizerAccessToken($merchant);
-		$url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=" . $access_token . "&type=image";
-		$curl = curl_init();
-		if (class_exists('\CURLFile')) {//关键是判断curlfile,官网推荐php5.5或更高的版本使用curlfile来实例文件
-			$data = array('media' => new \CURLFile($fullFile));
-		} else {
-			$data = array('media' => file_get_contents($fullFile));
-		}
-		if (class_exists('\CURLFile')) {
-			curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
-		} else {
-			if (defined('CURLOPT_SAFE_UPLOAD')) {
-				curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
-			}
-		}
-		curl_setopt($curl, CURLOPT_URL, $url);
-		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
-		curl_setopt($curl, CURLOPT_POST, true);
-		curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
-		$result = curl_exec($curl);
-		curl_close($curl);
-		return json_decode($result);
-	}
-	
-	/**
-	 * 上传视频文件
-	 * @param unknown_type
-	 * @param $merchant
-	 * @param $fullFile
-	 * @return mixed
-	 */
-	public function uploadVideoMedia($merchant, $fullFile)
-	{
-		$access_token = self::getAuthorizerAccessToken($merchant);
-		$url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=" . $access_token . "&type=video";
-		$curl = curl_init();
-		if (class_exists('\CURLFile')) {//关键是判断curlfile,官网推荐php5.5或更高的版本使用curlfile来实例文件
-			$data = array('media' => new \CURLFile($fullFile));
-		} else {
-			$data = array('media' => file_get_contents($fullFile));
-		}
-		if (class_exists('\CURLFile')) {
-			curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
-		} else {
-			if (defined('CURLOPT_SAFE_UPLOAD')) {
-				curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
-			}
-		}
-		curl_setopt($curl, CURLOPT_URL, $url);
-		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
-		curl_setopt($curl, CURLOPT_POST, true);
-		curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
-		$result = curl_exec($curl);
-		curl_close($curl);
-		return json_decode($result);
-	}
-	
-	/**
-	 * 下载多媒体文件
-	 * @param unknown_type $access_token
-	 * @param unknown_type $media_id
-	 */
-	public static function uploadMedia($media_id, $access_token)
-	{
-		$url = 'http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=' . $access_token . '&media_id=' . $media_id;
-		$result = CurlUtil::httpsGet($url);
-		if (isset($result['errcode'])) {
-			return false;
-		} else {
-			return $result;
-		}
-	}
-	
-	/**
-	 * 获取素材总数
-	 * 图片和图文消息素材(包括单图文和多图文)的总数上限为5000,其他素材的总数上限为1000
-	 */
-	public function getMaterialCount($merchant)
-	{
-		$token = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token={$token}";
-		$curl = new curl\Curl();
-		$response = $curl->get($url);
-		return $response;
-	}
-	
-	/**
-	 * 获取素材列表 图文列表
-	 *    $data    = ['type' => 'image','offset' => 0,'count' => 100];
-	 *    type:news image video voice
-	 */
-	public function batchgetMaterial($merchant, $data)
-	{
-		$token = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token={$token}";
-		$curl = new curl\Curl();
-		$response = $curl->setOption(CURLOPT_POSTFIELDS, json_encode($data))->post($url);
-		return json_decode($response, true);
-	}
-	
-	/**
-	 * 解除绑定删除自定义菜单
-	 * @param string $accessToken
-	 */
-	public static function menuDelete($merchant)
-	{
-		$token = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=$token";
-		$curl = new curl\Curl();
-		$response = $curl->get($url);
-		return $response;
-	}
-	
-	//微信api不支持中文转义的json结构
-	static function json_encode($arr)
-	{
-		if (count($arr) == 0) return "[]";
-		$parts = array();
-		$is_list = false;
-		//Find out if the given array is a numerical array
-		$keys = array_keys($arr);
-		$max_length = count($arr) - 1;
-		if (($keys [0] === 0) && ($keys [$max_length] === $max_length)) { //See if the first key is 0 and last key is length - 1
-			$is_list = true;
-			for ($i = 0; $i < count($keys); $i++) { //See if each key correspondes to its position
-				if ($i != $keys [$i]) { //A key fails at position check.
-					$is_list = false; //It is an associative array.
-					break;
-				}
-			}
-		}
-		foreach ($arr as $key => $value) {
-			if (is_array($value)) { //Custom handling for arrays
-				if ($is_list)
-					$parts [] = self::json_encode($value); /* :RECURSION: */
-				else
-					$parts [] = '"' . $key . '":' . self::json_encode($value); /* :RECURSION: */
-			} else {
-				$str = '';
-				if (!$is_list)
-					$str = '"' . $key . '":';
-				//Custom handling for multiple data types
-				if (!is_string($value) && is_numeric($value) && $value < 2000000000)
-					$str .= $value; //Numbers
-				elseif ($value === false)
-					$str .= 'false'; //The booleans
-				elseif ($value === true)
-					$str .= 'true';
-				else
-					$str .= '"' . addslashes($value) . '"'; //All other things
-				$parts [] = $str;
-			}
-		}
-		$json = implode(',', $parts);
-		if ($is_list)
-			return '[' . $json . ']'; //Return numerical JSON
-		return '{' . $json . '}'; //Return associative JSON
-	}
-	
-	/**
-	 * 创建临时二维码 shish 2019.9.4
-	 */
-	public static function qrcodeCreate($merchant, $sceneId, $expireSeconds = null)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=$accessToken";
-		//有效期默认一天
-		$expireSeconds = isset($expireSeconds) ? $expireSeconds : 86400;
-		$post = array('expire_seconds' => $expireSeconds, 'action_name' => 'QR_STR_SCENE', "action_info" => array('scene' => array('scene_str' => $sceneId)));
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 创建永久二维码
-	 */
-	public static function qrcodePermanentCreate($merchant, $sceneId)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=$accessToken";
-		$post = array('action_name' => 'QR_LIMIT_STR_SCENE', "action_info" => array('scene' => array('scene_str' => $sceneId)));
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 微信授权获取code
-	 */
-	public static function getCode($urlEncode, $merchant, $scope)
-	{
-		$host = Yii::$app->request->getHostInfo();
-		$REDIRECT_URI = $host . '/auth/get-user-info?url=' . $urlEncode . '&authScope=' . $scope;
-		Yii::info($REDIRECT_URI);
-		$appId = $merchant['wxAppId'];
-		$id = configDict::getConfig('openId');
-		$open = xhWxOpenService::getById($id);
-		$component_appid = $open['appId'];
-		$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $appId . "&redirect_uri=" . urlencode($REDIRECT_URI) . "&response_type=code&scope=" . $scope . "&state=1&component_appid={$component_appid}#wechat_redirect";
-		header("Location:" . $url);
-		//如果这里没有exit(),在apache服务器下无法实现跳转
-		exit();
-	}
-	
-	/**
-	 * 获取openId
-	 */
-	public static function getOpenId($code, $merchant)
-	{
-		$appId = $merchant['wxAppId'];
-		$id = configDict::getConfig('openId');
-		$open = xhWxOpenService::getById($id);
-		$component_appid = $open['appId'];
-		$componentAccessToken = wxUtil::getComponentAccessToken($open);
-		$url = "https://api.weixin.qq.com/sns/oauth2/component/access_token?appid={$appId}&code={$code}&grant_type=authorization_code&component_appid={$component_appid}&component_access_token={$componentAccessToken}";
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$data = Json::decode($result);
-		if (isset($data['openid']) == false) {
-			Yii::warning('error:' . json_encode($data) . ' code:' . $code, __METHOD__);
-			return false;
-		}
-		return $data;
-	}
-	
-	/**
-	 * 授权获取自己的信息
-	 */
-	public function authGetUserInfo($openid, $access_token)
-	{
-		$url = "https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid";
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$data = Json::decode($result);
-		return $data;
-	}
-	
-	/**
-	 * 自动获取自己的信息(公众号的粉丝才能获取)
-	 */
-	public static function autoGetUserInfo($openid, $merchant)
-	{
-		$access_token = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$access_token&openid=$openid&lang=zh_CN";
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$data = Json::decode($result);
-		return $data;
-	}
-	
-	/**
-	 * 网址接入验证
-	 */
-	public static function signatureValidation()
-	{
-		$signature = $_GET['signature'];
-		$timestamp = $_GET['timestamp'];
-		$nonce = $_GET['nonce'];
-		$account = $_GET['account'];
-		$merchant = xhMerchantService::getByAccount($account);
-		if ($merchant) {
-			$token = $merchant['wxToken'];
-			// 3个数值组成数组验证
-			$tmpArr = array(
-				$token,
-				$timestamp,
-				$nonce
-			);
-			// 字典排序
-			sort($tmpArr, SORT_STRING);
-			$tmpStr = implode($tmpArr);
-			// sha1加密
-			$tmpStr = sha1($tmpStr);
-			if ($signature == $tmpStr) {
-				return true;
-			} else {
-				return false;
-			}
-		} else {
-			return false;
-		}
-	}
-	
-	//客服接口发消息
-	public static function sendMsg($content, $merchant, $openId)
-	{
-		$token = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$token}";
-		$data = ['touser' => $openId, 'msgtype' => 'text', 'text' => ['content' => $content]];
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	public static function sendImgMsg($mediaId, $merchant, $openId)
-	{
-		$token = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$token}";
-		$data = ['touser' => $openId, 'msgtype' => 'image', 'image' => ['media_id' => $mediaId]];
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	public static function sendVideoMsg($mediaId, $merchant, $openId)
-	{
-		$token = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$token}";
-		$data = ['touser' => $openId, 'msgtype' => 'video', 'video' => ['media_id' => $mediaId,
-			'thumb_media_id' => $mediaId,
-			'title' => '因爱而生',
-			'description' => "情定原生,爱在今生;\n坐标:浙江,绍兴上虞;\n看到过一句话:“一个城市不过是几条巷道上,几间房子和几个人的组合。如果没有了这些,一个城市如同陨落,只剩下悲凉的记忆;”\n万事万物持续流变,珍爱的东西尤其不可能一直存在,如朝霞,如春花,如爱情;\n无论什么时候,不管天气好坏,都能拿出某些个让人喜欢的东西。",
-		]];
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 消息模板,发送任务通知
-	 * @param unknown $data
-	 * @return mixed
-	 */
-	public static function sendTaskInform($data, $merchant)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$accessToken}";
-		$data = urldecode(json_encode($data, JSON_UNESCAPED_UNICODE));
-		$curl = new curl\Curl();
-		$response = $curl->setOption(CURLOPT_POSTFIELDS, $data)->post($url);
-		$arr = json_decode($response);
-		return $arr;
-	}
-	
-	/**
-	 * 创建模板消息
-	 * @param unknown $accessToken
-	 * @param unknown $template_id_short
-	 * @return unknown
-	 */
-	public static function tMessageCreate($merchant, $shortTemplateId)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token={$accessToken}";
-		$post = array('template_id_short' => $shortTemplateId);
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 删除模板消息
-	 * @param unknown $accessToken
-	 * @param unknown $templateId
-	 * @return unknown
-	 */
-	public static function delTMessage($merchant, $templateId)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token={$accessToken}";
-		$post = array('template_id' => $templateId);
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 取所有模板消息
-	 * @param unknown_type $appId
-	 * @return unknown
-	 */
-	public function getAllTMessage($merchant)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token={$accessToken}";
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 设置模板消息的行业
-	 * @param unknown $accessToken
-	 * @param unknown $templateId
-	 * @return unknown
-	 */
-	public function setTMIndustry($merchant, $industry_id1, $industry_id2)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token={$accessToken}";
-		$post = array('industry_id1' => $industry_id1, 'industry_id2' => $industry_id2);
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 获取公众号的accessToken 公众号调用凭据
-	 * @param unknown $appId
-	 * @return unknown|string
-	 */
-	public static function getAuthorizerAccessToken($merchant, $isOpen = 0)
-	{
-		$merchantId = $merchant['id'];
-		$id = configDict::getConfig('openId');
-		$open = xhWxOpenService::getById($id);
-		$component_appid = $open['appId'];
-		$componentAccessToken = wxUtil::getComponentAccessToken($open);
-		$appId = $merchant['wxAppId'];
-		$wxAccessToken = $merchant['wxAccessToken'];
-		$wxAccessTokenTime = $merchant['wxAccessTokenTime'];
-		$authorizer_refresh_token = $merchant['wxRefreshToken'];
-		$now = time();
-		if ($now > strtotime($wxAccessTokenTime)) {
-			$url = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token={$componentAccessToken}";
-			$data = ['component_appid' => $component_appid, 'authorizer_appid' => $appId, 'authorizer_refresh_token' => $authorizer_refresh_token];
-			$curl = new curl\Curl();
-			$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-			$result = Json::decode($result);
-			if (isset($result['authorizer_access_token'])) {
-				$authorizer_access_token = $result['authorizer_access_token'];
-				$expires_in = $result['expires_in'];
-				$authorizer_refresh_token = $result['authorizer_refresh_token'];
-				$uData['wxRefreshToken'] = $authorizer_refresh_token;;
-				$uData['wxAccessToken'] = $authorizer_access_token;
-				$uData['wxAccessTokenTime'] = date("Y-m-d H:i:s", (time() + $expires_in - 100));
-				if ($isOpen == 1) {
-					$open = WxOpenService::getOpen();
-					$wx_base_id = isset($open['wx_base_id']) ? $open['wx_base_id'] : 0;
-					if (!empty($wx_base_id)) {
-						WxBaseService::updateById($wx_base_id, $uData);
-					}
-				} else {
-					xhMerchantService::updateById($merchantId, $uData);
-				}
-				return $authorizer_access_token;
-			}
-			return;
-		} else {
-			return $wxAccessToken;
-		}
-	}
-	
-	/**
-	 * 获取小程序的accessToken
-	 */
-	public static function getMiniProgramAccessToken($merchant, $isOpen = 0)
-	{
-		$merchantId = $merchant['id'];
-		$id = configDict::getConfig('openId');
-		$open = xhWxOpenService::getById($id);
-		$component_appid = $open['appId'];
-		$componentAccessToken = wxUtil::getComponentAccessToken($open);
-		$appId = $merchant['miniAppId'];
-		if ($isOpen == 1) {
-			$miniAccessToken = $merchant['miniAccessToken'];
-			$miniAccessTokenTime = $merchant['miniAccessTokenTime'];
-			$miniRefreshToken = $merchant['miniRefreshToken'];
-		} else {
-			$extend = xhMerchantExtendService::getByMerchantId($merchantId);
-			$miniAccessToken = $extend['miniAccessToken'];
-			$miniAccessTokenTime = $extend['miniAccessTokenTime'];
-			$miniRefreshToken = $extend['miniRefreshToken'];
-		}
-		$now = time();
-		if ($now > strtotime($miniAccessTokenTime)) {
-			$url = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token={$componentAccessToken}";
-			$data = ['component_appid' => $component_appid, 'authorizer_appid' => $appId, 'authorizer_refresh_token' => $miniRefreshToken];
-			$curl = new curl\Curl();
-			$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-			$result = Json::decode($result);
-			Yii::info('重新获取mini accesstoken:' . json_encode($result));
-			if (isset($result['authorizer_access_token'])) {
-				$expires_in = $result['expires_in'];
-				$miniAccessToken = $result['authorizer_access_token'];
-				$uData['miniRefreshToken'] = $result['authorizer_refresh_token'];
-				$uData['miniAccessToken'] = $miniAccessToken;
-				$uData['miniAccessTokenTime'] = date("Y-m-d H:i:s", (time() + $expires_in - 100));
-				if ($isOpen == 1) {
-					$open = WxOpenService::getOpen();
-					$wx_mini_base_id = isset($open['wx_mini_base_id']) ? $open['wx_mini_base_id'] : 0;
-					if (!empty($wx_mini_base_id)) {
-						WxMiniBaseService::updateById($wx_mini_base_id, $uData);
-					}
-				} else {
-					xhMerchantExtendService::updateByMerchantId($merchantId, $uData);
-				}
-				
-				return $miniAccessToken;
-			}
-			Yii::info('accessToken失效:merchantId:' . $merchantId);
-		}
-		return $miniAccessToken;
-	}
-	
-	public static function saveWeixinImg($userId, $url, $class = 0)
-	{
-		$className = [
-			'0' => 'weixinUserAvatar',//微信头像
-			'1' => 'weixinUserImg',//微信公众号二维码
-			'2' => 'weixinMpQrcode',
-			'3' => 'weixinMpAvatar',
-		];
-		$folder = Yii::getAlias('@webroot') . '/../../images';
-		$pre = '/' . $className[$class] . '/' . date('Y') . '/' . date('m') . '/' . date("d") . '/';
-		if (!file_exists($folder . $pre))
-			mkdir($folder . $pre, 0777, true);
-		$randString = stringUtil::buildOrderNo();
-		$name = md5($userId . $randString) . '.jpg';
-		$fullFileName = $folder . $pre . $name;
-		$fileName = $pre . $name;
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$fp2 = @fopen($fullFileName, 'a');//文件大小
-		fwrite($fp2, $result);
-		fclose($fp2);
-		return $fileName;
-	}
-	
-	/**
-	 * 下载学员作品图片
-	 */
-	public static function downloadStudentWorksImg($merchant, $mediaId, $savePathType = 'wxUserImg')
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$accessToken}&media_id={$mediaId}";
-		$ch = curl_init($url);
-		curl_setopt($ch, CURLOPT_HEADER, 0);
-		curl_setopt($ch, CURLOPT_NOBODY, 0);//对body进行输出。
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-		$body = curl_exec($ch);
-		$httpinfo = curl_getinfo($ch);
-		curl_close($ch);
-		preg_match('/\w\/(\w+)/i', $httpinfo["content_type"], $extmatches);//求出文件格式
-		$fileExt = $extmatches[1];
-		$imgSavePath = configDict::getConfig('imgSavePath');
-		$comImgSavePath = $imgSavePath[$savePathType];
-		$folder = Yii::getAlias('@webroot') . '/../../images';
-		$pre = '/' . $comImgSavePath . '/' . date('Y') . '/' . date('m') . '/' . date("d") . '/';
-		if (!file_exists($folder . $pre)) {
-			mkdir($folder . $pre, 0777, true);
-		}
-		$randString = stringUtil::buildOrderNo();
-		$fullFileName = $folder . $pre . $randString . '.jpg';
-		$fileName = $pre . $randString . '.jpg';
-		$fp2 = @fopen($fullFileName, 'a');//文件大小
-		fwrite($fp2, $body);
-		fclose($fp2);
-		$srcImg = $fullFileName;
-		
-		$dstImg300 = $folder . $pre . $randString . "_300.jpg";//生成300px缩略图,不保存到数据库
-		util::img2thumb($srcImg, $dstImg300, $width = 300, 0, 0, 0);
-		
-		$dstImg100 = $folder . $pre . $randString . "_100.jpg";//生成50px缩略图,不保存到数据库
-		util::img2thumb($srcImg, $dstImg100, $width = 100, 0, 0, 0);
-		return $fileName;
-	}
-	
-	/**
-	 * 获取media_id里的图片保存到服务器
-	 */
-	public static function downloadmediaIdImg($merchant, $mediaId, $savePathType = 'wxUserImg')
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$accessToken}&media_id={$mediaId}";
-		$ch = curl_init($url);
-		curl_setopt($ch, CURLOPT_HEADER, 0);
-		curl_setopt($ch, CURLOPT_NOBODY, 0);//对body进行输出。
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-		$body = curl_exec($ch);
-		$httpinfo = curl_getinfo($ch);
-		curl_close($ch);
-		preg_match('/\w\/(\w+)/i', $httpinfo["content_type"], $extmatches);//求出文件格式
-		$fileExt = $extmatches[1];
-		$imgSavePath = configDict::getConfig('imgSavePath');
-		$comImgSavePath = $imgSavePath[$savePathType];
-		$folder = Yii::getAlias('@webroot') . '/../../images';
-		$pre = '/' . $comImgSavePath . '/' . date('Y') . '/' . date('m') . '/' . date("d") . '/';
-		if (!file_exists($folder . $pre)) {
-			mkdir($folder . $pre, 0777, true);
-		}
-		$randString = stringUtil::buildOrderNo();
-		$fullFileName = $folder . $pre . $randString . '.jpg';
-		$fileName = $pre . $randString . '.jpg';
-		$fp2 = @fopen($fullFileName, 'a');//文件大小
-		fwrite($fp2, $body);
-		fclose($fp2);
-		$srcImg = $fullFileName;
-		
-		$mediumImg = $pre . $randString . "_200.jpg";
-		$dstImg200 = $folder . $mediumImg;//生成200px缩略图,不保存到数据库
-		util::img2thumb($srcImg, $dstImg200, $width = 200, 0, 0, 0);
-		
-		$smallImg = $pre . $randString . "_50.jpg";
-		$dstImg50 = $folder . $smallImg;//生成50px缩略图,不保存到数据库
-		util::img2thumb($srcImg, $dstImg50, $width = 50, 0, 0, 0);
-		return ['large' => $fileName, 'medium' => $mediumImg, 'small' => $smallImg];
-	}
-	
-	public static function createTag($merchant, $name)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/tags/create?access_token={$accessToken}";
-		$post = ['tag' => ['name' => $name]];
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	public static function delTag($merchant, $id)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/tags/delete?access_token={$accessToken}";
-		$post = ['tag' => ['id' => $id]];
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	public static function modTag($merchant, $id, $name)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/tags/update?access_token={$accessToken}";
-		$post = ['tag' => ['id' => $id, 'name' => $name]];
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 获取商家所有标签
-	 */
-	public static function getTag($merchant)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/tags/get?access_token={$accessToken}";
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	public function getUserTag($tagId, $nextOpenId = '')
-	{
-		$url = "https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=" . $this->access_token;
-		$post = ['tagid' => $tagId, 'next_openid' => $nextOpenId];
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 批量为用户打标签
-	 */
-	public static function membersBatchTag($merchant, $openIdList, $tagId)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token={$accessToken}";
-		$post = ['openid_list' => $openIdList, 'tagid' => $tagId];
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 批量取消用户标签
-	 * @param unknown_type $appId
-	 * @param unknown_type $openIdList
-	 * @param unknown_type $tagId
-	 * @return unknown
-	 */
-	public static function membersCancelTag($merchant, $openIdList, $tagId)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token={$accessToken}";
-		$post = ['openid_list' => $openIdList, 'tagid' => $tagId];
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 新增临时素材
-	 * @param unknown_type $appId
-	 * @return unknown
-	 */
-	public static function uploadTempMedia($merchant, $imgUrl, $type = 'image')
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token={$accessToken}&type=" . $type;
-		$postData = ['media' => '@' . $imgUrl];
-		$ch = curl_init();
-		curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
-		curl_setopt($ch, CURLOPT_URL, $url);
-		curl_setopt($ch, CURLOPT_POST, 1);
-		curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-		$response = curl_exec($ch);
-		$result = Json::decode($response);
-		return $result;
-	}
-	
-	/**
-	 * 获取临时素材
-	 * @param unknown_type $appId
-	 * @param unknown_type $mediaId
-	 */
-	public static function getTempMaterial($merchant, $mediaId)
-	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
-		$url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$accessToken}&media_id=" . $mediaId;
-		$fileInfo = self::getTempMaterialInfo($url);
-		if (empty($fileInfo) || isset($fileInfo['errcode'])) {
-			$msg = '未错误哦~';
-			return ['code' => 'A0002', 'msg' => $msg];
-		}
-		$fileName = substr(md5($mediaId), -4) . stringUtil::buildOrderNo() . '.amr';
-		$preFolder = Yii::getAlias('@webroot') . '/../../images';
-		$folder = '/weixinChatVoice/' . date('Y') . '/' . date('m') . '/' . date("d") . '/';
-		if (!file_exists($preFolder . $folder))
-			mkdir($preFolder . $folder, 0777, true);
-		$saveFile = $preFolder . $folder . $fileName;
-		if (file_exists($saveFile) == false) {
-			self::readTempMaterial($saveFile, $fileInfo["body"]);
-		}
-		return ['code' => 'A0001', 'msg' => 'success', 'data' => ['url' => $folder . $fileName]];
-	}
-	
-	/**
-	 * 获取临时素材的头信息等
-	 * @param unknown_type $url
-	 * @return unknown
-	 */
-	public static function getTempMaterialInfo($url)
-	{
-		$ch = curl_init($url);
-		curl_setopt($ch, CURLOPT_HEADER, 0);
-		curl_setopt($ch, CURLOPT_NOBODY, 0);//只取body头
-		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
-		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-		$package = curl_exec($ch);
-		$httpinfo = curl_getinfo($ch);
-		curl_close($ch);
-		$imageAll = ['header' => $httpinfo, 'body' => $package];
-		return $imageAll;
-	}
-	
-	/**
-	 * 读取临时素材的资源
-	 * @param unknown_type $filename
-	 * @param unknown_type $fileContent
-	 */
-	function readTempMaterial($filename, $fileContent)
-	{
-		$localFile = fopen($filename, 'w');
-		if (false !== $localFile) {
-			if (false !== fwrite($localFile, $fileContent)) {
-				fclose($localFile);
-			}
-		}
-	}
-	
-	/**
-	 * 创建门店
-	 * @param $merchant
-	 * @param $menu
-	 * @return mixed
-	 */
-	public function createStore($info)
-	{
-		$jsonData = urldecode(json_encode($info, JSON_UNESCAPED_UNICODE));
-		$url = "http://api.weixin.qq.com/cgi-bin/poi/addpoi?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		return $curl->setOption(CURLOPT_POSTFIELDS, $jsonData)->post($url);
-	}
-	
-	/**
-	 * 查询门店信息
-	 * @param $poi_id
-	 */
-	public function getStoreInfo($poi_id)
-	{
-		$data = ['poi_id' => $poi_id];
-		$jsonData = urldecode(json_encode($data, JSON_UNESCAPED_UNICODE));
-		$url = "http://api.weixin.qq.com/cgi-bin/poi/getpoi?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		return $curl->setOption(CURLOPT_POSTFIELDS, $jsonData)->post($url);
-	}
-	
-	/**
-	 * 查询门店列表
-	 * @param int $begin 开始数据
-	 * @param int $count 返回数据条数,最大允许50,默认为20
-	 */
-	public function getStoreList($begin = 0, $count = 20)
-	{
-		$data = ["begin" => $begin, "limit" => $count];
-		$jsonData = urldecode(json_encode($data, JSON_UNESCAPED_UNICODE));
-		$url = "http://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		return $curl->setOption(CURLOPT_POSTFIELDS, $jsonData)->post($url);
-	}
-	
-	/**
-	 * 查询门店列表 -- 重复 可删除
-	 * @param $data
-	 * @return mixed
-	 */
-	function getShopList($data)
-	{
-		$url = "https://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 修改门店服务信息
-	 */
-	public function updateStore(array $buffer)
-	{
-		$jsonData = urldecode(json_encode($buffer, JSON_UNESCAPED_UNICODE));
-		$url = "http://api.weixin.qq.com/cgi-bin/poi/updatepoi?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		return $curl->setOption(CURLOPT_POSTFIELDS, $jsonData)->post($url);
-	}
-	
-	/**
-	 * 删除门店
-	 * @param $poi_id
-	 * @return mixed
-	 */
-	public function delStore($poi_id)
-	{
-		$data = ['poi_id' => $poi_id];
-		$jsonData = urldecode(json_encode($data, JSON_UNESCAPED_UNICODE));
-		$url = "http://api.weixin.qq.com/cgi-bin/poi/delpoi?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		return $curl->setOption(CURLOPT_POSTFIELDS, $jsonData)->post($url);
-	}
-	
-	/**
-	 * 门店类目表
-	 */
-	public function storeTypeList()
-	{
-		$url = "http://api.weixin.qq.com/cgi-bin/poi/getwxcategory?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		return $curl->get($url);
-	}
-	
-	/******************************* wifi *************************************/
-	/**
-	 * 获取wifi门店列表
-	 * @param $pageindex    开始页
-	 * @param $pagesize     每页数据条数(最大20)
-	 * @return mixed
-	 */
-	function getShopWifiList($pageindex = 1, $pagesize = 10)
-	{
-		$data = ["pageindex" => $pageindex, "pagesize" => $pagesize];
-		$url = "https://api.weixin.qq.com/bizwifi/shop/list?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 添加密码型设备
-	 * @param $shopId   门店ID
-	 * @param $ssid     无线网络设备的ssid
-	 * @param $pwd      无线网络设备的密码
-	 * @return mixed
-	 */
-	function addPasswordDevice($shopId, $ssid, $pwd)
-	{
-		$data = ["shop_id" => $shopId, "ssid" => $ssid, "password" => $pwd];
-		$url = "https://api.weixin.qq.com/bizwifi/device/add?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 修改门店Wi-Fi(修改门店网络信息)
-	 * @param $shopId
-	 * @param $oldSsid
-	 * @param $ssid
-	 * @param string $pwd
-	 * @return mixed
-	 */
-	function updateDevice($shopId, $oldSsid, $ssid, $pwd = '')
-	{
-		$data = ["shop_id" => $shopId, "old_ssid" => $oldSsid, "ssid" => $ssid];
-		if (!empty($pwd)) {
-			$data["password"] = $pwd;
-		}
-		$url = "https://api.weixin.qq.com/bizwifi/shop/update?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 删除密码型设备
-	 * @param $bssid   无线网络设备无线mac地址
-	 * @return mixed
-	 */
-	function delPasswordDevice($bssid)
-	{
-		$data = ["bssid" => $bssid];
-		$url = "https://api.weixin.qq.com/bizwifi/device/delete?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 查询门店Wi-Fi信息
-	 * @param $shopId   门店ID
-	 * @return mixed
-	 */
-	function getShopWifi($shopId)
-	{
-		$data = ["shop_id" => $shopId];
-		$url = "https://api.weixin.qq.com/bizwifi/shop/get?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	/**
-	 * 获取物料二维码
-	 * @param $shopId   门店ID
-	 * @param $ssid     无线网络设备的ssid
-	 * @param $img_id   物料样式编号(0-纯二维码,可用于自由设计宣传材料;1-二维码物料,155mm×215mm(宽×高),可直接张贴)
-	 * @return mixed
-	 */
-	function getWifiQrCode($shopId, $ssid, $img_id)
-	{
-		//$data = ["shop_id" => 429620, "ssid" => "WX567", "img_id" => $img_id];
-		$data = ["shop_id" => $shopId, "ssid" => $ssid, "img_id" => $img_id];
-		$url = "https://api.weixin.qq.com/bizwifi/qrcode/get?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	function getWifiUrl()
-	{
-		$url = "https://api.weixin.qq.com/bizwifi/account/get_connecturl?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	function generateShortUrl($longUrl)
-	{
-		$data = ["action" => "long2short", "long_url" => $longUrl,];
-		$url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=" . $this->access_token;
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		if (isset($result['errcode']) && $result['errcode'] == 0) {
-			return ['code' => 'A0001', 'data' => ['shortUrl' => $result['short_url']]];
-		}
-		return ['code' => 'A0002', 'data' => []];
-	}
-	
-	//长链接转短链接 shish 2019.9.26
-	public static function urlLongToShort($longUrl, $merchant)
-	{
-		$accessToken = self::getMiniProgramAccessToken($merchant);
-		$data = ["action" => "long2short", "long_url" => $longUrl,];
-		$url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=" . $accessToken;
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		$url = '';
-		if (isset($result['errcode']) && $result['errcode'] == 0) {
-			$url = $result['short_url'];
-		}
-		return ['url' => $url];
-	}
-	
-	/**
-	 * 拉取门店所有的设备信息
-	 * @return array
-	 */
-	public function getShopWifiListAll()
-	{
-		$startPage = 1;
-		$list = [];
-		while (true) {
-			$reList = $this->getShopWifiList($startPage, 20);
-			if ($startPage <= $reList['data']['pagecount']) {
-				$list = array_merge($list, $reList['data']['records']);
-				++$startPage;
-			} else {
-				break;
-			}
-		}
-		
-		return $list;
-	}
-	
-	/**
-	 * 通过 poi_id 从Wi-Fi门店列表中 获取 shopId
-	 * @param $poiId
-	 * @return bool
-	 */
-	public function getShopId($poiId, $list = [])
-	{
-		if (empty($list)) {
-			$list = $this->getShopWifiListAll();
-		}
-		foreach ($list as $shop) {
-			if ($shop['poi_id'] == $poiId)
-				return (string)$shop['shop_id'];
-		}
-		
-		return false;
-	}
-	
-	//设置小程序服务器域名
-	public static function setDomain($merchant, $isOpen = 0)
-	{
-		$accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
-		$url = "https://api.weixin.qq.com/wxa/modify_domain?access_token=" . $accessToken;
-		$curl = new curl\Curl();
-		$mallHost = Yii::$app->params['mallHost'];
-		$has = strpos($mallHost, 'https');
-		//如果不是https则换成https
-		if ($has === false) {
-			$mallHost = str_replace('http', 'https', $mallHost);
-		}
-		$data = [
-			"action" => "set",
-			"requestdomain" => [$mallHost],
-			"wsrequestdomain" => [$mallHost],
-			"uploaddomain" => [$mallHost],
-			"downloaddomain" => [$mallHost],
-		];
-		print_r($data);
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$respond = Json::decode($result);
-		print_r($respond);
-	}
-	
-	//设置业务域名
-	public static function setWebViewDomain($merchant, $isOpen = 0)
-	{
-		$accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
-		$url = "https://api.weixin.qq.com/wxa/setwebviewdomain?access_token=" . $accessToken;
-		$curl = new curl\Curl();
-		$mallHost = Yii::$app->params['mallHost'];
-		$has = strpos($mallHost, 'https');
-		//如果不是https则换成https
-		if ($has === false) {
-			$mallHost = str_replace('http', 'https', $mallHost);
-		}
-		$data = [
-			"action" => "set",
-			"webviewdomain" => [$mallHost],
-		];
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$respond = Json::decode($result);
-		print_r($respond);
-	}
-	
-	//为授权的小程序帐号上传小程序代码
-	public static function miniCommit($merchant, $templateId, $isOpen = 0)
-	{
-		$accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
-		$url = 'https://api.weixin.qq.com/wxa/commit?access_token=' . $accessToken;
-		$curl = new curl\Curl();
-		$mUrl = Yii::$app->params['mallHost'];
-		$imgUrl = Yii::$app->params['imgHost'];
-		
-		//如果不是https则换成https
-		$has = strpos($mUrl, 'https');
-		if ($has === false) {
-			$mUrl = str_replace('http', 'https', $mUrl);
-		}
-		
-		//如果不是https则换成https
-		$has = strpos($imgUrl, 'https');
-		if ($has === false) {
-			$imgUrl = str_replace('http', 'https', $imgUrl);
-		}
-		$account = isset($merchant['id']) ? $merchant['id'] : 0;
-		$name = isset($merchant['merchantName']) ? $merchant['merchantName'] : '';
-		if ($isOpen == 1) {
-			$open = WxOpenService::getOpen();
-			$name = isset($open['name']) ? $open['name'] : '';
-		}
-		$ext = [
-			'extAppid' => $merchant['miniAppId'],
-			'ext' => [
-				'account' => $account,
-				'mallHost' => $mUrl,
-				'imgHost' => $imgUrl,
-				'merchantName' => $name,
-			],
-		];
-		Yii::info("ext:" . json_encode($ext));
-		$extJson = json_encode($ext);
-		$data = [
-			"template_id" => $templateId,
-			"ext_json" => $extJson,
-			"user_version" => date("mdHis"),
-			"user_desc" => date("mdHis")
-		];
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$respond = Json::decode($result);
-		print_r($respond);
-	}
-	
-	//获取体验小程序的体验二维码
-	public static function getExperienceQrCode($merchant, $isOpen = 0)
-	{
-		$accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
-		$path = urlencode("pages/home/index");
-		$url = "https://api.weixin.qq.com/wxa/get_qrcode?access_token={$accessToken}&path=" . $path;
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$file = dirUtil::getImgDir() . '/retail/miniExperience/' . $merchant['id'] . '.jpg';
-		file_put_contents($file, $result);
-		echo "<b /><img src='" . Yii::$app->params['imgHost'] . "/retail/miniExperience/" . $merchant['id'] . ".jpg' />";
-	}
-	
-	//获取授权小程序帐号已设置的类目
-	public static function getMiniCategory($merchant, $isOpen = 0)
-	{
-		$accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
-		$url = "https://api.weixin.qq.com/wxa/get_category?access_token=" . $accessToken;
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$respond = Json::decode($result);
-		echo "<pre>";
-		print_r($respond);
-	}
-	
-	//获取小程序的第三方提交代码的页面配置
-	public static function getMiniPage($merchant, $isOpen = 0)
-	{
-		$accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
-		$url = "https://api.weixin.qq.com/wxa/get_page?access_token=" . $accessToken;
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$respond = Json::decode($result);
-		echo "<pre>";
-		print_r($respond);
-	}
-	
-	//将第三方提交的代码包提交审核
-	public static function miniSubmitAudit($merchant, $isOpen = 0)
-	{
-		$accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
-		$url = "https://api.weixin.qq.com/wxa/submit_audit?access_token=" . $accessToken;
-		$curl = new curl\Curl();
-		$data = [
-			"item_list" => [
-				[
-					"address" => "pages/home/index",
-					"tag" => "鲜花 花店",
-					"first_class" => "商家自营",
-					"second_class" => "鲜花/园艺/工艺品",
-					"first_id" => 304,
-					"second_id" => 323,
-					"title" => "商城",
-				],
-			],
-			"feedback_info" => "",
-			"feedback_stuff" => "",
-		];
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$respond = Json::decode($result);
-		echo "<pre>";
-		print_r($respond);
-	}
-	
-	//查询最新一次提交的审核状态
-	public static function miniGetLatestAuditStatus($merchant, $isOpen = 0)
-	{
-		$accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
-		$url = "https://api.weixin.qq.com/wxa/get_latest_auditstatus?access_token=" . $accessToken;
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$respond = Json::decode($result);
-		echo "<pre>";
-		print_r($respond);
-	}
-	
-	
-	//发布已通过审核的小程序
-	public static function miniRelease($merchant, $isOpen = 0)
-	{
-		$accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
-		$url = "https://api.weixin.qq.com/wxa/release?access_token=" . $accessToken;
-		$curl = new curl\Curl();
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, '{}')->post($url);
-		$respond = Json::decode($result);
-		return $respond;
-	}
-	
-	//撤回审核
-	public static function rollbackCheck($merchant, $isOpen = 0)
-	{
-		$accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
-		$url = "https://api.weixin.qq.com/wxa/undocodeaudit?access_token=" . $accessToken;
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$respond = Json::decode($result);
-		echo "<pre>";
-		print_r($respond);
-	}
-	
-	//申请会员的小程序码
-	public static function generateMemberCode($merchant, $shopId, $isOpen = 0)
-	{
-		$behind = '/retail/mimiMemberCode/' . $merchant['id'] . '_' . $shopId . '_apply_member.jpg';
-		$file = dirUtil::getImgDir() . $behind;
-		if (file_exists($file)) {
-			return $behind;
-		}
-		$path = 'pages/home/user?scan=1&shopId=' . $shopId;
-		$accessToken = self::getMiniProgramAccessToken($merchant);
-		$url = "https://api.weixin.qq.com/wxa/getwxacode?access_token={$accessToken}";
-		$curl = new curl\Curl();
-		$data = [
-			"path" => $path,
-			"width" => 1000,
-		];
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		file_put_contents($file, $result);
-		return $behind;
-	}
-	
-	/**
-	 * 微信开放平台获取component_access_token
-	 */
-	public static function getComponentAccessToken($open)
-	{
-		$id = $open['id'];
-		$componentAccessToken = $open['componentAccessToken'];
-		$componentAccessTokenTime = $open['componentAccessTokenTime'];
-		$now = time();
-		if ($now > strtotime($componentAccessTokenTime)) {
-			$appId = $open['appId'];
-			$appSecret = $open['appSecret'];
-			$verifyTicket = $open['verifyTicket'];
-			$data = ['component_appid' => $appId, 'component_appsecret' => $appSecret, 'component_verify_ticket' => $verifyTicket];
-			$url = 'https://api.weixin.qq.com/cgi-bin/component/api_component_token';
-			$curl = new curl\Curl();
-			$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-			if (empty($result)) {
-				util::stop('没有取到ComponentAccessToken');
-			}
-			$result = Json::decode($result);
-			if (isset($result['component_access_token']) == false || empty($result['component_access_token'])) {
-				echo '<pre>';
-				print_r($result);
-				Yii::info('get component access token error:' . json_encode($result));
-				Yii::$app->end();
-			}
-			$component_access_token = $result['component_access_token'];
-			$expiresIn = $result['expires_in'];
-			$oData = [];
-			$oData['componentAccessToken'] = $component_access_token;
-			$oData['componentAccessTokenTime'] = date("Y-m-d H:i:s", ($now + $expiresIn - 100));//安全起见,将过期时间设置得比微信里还短
-			xhWxOpenService::updateById($id, $oData);
-			return $component_access_token;
-		} else {
-			return $componentAccessToken;
-		}
-	}
-	
-	/**
-	 * 微信开放平台获取预授权码pre_auth_code
-	 */
-	public static function getPreAuthCode($open)
-	{
-		$id = $open['id'];
-		$preAuthCode = $open['preAuthCode'];
-		$preAuthCodeTime = $open['preAuthCodeTime'];
-		$now = time();
-		if ($now > strtotime($preAuthCodeTime)) {
-			$token = self::getComponentAccessToken($open);
-			$appId = $open['appId'];
-			$url = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token={$token}";
-			$curl = new curl\Curl();
-			$data = ['component_appid' => $appId];
-			$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-			$result = Json::decode($result);
-			Yii::info($result);
-			if (isset($result['pre_auth_code']) == false || empty($result['pre_auth_code'])) {
-				echo "没有取到pre_auth_code,原因:" . json_encode($result) . " appid:" . $appId . " token:" . $token;
-				Yii::$app->end();
-			}
-			$preAuthCode = $result['pre_auth_code'];
-			$expiresIn = $result['expires_in'];
-			$oData = [];
-			$oData['preAuthCode'] = $preAuthCode;
-			$oData['preAuthCodeTime'] = date("Y-m-d H:i:s", ($now + $expiresIn - 100));//安全起见,将过期时间设置得比微信里还短100秒
-			xhWxOpenService::updateById($id, $oData);
-			return $preAuthCode;
-		} else {
-			return $preAuthCode;
-		}
-	}
-	
-	/**
-	 * 微信开放平台使用授权码换取公众号的接口调用凭据和授权信息
-	 * authorizer_access_token authorizer_refresh_token
-	 */
-	public static function getAuthorizer($code)
-	{
-		$id = configDict::getConfig('openId');
-		$open = xhWxOpenService::getById($id);
-		$appId = $open['appId'];
-		$accessToken = self::getComponentAccessToken($open);
-		$url = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token={$accessToken}";
-		$curl = new curl\Curl();
-		$data = ['authorization_code' => $code, 'component_appid' => $appId];
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	//微信开放平台获取授权方的公众号帐号基本信息 shish 2020.3.11
-	public static function getAuthorizerInfo($authorizerAppId)
-	{
-		$open = WxOpenClass::getOpen();
-		$appId = $open['appId'];
-		$accessToken = self::getComponentAccessToken($open);
-		$url = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token={$accessToken}";
-		$curl = new curl\Curl();
-		$data = ['component_appid' => $appId, 'authorizer_appid' => $authorizerAppId];
-		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
+    public $access_token;
+
+    public function __construct($merchant = '')
+    {
+        $this->access_token = !empty($merchant) ? self::getAuthorizerAccessToken($merchant) : '';
+    }
+
+    //获取用户基本信息
+    public static function userInfo($openId, $merchant)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$accessToken&openid=$openId";
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $result = Json::decode($result);
+        if (isset($result['errcode'])) {
+
+        } else {
+            return $result;
+        }
+    }
+
+    //创建开放平台帐号
+    public static function createOpenAccount($appId, $merchant, $isOpen = 0)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant, $isOpen);
+        $url = "https://api.weixin.qq.com/cgi-bin/open/create?access_token=" . $accessToken;
+        $curl = new curl\Curl();
+        $data = ['appid' => $appId];
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    //绑定到开放平台
+    public static function bindOpenAccount($appId, $openAppId, $merchant, $isMiniProgram, $isOpen = 0)
+    {
+        if ($isMiniProgram) {
+            $accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
+        } else {
+            $accessToken = self::getAuthorizerAccessToken($merchant, $isOpen);
+        }
+        $url = 'https://api.weixin.qq.com/cgi-bin/open/bind?access_token=' . $accessToken;
+        $curl = new curl\Curl();
+        $data = ['appid' => $appId, 'open_appid' => $openAppId];
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    //获取公众号、小程序绑定的开放平台帐号
+    public static function getOpenAccount($appId, $merchant, $isMiniProgram, $isOpen = 0)
+    {
+        if ($isMiniProgram) {
+            $accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
+        } else {
+            $accessToken = self::getAuthorizerAccessToken($merchant, $isOpen);
+        }
+        $url = "https://api.weixin.qq.com/cgi-bin/open/get?access_token=" . $accessToken;
+        $curl = new curl\Curl();
+        $data = ['appid' => $appId];
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    //解绑公众号绑定的平台 shish 2019.9.15
+    public static function unbindAccount($merchant, $isOpen = 0)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant, $isOpen);
+        $url = "https://api.weixin.qq.com/cgi-bin/open/unbind?access_token=" . $accessToken;
+        $curl = new curl\Curl();
+        $openAppId = $merchant['openAppId'];
+        $appId = $merchant['wxAppId'];
+        $data = ['appid' => $appId, 'open_appid' => $openAppId];
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    //解绑小程序绑定的平台 shish 2019.9.15
+    public static function unbindMiniProgram($merchant, $isOpen = 0)
+    {
+        $accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
+        $url = "https://api.weixin.qq.com/cgi-bin/open/unbind?access_token=" . $accessToken;
+        $curl = new curl\Curl();
+        $openAppId = $merchant['openAppId'];
+        $appId = $merchant['miniAppId'];
+        $data = ['appid' => $appId, 'open_appid' => $openAppId];
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    public static function getSubscribeUserList($merchant, $nextOpenId = '')
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=$accessToken&next_openid=$nextOpenId";
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        return Json::decode($result);
+    }
+
+    public static function batchGetUserInfo($merchant, $openIdList)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=" . $accessToken;
+        $format = [];
+        foreach ($openIdList as $val) {
+            $format[] = ['openid' => $val, 'lang' => "zh-CN"];
+        }
+        $newOpenIdList = ["user_list" => $format];
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($newOpenIdList))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    //查询所有分组
+    public static function groupList($accessToken)
+    {
+        $url = "https://api.weixin.qq.com/cgi-bin/groups/get?access_token=$accessToken";
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $result = Json::decode($result);
+        if (isset($result['errcode'])) {
+            return null;
+        } else {
+            return $result;
+        }
+    }
+
+    /**
+     * 提交自定义菜单到微信平台
+     */
+    public function userMenuToWeiXin($menu)
+    {
+        $jsonData = urldecode(json_encode($menu, JSON_UNESCAPED_UNICODE));
+        $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        $response = $curl->setOption(CURLOPT_POSTFIELDS, $jsonData)->post($url);
+        return $response;
+    }
+
+    /**
+     * 上传图片多媒体文件
+     */
+    public static function uploadImgMedia($merchant, $fullFile)
+    {
+        $access_token = self::getAuthorizerAccessToken($merchant);
+        $url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=" . $access_token . "&type=image";
+        $curl = curl_init();
+        if (class_exists('\CURLFile')) {//关键是判断curlfile,官网推荐php5.5或更高的版本使用curlfile来实例文件
+            $data = array('media' => new \CURLFile($fullFile));
+        } else {
+            $data = array('media' => file_get_contents($fullFile));
+        }
+        if (class_exists('\CURLFile')) {
+            curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
+        } else {
+            if (defined('CURLOPT_SAFE_UPLOAD')) {
+                curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
+            }
+        }
+        curl_setopt($curl, CURLOPT_URL, $url);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($curl, CURLOPT_POST, true);
+        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+        $result = curl_exec($curl);
+        curl_close($curl);
+        return json_decode($result);
+    }
+
+    /**
+     * 上传视频文件
+     * @param unknown_type
+     * @param $merchant
+     * @param $fullFile
+     * @return mixed
+     */
+    public function uploadVideoMedia($merchant, $fullFile)
+    {
+        $access_token = self::getAuthorizerAccessToken($merchant);
+        $url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=" . $access_token . "&type=video";
+        $curl = curl_init();
+        if (class_exists('\CURLFile')) {//关键是判断curlfile,官网推荐php5.5或更高的版本使用curlfile来实例文件
+            $data = array('media' => new \CURLFile($fullFile));
+        } else {
+            $data = array('media' => file_get_contents($fullFile));
+        }
+        if (class_exists('\CURLFile')) {
+            curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
+        } else {
+            if (defined('CURLOPT_SAFE_UPLOAD')) {
+                curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
+            }
+        }
+        curl_setopt($curl, CURLOPT_URL, $url);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($curl, CURLOPT_POST, true);
+        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+        $result = curl_exec($curl);
+        curl_close($curl);
+        return json_decode($result);
+    }
+
+    /**
+     * 下载多媒体文件
+     * @param unknown_type $access_token
+     * @param unknown_type $media_id
+     */
+    public static function uploadMedia($media_id, $access_token)
+    {
+        $url = 'http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=' . $access_token . '&media_id=' . $media_id;
+        $result = CurlUtil::httpsGet($url);
+        if (isset($result['errcode'])) {
+            return false;
+        } else {
+            return $result;
+        }
+    }
+
+    /**
+     * 获取素材总数
+     * 图片和图文消息素材(包括单图文和多图文)的总数上限为5000,其他素材的总数上限为1000
+     */
+    public function getMaterialCount($merchant)
+    {
+        $token = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token={$token}";
+        $curl = new curl\Curl();
+        $response = $curl->get($url);
+        return $response;
+    }
+
+    /**
+     * 获取素材列表 图文列表
+     *    $data    = ['type' => 'image','offset' => 0,'count' => 100];
+     *    type:news image video voice
+     */
+    public function batchgetMaterial($merchant, $data)
+    {
+        $token = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token={$token}";
+        $curl = new curl\Curl();
+        $response = $curl->setOption(CURLOPT_POSTFIELDS, json_encode($data))->post($url);
+        return json_decode($response, true);
+    }
+
+    /**
+     * 解除绑定删除自定义菜单
+     * @param string $accessToken
+     */
+    public static function menuDelete($merchant)
+    {
+        $token = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=$token";
+        $curl = new curl\Curl();
+        $response = $curl->get($url);
+        return $response;
+    }
+
+    //微信api不支持中文转义的json结构
+    static function json_encode($arr)
+    {
+        if (count($arr) == 0) return "[]";
+        $parts = array();
+        $is_list = false;
+        //Find out if the given array is a numerical array
+        $keys = array_keys($arr);
+        $max_length = count($arr) - 1;
+        if (($keys [0] === 0) && ($keys [$max_length] === $max_length)) { //See if the first key is 0 and last key is length - 1
+            $is_list = true;
+            for ($i = 0; $i < count($keys); $i++) { //See if each key correspondes to its position
+                if ($i != $keys [$i]) { //A key fails at position check.
+                    $is_list = false; //It is an associative array.
+                    break;
+                }
+            }
+        }
+        foreach ($arr as $key => $value) {
+            if (is_array($value)) { //Custom handling for arrays
+                if ($is_list)
+                    $parts [] = self::json_encode($value); /* :RECURSION: */
+                else
+                    $parts [] = '"' . $key . '":' . self::json_encode($value); /* :RECURSION: */
+            } else {
+                $str = '';
+                if (!$is_list)
+                    $str = '"' . $key . '":';
+                //Custom handling for multiple data types
+                if (!is_string($value) && is_numeric($value) && $value < 2000000000)
+                    $str .= $value; //Numbers
+                elseif ($value === false)
+                    $str .= 'false'; //The booleans
+                elseif ($value === true)
+                    $str .= 'true';
+                else
+                    $str .= '"' . addslashes($value) . '"'; //All other things
+                $parts [] = $str;
+            }
+        }
+        $json = implode(',', $parts);
+        if ($is_list)
+            return '[' . $json . ']'; //Return numerical JSON
+        return '{' . $json . '}'; //Return associative JSON
+    }
+
+    /**
+     * 创建临时二维码 shish 2019.9.4
+     */
+    public static function qrcodeCreate($merchant, $sceneId, $expireSeconds = null)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=$accessToken";
+        //有效期默认一天
+        $expireSeconds = isset($expireSeconds) ? $expireSeconds : 86400;
+        $post = array('expire_seconds' => $expireSeconds, 'action_name' => 'QR_STR_SCENE', "action_info" => array('scene' => array('scene_str' => $sceneId)));
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 创建永久二维码
+     */
+    public static function qrcodePermanentCreate($merchant, $sceneId)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=$accessToken";
+        $post = array('action_name' => 'QR_LIMIT_STR_SCENE', "action_info" => array('scene' => array('scene_str' => $sceneId)));
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 微信授权获取code
+     */
+    public static function getCode($urlEncode, $merchant, $scope)
+    {
+        $host = Yii::$app->request->getHostInfo();
+        $REDIRECT_URI = $host . '/auth/get-user-info?url=' . $urlEncode . '&authScope=' . $scope;
+        Yii::info($REDIRECT_URI);
+        $appId = $merchant['wxAppId'];
+        $id = configDict::getConfig('openId');
+        $open = xhWxOpenService::getById($id);
+        $component_appid = $open['appId'];
+        $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $appId . "&redirect_uri=" . urlencode($REDIRECT_URI) . "&response_type=code&scope=" . $scope . "&state=1&component_appid={$component_appid}#wechat_redirect";
+        header("Location:" . $url);
+        //如果这里没有exit(),在apache服务器下无法实现跳转
+        exit();
+    }
+
+    /**
+     * 获取openId
+     */
+    public static function getOpenId($code, $merchant)
+    {
+        $appId = $merchant['wxAppId'];
+        $id = configDict::getConfig('openId');
+        $open = xhWxOpenService::getById($id);
+        $component_appid = $open['appId'];
+        $componentAccessToken = wxUtil::getComponentAccessToken($open);
+        $url = "https://api.weixin.qq.com/sns/oauth2/component/access_token?appid={$appId}&code={$code}&grant_type=authorization_code&component_appid={$component_appid}&component_access_token={$componentAccessToken}";
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $data = Json::decode($result);
+        if (isset($data['openid']) == false) {
+            Yii::warning('error:' . json_encode($data) . ' code:' . $code, __METHOD__);
+            return false;
+        }
+        return $data;
+    }
+
+    /**
+     * 授权获取自己的信息
+     */
+    public function authGetUserInfo($openid, $access_token)
+    {
+        $url = "https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid";
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $data = Json::decode($result);
+        return $data;
+    }
+
+    /**
+     * 自动获取自己的信息(公众号的粉丝才能获取)
+     */
+    public static function autoGetUserInfo($openid, $merchant)
+    {
+        $access_token = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$access_token&openid=$openid&lang=zh_CN";
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $data = Json::decode($result);
+        return $data;
+    }
+
+    /**
+     * 网址接入验证
+     */
+    public static function signatureValidation()
+    {
+        $signature = $_GET['signature'];
+        $timestamp = $_GET['timestamp'];
+        $nonce = $_GET['nonce'];
+        $account = $_GET['account'];
+        $merchant = xhMerchantService::getByAccount($account);
+        if ($merchant) {
+            $token = $merchant['wxToken'];
+            // 3个数值组成数组验证
+            $tmpArr = array(
+                $token,
+                $timestamp,
+                $nonce
+            );
+            // 字典排序
+            sort($tmpArr, SORT_STRING);
+            $tmpStr = implode($tmpArr);
+            // sha1加密
+            $tmpStr = sha1($tmpStr);
+            if ($signature == $tmpStr) {
+                return true;
+            } else {
+                return false;
+            }
+        } else {
+            return false;
+        }
+    }
+
+    //客服接口发消息
+    public static function sendMsg($content, $merchant, $openId)
+    {
+        $token = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$token}";
+        $data = ['touser' => $openId, 'msgtype' => 'text', 'text' => ['content' => $content]];
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    public static function sendImgMsg($mediaId, $merchant, $openId)
+    {
+        $token = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$token}";
+        $data = ['touser' => $openId, 'msgtype' => 'image', 'image' => ['media_id' => $mediaId]];
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    public static function sendVideoMsg($mediaId, $merchant, $openId)
+    {
+        $token = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$token}";
+        $data = ['touser' => $openId, 'msgtype' => 'video', 'video' => ['media_id' => $mediaId,
+            'thumb_media_id' => $mediaId,
+            'title' => '因爱而生',
+            'description' => "情定原生,爱在今生;\n坐标:浙江,绍兴上虞;\n看到过一句话:“一个城市不过是几条巷道上,几间房子和几个人的组合。如果没有了这些,一个城市如同陨落,只剩下悲凉的记忆;”\n万事万物持续流变,珍爱的东西尤其不可能一直存在,如朝霞,如春花,如爱情;\n无论什么时候,不管天气好坏,都能拿出某些个让人喜欢的东西。",
+        ]];
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 消息模板,发送任务通知
+     * @param unknown $data
+     * @return mixed
+     */
+    public static function sendTaskInform($data, $merchant)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$accessToken}";
+        $data = urldecode(json_encode($data, JSON_UNESCAPED_UNICODE));
+        $curl = new curl\Curl();
+        $response = $curl->setOption(CURLOPT_POSTFIELDS, $data)->post($url);
+        $arr = json_decode($response);
+        return $arr;
+    }
+
+    /**
+     * 创建模板消息
+     * @param unknown $accessToken
+     * @param unknown $template_id_short
+     * @return unknown
+     */
+    public static function tMessageCreate($merchant, $shortTemplateId)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token={$accessToken}";
+        $post = array('template_id_short' => $shortTemplateId);
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 删除模板消息
+     * @param unknown $accessToken
+     * @param unknown $templateId
+     * @return unknown
+     */
+    public static function delTMessage($merchant, $templateId)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token={$accessToken}";
+        $post = array('template_id' => $templateId);
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 取所有模板消息
+     * @param unknown_type $appId
+     * @return unknown
+     */
+    public function getAllTMessage($merchant)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token={$accessToken}";
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 设置模板消息的行业
+     * @param unknown $accessToken
+     * @param unknown $templateId
+     * @return unknown
+     */
+    public function setTMIndustry($merchant, $industry_id1, $industry_id2)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token={$accessToken}";
+        $post = array('industry_id1' => $industry_id1, 'industry_id2' => $industry_id2);
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 获取公众号的accessToken 公众号调用凭据
+     * @param unknown $appId
+     * @return unknown|string
+     */
+    public static function getAuthorizerAccessToken($merchant, $isOpen = 0)
+    {
+        $merchantId = $merchant['id'];
+        $id = configDict::getConfig('openId');
+        $open = xhWxOpenService::getById($id);
+        $component_appid = $open['appId'];
+        $componentAccessToken = wxUtil::getComponentAccessToken($open);
+        $appId = $merchant['wxAppId'];
+        $wxAccessToken = $merchant['wxAccessToken'];
+        $wxAccessTokenTime = $merchant['wxAccessTokenTime'];
+        $authorizer_refresh_token = $merchant['wxRefreshToken'];
+        $now = time();
+        if ($now > strtotime($wxAccessTokenTime)) {
+            $url = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token={$componentAccessToken}";
+            $data = ['component_appid' => $component_appid, 'authorizer_appid' => $appId, 'authorizer_refresh_token' => $authorizer_refresh_token];
+            $curl = new curl\Curl();
+            $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+            $result = Json::decode($result);
+            if (isset($result['authorizer_access_token'])) {
+                $authorizer_access_token = $result['authorizer_access_token'];
+                $expires_in = $result['expires_in'];
+                $authorizer_refresh_token = $result['authorizer_refresh_token'];
+                $uData['wxRefreshToken'] = $authorizer_refresh_token;;
+                $uData['wxAccessToken'] = $authorizer_access_token;
+                $uData['wxAccessTokenTime'] = date("Y-m-d H:i:s", (time() + $expires_in - 100));
+                if ($isOpen == 1) {
+                    $open = WxOpenService::getOpen();
+                    $wx_base_id = isset($open['wx_base_id']) ? $open['wx_base_id'] : 0;
+                    if (!empty($wx_base_id)) {
+                        WxBaseService::updateById($wx_base_id, $uData);
+                    }
+                } else {
+                    xhMerchantService::updateById($merchantId, $uData);
+                }
+                return $authorizer_access_token;
+            }
+            return;
+        } else {
+            return $wxAccessToken;
+        }
+    }
+
+    /**
+     * 获取小程序的accessToken
+     */
+    public static function getMiniProgramAccessToken($merchant, $isOpen = 0)
+    {
+        $merchantId = $merchant['id'];
+        $id = configDict::getConfig('openId');
+        $open = xhWxOpenService::getById($id);
+        $component_appid = $open['appId'];
+        $componentAccessToken = wxUtil::getComponentAccessToken($open);
+        $appId = $merchant['miniAppId'];
+        if ($isOpen == 1) {
+            $miniAccessToken = $merchant['miniAccessToken'];
+            $miniAccessTokenTime = $merchant['miniAccessTokenTime'];
+            $miniRefreshToken = $merchant['miniRefreshToken'];
+        } else {
+            $extend = xhMerchantExtendService::getByMerchantId($merchantId);
+            $miniAccessToken = $extend['miniAccessToken'];
+            $miniAccessTokenTime = $extend['miniAccessTokenTime'];
+            $miniRefreshToken = $extend['miniRefreshToken'];
+        }
+        $now = time();
+        if ($now > strtotime($miniAccessTokenTime)) {
+            $url = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token={$componentAccessToken}";
+            $data = ['component_appid' => $component_appid, 'authorizer_appid' => $appId, 'authorizer_refresh_token' => $miniRefreshToken];
+            $curl = new curl\Curl();
+            $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+            $result = Json::decode($result);
+            Yii::info('重新获取mini accesstoken:' . json_encode($result));
+            if (isset($result['authorizer_access_token'])) {
+                $expires_in = $result['expires_in'];
+                $miniAccessToken = $result['authorizer_access_token'];
+                $uData['miniRefreshToken'] = $result['authorizer_refresh_token'];
+                $uData['miniAccessToken'] = $miniAccessToken;
+                $uData['miniAccessTokenTime'] = date("Y-m-d H:i:s", (time() + $expires_in - 100));
+                if ($isOpen == 1) {
+                    $open = WxOpenService::getOpen();
+                    $wx_mini_base_id = isset($open['wx_mini_base_id']) ? $open['wx_mini_base_id'] : 0;
+                    if (!empty($wx_mini_base_id)) {
+                        WxMiniBaseService::updateById($wx_mini_base_id, $uData);
+                    }
+                } else {
+                    xhMerchantExtendService::updateByMerchantId($merchantId, $uData);
+                }
+
+                return $miniAccessToken;
+            }
+            Yii::info('accessToken失效:merchantId:' . $merchantId);
+        }
+        return $miniAccessToken;
+    }
+
+    public static function saveWeixinImg($userId, $url, $class = 0)
+    {
+        $className = [
+            '0' => 'weixinUserAvatar',//微信头像
+            '1' => 'weixinUserImg',//微信公众号二维码
+            '2' => 'weixinMpQrcode',
+            '3' => 'weixinMpAvatar',
+        ];
+        $folder = Yii::getAlias('@webroot') . '/../../images';
+        $pre = '/' . $className[$class] . '/' . date('Y') . '/' . date('m') . '/' . date("d") . '/';
+        if (!file_exists($folder . $pre))
+            mkdir($folder . $pre, 0777, true);
+        $randString = stringUtil::buildOrderNo();
+        $name = md5($userId . $randString) . '.jpg';
+        $fullFileName = $folder . $pre . $name;
+        $fileName = $pre . $name;
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $fp2 = @fopen($fullFileName, 'a');//文件大小
+        fwrite($fp2, $result);
+        fclose($fp2);
+        return $fileName;
+    }
+
+    /**
+     * 下载学员作品图片
+     */
+    public static function downloadStudentWorksImg($merchant, $mediaId, $savePathType = 'wxUserImg')
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$accessToken}&media_id={$mediaId}";
+        $ch = curl_init($url);
+        curl_setopt($ch, CURLOPT_HEADER, 0);
+        curl_setopt($ch, CURLOPT_NOBODY, 0);//对body进行输出。
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        $body = curl_exec($ch);
+        $httpinfo = curl_getinfo($ch);
+        curl_close($ch);
+        preg_match('/\w\/(\w+)/i', $httpinfo["content_type"], $extmatches);//求出文件格式
+        $fileExt = $extmatches[1];
+        $imgSavePath = configDict::getConfig('imgSavePath');
+        $comImgSavePath = $imgSavePath[$savePathType];
+        $folder = Yii::getAlias('@webroot') . '/../../images';
+        $pre = '/' . $comImgSavePath . '/' . date('Y') . '/' . date('m') . '/' . date("d") . '/';
+        if (!file_exists($folder . $pre)) {
+            mkdir($folder . $pre, 0777, true);
+        }
+        $randString = stringUtil::buildOrderNo();
+        $fullFileName = $folder . $pre . $randString . '.jpg';
+        $fileName = $pre . $randString . '.jpg';
+        $fp2 = @fopen($fullFileName, 'a');//文件大小
+        fwrite($fp2, $body);
+        fclose($fp2);
+        $srcImg = $fullFileName;
+
+        $dstImg300 = $folder . $pre . $randString . "_300.jpg";//生成300px缩略图,不保存到数据库
+        util::img2thumb($srcImg, $dstImg300, $width = 300, 0, 0, 0);
+
+        $dstImg100 = $folder . $pre . $randString . "_100.jpg";//生成50px缩略图,不保存到数据库
+        util::img2thumb($srcImg, $dstImg100, $width = 100, 0, 0, 0);
+        return $fileName;
+    }
+
+    /**
+     * 获取media_id里的图片保存到服务器
+     */
+    public static function downloadmediaIdImg($merchant, $mediaId, $savePathType = 'wxUserImg')
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$accessToken}&media_id={$mediaId}";
+        $ch = curl_init($url);
+        curl_setopt($ch, CURLOPT_HEADER, 0);
+        curl_setopt($ch, CURLOPT_NOBODY, 0);//对body进行输出。
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        $body = curl_exec($ch);
+        $httpinfo = curl_getinfo($ch);
+        curl_close($ch);
+        preg_match('/\w\/(\w+)/i', $httpinfo["content_type"], $extmatches);//求出文件格式
+        $fileExt = $extmatches[1];
+        $imgSavePath = configDict::getConfig('imgSavePath');
+        $comImgSavePath = $imgSavePath[$savePathType];
+        $folder = Yii::getAlias('@webroot') . '/../../images';
+        $pre = '/' . $comImgSavePath . '/' . date('Y') . '/' . date('m') . '/' . date("d") . '/';
+        if (!file_exists($folder . $pre)) {
+            mkdir($folder . $pre, 0777, true);
+        }
+        $randString = stringUtil::buildOrderNo();
+        $fullFileName = $folder . $pre . $randString . '.jpg';
+        $fileName = $pre . $randString . '.jpg';
+        $fp2 = @fopen($fullFileName, 'a');//文件大小
+        fwrite($fp2, $body);
+        fclose($fp2);
+        $srcImg = $fullFileName;
+
+        $mediumImg = $pre . $randString . "_200.jpg";
+        $dstImg200 = $folder . $mediumImg;//生成200px缩略图,不保存到数据库
+        util::img2thumb($srcImg, $dstImg200, $width = 200, 0, 0, 0);
+
+        $smallImg = $pre . $randString . "_50.jpg";
+        $dstImg50 = $folder . $smallImg;//生成50px缩略图,不保存到数据库
+        util::img2thumb($srcImg, $dstImg50, $width = 50, 0, 0, 0);
+        return ['large' => $fileName, 'medium' => $mediumImg, 'small' => $smallImg];
+    }
+
+    public static function createTag($merchant, $name)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/tags/create?access_token={$accessToken}";
+        $post = ['tag' => ['name' => $name]];
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    public static function delTag($merchant, $id)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/tags/delete?access_token={$accessToken}";
+        $post = ['tag' => ['id' => $id]];
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    public static function modTag($merchant, $id, $name)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/tags/update?access_token={$accessToken}";
+        $post = ['tag' => ['id' => $id, 'name' => $name]];
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 获取商家所有标签
+     */
+    public static function getTag($merchant)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/tags/get?access_token={$accessToken}";
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    public function getUserTag($tagId, $nextOpenId = '')
+    {
+        $url = "https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=" . $this->access_token;
+        $post = ['tagid' => $tagId, 'next_openid' => $nextOpenId];
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 批量为用户打标签
+     */
+    public static function membersBatchTag($merchant, $openIdList, $tagId)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token={$accessToken}";
+        $post = ['openid_list' => $openIdList, 'tagid' => $tagId];
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 批量取消用户标签
+     * @param unknown_type $appId
+     * @param unknown_type $openIdList
+     * @param unknown_type $tagId
+     * @return unknown
+     */
+    public static function membersCancelTag($merchant, $openIdList, $tagId)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token={$accessToken}";
+        $post = ['openid_list' => $openIdList, 'tagid' => $tagId];
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($post))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 新增临时素材
+     * @param unknown_type $appId
+     * @return unknown
+     */
+    public static function uploadTempMedia($merchant, $imgUrl, $type = 'image')
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token={$accessToken}&type=" . $type;
+        $postData = ['media' => '@' . $imgUrl];
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        $response = curl_exec($ch);
+        $result = Json::decode($response);
+        return $result;
+    }
+
+    /**
+     * 获取临时素材
+     * @param unknown_type $appId
+     * @param unknown_type $mediaId
+     */
+    public static function getTempMaterial($merchant, $mediaId)
+    {
+        $accessToken = self::getAuthorizerAccessToken($merchant);
+        $url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$accessToken}&media_id=" . $mediaId;
+        $fileInfo = self::getTempMaterialInfo($url);
+        if (empty($fileInfo) || isset($fileInfo['errcode'])) {
+            $msg = '未错误哦~';
+            return ['code' => 'A0002', 'msg' => $msg];
+        }
+        $fileName = substr(md5($mediaId), -4) . stringUtil::buildOrderNo() . '.amr';
+        $preFolder = Yii::getAlias('@webroot') . '/../../images';
+        $folder = '/weixinChatVoice/' . date('Y') . '/' . date('m') . '/' . date("d") . '/';
+        if (!file_exists($preFolder . $folder))
+            mkdir($preFolder . $folder, 0777, true);
+        $saveFile = $preFolder . $folder . $fileName;
+        if (file_exists($saveFile) == false) {
+            self::readTempMaterial($saveFile, $fileInfo["body"]);
+        }
+        return ['code' => 'A0001', 'msg' => 'success', 'data' => ['url' => $folder . $fileName]];
+    }
+
+    /**
+     * 获取临时素材的头信息等
+     * @param unknown_type $url
+     * @return unknown
+     */
+    public static function getTempMaterialInfo($url)
+    {
+        $ch = curl_init($url);
+        curl_setopt($ch, CURLOPT_HEADER, 0);
+        curl_setopt($ch, CURLOPT_NOBODY, 0);//只取body头
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        $package = curl_exec($ch);
+        $httpinfo = curl_getinfo($ch);
+        curl_close($ch);
+        $imageAll = ['header' => $httpinfo, 'body' => $package];
+        return $imageAll;
+    }
+
+    /**
+     * 读取临时素材的资源
+     * @param unknown_type $filename
+     * @param unknown_type $fileContent
+     */
+    function readTempMaterial($filename, $fileContent)
+    {
+        $localFile = fopen($filename, 'w');
+        if (false !== $localFile) {
+            if (false !== fwrite($localFile, $fileContent)) {
+                fclose($localFile);
+            }
+        }
+    }
+
+    /**
+     * 创建门店
+     * @param $merchant
+     * @param $menu
+     * @return mixed
+     */
+    public function createStore($info)
+    {
+        $jsonData = urldecode(json_encode($info, JSON_UNESCAPED_UNICODE));
+        $url = "http://api.weixin.qq.com/cgi-bin/poi/addpoi?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        return $curl->setOption(CURLOPT_POSTFIELDS, $jsonData)->post($url);
+    }
+
+    /**
+     * 查询门店信息
+     * @param $poi_id
+     */
+    public function getStoreInfo($poi_id)
+    {
+        $data = ['poi_id' => $poi_id];
+        $jsonData = urldecode(json_encode($data, JSON_UNESCAPED_UNICODE));
+        $url = "http://api.weixin.qq.com/cgi-bin/poi/getpoi?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        return $curl->setOption(CURLOPT_POSTFIELDS, $jsonData)->post($url);
+    }
+
+    /**
+     * 查询门店列表
+     * @param int $begin 开始数据
+     * @param int $count 返回数据条数,最大允许50,默认为20
+     */
+    public function getStoreList($begin = 0, $count = 20)
+    {
+        $data = ["begin" => $begin, "limit" => $count];
+        $jsonData = urldecode(json_encode($data, JSON_UNESCAPED_UNICODE));
+        $url = "http://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        return $curl->setOption(CURLOPT_POSTFIELDS, $jsonData)->post($url);
+    }
+
+    /**
+     * 查询门店列表 -- 重复 可删除
+     * @param $data
+     * @return mixed
+     */
+    function getShopList($data)
+    {
+        $url = "https://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 修改门店服务信息
+     */
+    public function updateStore(array $buffer)
+    {
+        $jsonData = urldecode(json_encode($buffer, JSON_UNESCAPED_UNICODE));
+        $url = "http://api.weixin.qq.com/cgi-bin/poi/updatepoi?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        return $curl->setOption(CURLOPT_POSTFIELDS, $jsonData)->post($url);
+    }
+
+    /**
+     * 删除门店
+     * @param $poi_id
+     * @return mixed
+     */
+    public function delStore($poi_id)
+    {
+        $data = ['poi_id' => $poi_id];
+        $jsonData = urldecode(json_encode($data, JSON_UNESCAPED_UNICODE));
+        $url = "http://api.weixin.qq.com/cgi-bin/poi/delpoi?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        return $curl->setOption(CURLOPT_POSTFIELDS, $jsonData)->post($url);
+    }
+
+    /**
+     * 门店类目表
+     */
+    public function storeTypeList()
+    {
+        $url = "http://api.weixin.qq.com/cgi-bin/poi/getwxcategory?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        return $curl->get($url);
+    }
+
+    /******************************* wifi *************************************/
+    /**
+     * 获取wifi门店列表
+     * @param $pageindex    开始页
+     * @param $pagesize     每页数据条数(最大20)
+     * @return mixed
+     */
+    function getShopWifiList($pageindex = 1, $pagesize = 10)
+    {
+        $data = ["pageindex" => $pageindex, "pagesize" => $pagesize];
+        $url = "https://api.weixin.qq.com/bizwifi/shop/list?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 添加密码型设备
+     * @param $shopId   门店ID
+     * @param $ssid     无线网络设备的ssid
+     * @param $pwd      无线网络设备的密码
+     * @return mixed
+     */
+    function addPasswordDevice($shopId, $ssid, $pwd)
+    {
+        $data = ["shop_id" => $shopId, "ssid" => $ssid, "password" => $pwd];
+        $url = "https://api.weixin.qq.com/bizwifi/device/add?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 修改门店Wi-Fi(修改门店网络信息)
+     * @param $shopId
+     * @param $oldSsid
+     * @param $ssid
+     * @param string $pwd
+     * @return mixed
+     */
+    function updateDevice($shopId, $oldSsid, $ssid, $pwd = '')
+    {
+        $data = ["shop_id" => $shopId, "old_ssid" => $oldSsid, "ssid" => $ssid];
+        if (!empty($pwd)) {
+            $data["password"] = $pwd;
+        }
+        $url = "https://api.weixin.qq.com/bizwifi/shop/update?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 删除密码型设备
+     * @param $bssid   无线网络设备无线mac地址
+     * @return mixed
+     */
+    function delPasswordDevice($bssid)
+    {
+        $data = ["bssid" => $bssid];
+        $url = "https://api.weixin.qq.com/bizwifi/device/delete?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 查询门店Wi-Fi信息
+     * @param $shopId   门店ID
+     * @return mixed
+     */
+    function getShopWifi($shopId)
+    {
+        $data = ["shop_id" => $shopId];
+        $url = "https://api.weixin.qq.com/bizwifi/shop/get?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    /**
+     * 获取物料二维码
+     * @param $shopId   门店ID
+     * @param $ssid     无线网络设备的ssid
+     * @param $img_id   物料样式编号(0-纯二维码,可用于自由设计宣传材料;1-二维码物料,155mm×215mm(宽×高),可直接张贴)
+     * @return mixed
+     */
+    function getWifiQrCode($shopId, $ssid, $img_id)
+    {
+        //$data = ["shop_id" => 429620, "ssid" => "WX567", "img_id" => $img_id];
+        $data = ["shop_id" => $shopId, "ssid" => $ssid, "img_id" => $img_id];
+        $url = "https://api.weixin.qq.com/bizwifi/qrcode/get?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    function getWifiUrl()
+    {
+        $url = "https://api.weixin.qq.com/bizwifi/account/get_connecturl?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    function generateShortUrl($longUrl)
+    {
+        $data = ["action" => "long2short", "long_url" => $longUrl,];
+        $url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=" . $this->access_token;
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        if (isset($result['errcode']) && $result['errcode'] == 0) {
+            return ['code' => 'A0001', 'data' => ['shortUrl' => $result['short_url']]];
+        }
+        return ['code' => 'A0002', 'data' => []];
+    }
+
+    //长链接转短链接 shish 2019.9.26
+    public static function urlLongToShort($longUrl, $merchant)
+    {
+        $accessToken = self::getMiniProgramAccessToken($merchant);
+        $data = ["action" => "long2short", "long_url" => $longUrl,];
+        $url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=" . $accessToken;
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        $url = '';
+        if (isset($result['errcode']) && $result['errcode'] == 0) {
+            $url = $result['short_url'];
+        }
+        return ['url' => $url];
+    }
+
+    /**
+     * 拉取门店所有的设备信息
+     * @return array
+     */
+    public function getShopWifiListAll()
+    {
+        $startPage = 1;
+        $list = [];
+        while (true) {
+            $reList = $this->getShopWifiList($startPage, 20);
+            if ($startPage <= $reList['data']['pagecount']) {
+                $list = array_merge($list, $reList['data']['records']);
+                ++$startPage;
+            } else {
+                break;
+            }
+        }
+
+        return $list;
+    }
+
+    /**
+     * 通过 poi_id 从Wi-Fi门店列表中 获取 shopId
+     * @param $poiId
+     * @return bool
+     */
+    public function getShopId($poiId, $list = [])
+    {
+        if (empty($list)) {
+            $list = $this->getShopWifiListAll();
+        }
+        foreach ($list as $shop) {
+            if ($shop['poi_id'] == $poiId)
+                return (string)$shop['shop_id'];
+        }
+
+        return false;
+    }
+
+    //设置小程序服务器域名
+    public static function setDomain($merchant, $isOpen = 0)
+    {
+        $accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
+        $url = "https://api.weixin.qq.com/wxa/modify_domain?access_token=" . $accessToken;
+        $curl = new curl\Curl();
+        $mallHost = Yii::$app->params['mallHost'];
+        $has = strpos($mallHost, 'https');
+        //如果不是https则换成https
+        if ($has === false) {
+            $mallHost = str_replace('http', 'https', $mallHost);
+        }
+        $data = [
+            "action" => "set",
+            "requestdomain" => [$mallHost],
+            "wsrequestdomain" => [$mallHost],
+            "uploaddomain" => [$mallHost],
+            "downloaddomain" => [$mallHost],
+        ];
+        print_r($data);
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $respond = Json::decode($result);
+        print_r($respond);
+    }
+
+    //设置业务域名
+    public static function setWebViewDomain($merchant, $isOpen = 0)
+    {
+        $accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
+        $url = "https://api.weixin.qq.com/wxa/setwebviewdomain?access_token=" . $accessToken;
+        $curl = new curl\Curl();
+        $mallHost = Yii::$app->params['mallHost'];
+        $has = strpos($mallHost, 'https');
+        //如果不是https则换成https
+        if ($has === false) {
+            $mallHost = str_replace('http', 'https', $mallHost);
+        }
+        $data = [
+            "action" => "set",
+            "webviewdomain" => [$mallHost],
+        ];
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $respond = Json::decode($result);
+        print_r($respond);
+    }
+
+    //为授权的小程序帐号上传小程序代码
+    public static function miniCommit($merchant, $templateId, $isOpen = 0)
+    {
+        $accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
+        $url = 'https://api.weixin.qq.com/wxa/commit?access_token=' . $accessToken;
+        $curl = new curl\Curl();
+        $mUrl = Yii::$app->params['mallHost'];
+        $imgUrl = Yii::$app->params['imgHost'];
+
+        //如果不是https则换成https
+        $has = strpos($mUrl, 'https');
+        if ($has === false) {
+            $mUrl = str_replace('http', 'https', $mUrl);
+        }
+
+        //如果不是https则换成https
+        $has = strpos($imgUrl, 'https');
+        if ($has === false) {
+            $imgUrl = str_replace('http', 'https', $imgUrl);
+        }
+        $account = isset($merchant['id']) ? $merchant['id'] : 0;
+        $name = isset($merchant['merchantName']) ? $merchant['merchantName'] : '';
+        if ($isOpen == 1) {
+            $open = WxOpenService::getOpen();
+            $name = isset($open['name']) ? $open['name'] : '';
+        }
+        $ext = [
+            'extAppid' => $merchant['miniAppId'],
+            'ext' => [
+                'account' => $account,
+                'mallHost' => $mUrl,
+                'imgHost' => $imgUrl,
+                'merchantName' => $name,
+            ],
+        ];
+        Yii::info("ext:" . json_encode($ext));
+        $extJson = json_encode($ext);
+        $data = [
+            "template_id" => $templateId,
+            "ext_json" => $extJson,
+            "user_version" => date("mdHis"),
+            "user_desc" => date("mdHis")
+        ];
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $respond = Json::decode($result);
+        print_r($respond);
+    }
+
+    //获取体验小程序的体验二维码
+    public static function getExperienceQrCode($merchant, $isOpen = 0)
+    {
+        $accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
+        $path = urlencode("pages/home/index");
+        $url = "https://api.weixin.qq.com/wxa/get_qrcode?access_token={$accessToken}&path=" . $path;
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $file = dirUtil::getImgDir() . '/retail/miniExperience/' . $merchant['id'] . '.jpg';
+        file_put_contents($file, $result);
+        echo "<b /><img src='" . Yii::$app->params['imgHost'] . "/retail/miniExperience/" . $merchant['id'] . ".jpg' />";
+    }
+
+    //获取授权小程序帐号已设置的类目
+    public static function getMiniCategory($merchant, $isOpen = 0)
+    {
+        $accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
+        $url = "https://api.weixin.qq.com/wxa/get_category?access_token=" . $accessToken;
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $respond = Json::decode($result);
+        echo "<pre>";
+        print_r($respond);
+    }
+
+    //获取小程序的第三方提交代码的页面配置
+    public static function getMiniPage($merchant, $isOpen = 0)
+    {
+        $accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
+        $url = "https://api.weixin.qq.com/wxa/get_page?access_token=" . $accessToken;
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $respond = Json::decode($result);
+        echo "<pre>";
+        print_r($respond);
+    }
+
+    //将第三方提交的代码包提交审核
+    public static function miniSubmitAudit($merchant, $isOpen = 0)
+    {
+        $accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
+        $url = "https://api.weixin.qq.com/wxa/submit_audit?access_token=" . $accessToken;
+        $curl = new curl\Curl();
+        $data = [
+            "item_list" => [
+                [
+                    "address" => "pages/home/index",
+                    "tag" => "鲜花 花店",
+                    "first_class" => "商家自营",
+                    "second_class" => "鲜花/园艺/工艺品",
+                    "first_id" => 304,
+                    "second_id" => 323,
+                    "title" => "商城",
+                ],
+            ],
+            "feedback_info" => "",
+            "feedback_stuff" => "",
+        ];
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $respond = Json::decode($result);
+        echo "<pre>";
+        print_r($respond);
+    }
+
+    //查询最新一次提交的审核状态
+    public static function miniGetLatestAuditStatus($merchant, $isOpen = 0)
+    {
+        $accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
+        $url = "https://api.weixin.qq.com/wxa/get_latest_auditstatus?access_token=" . $accessToken;
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $respond = Json::decode($result);
+        echo "<pre>";
+        print_r($respond);
+    }
+
+
+    //发布已通过审核的小程序
+    public static function miniRelease($merchant, $isOpen = 0)
+    {
+        $accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
+        $url = "https://api.weixin.qq.com/wxa/release?access_token=" . $accessToken;
+        $curl = new curl\Curl();
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, '{}')->post($url);
+        $respond = Json::decode($result);
+        return $respond;
+    }
+
+    //撤回审核
+    public static function rollbackCheck($merchant, $isOpen = 0)
+    {
+        $accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
+        $url = "https://api.weixin.qq.com/wxa/undocodeaudit?access_token=" . $accessToken;
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $respond = Json::decode($result);
+        echo "<pre>";
+        print_r($respond);
+    }
+
+    //申请会员的小程序码
+    public static function generateMemberCode($merchant, $shopId, $isOpen = 0)
+    {
+        $behind = '/retail/mimiMemberCode/' . $merchant['id'] . '_' . $shopId . '_apply_member.jpg';
+        $file = dirUtil::getImgDir() . $behind;
+        if (file_exists($file)) {
+            return $behind;
+        }
+        $path = 'pages/home/user?scan=1&shopId=' . $shopId;
+        $accessToken = self::getMiniProgramAccessToken($merchant);
+        $url = "https://api.weixin.qq.com/wxa/getwxacode?access_token={$accessToken}";
+        $curl = new curl\Curl();
+        $data = [
+            "path" => $path,
+            "width" => 1000,
+        ];
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        file_put_contents($file, $result);
+        return $behind;
+    }
+
+    /**
+     * 微信开放平台获取component_access_token
+     */
+    public static function getComponentAccessToken($open)
+    {
+        $id = $open['id'];
+        $componentAccessToken = $open['componentAccessToken'];
+        $componentAccessTokenTime = $open['componentAccessTokenTime'];
+        $now = time();
+        if ($now > strtotime($componentAccessTokenTime)) {
+            $appId = $open['appId'];
+            $appSecret = $open['appSecret'];
+            $verifyTicket = $open['verifyTicket'];
+            $data = ['component_appid' => $appId, 'component_appsecret' => $appSecret, 'component_verify_ticket' => $verifyTicket];
+            $url = 'https://api.weixin.qq.com/cgi-bin/component/api_component_token';
+            $curl = new curl\Curl();
+            $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+            if (empty($result)) {
+                util::stop('没有取到ComponentAccessToken');
+            }
+            $result = Json::decode($result);
+            if (isset($result['component_access_token']) == false || empty($result['component_access_token'])) {
+                echo '<pre>';
+                print_r($result);
+                Yii::info('get component access token error:' . json_encode($result));
+                Yii::$app->end();
+            }
+            $component_access_token = $result['component_access_token'];
+            $expiresIn = $result['expires_in'];
+            $oData = [];
+            $oData['componentAccessToken'] = $component_access_token;
+            $oData['componentAccessTokenTime'] = date("Y-m-d H:i:s", ($now + $expiresIn - 100));//安全起见,将过期时间设置得比微信里还短
+            xhWxOpenService::updateById($id, $oData);
+            return $component_access_token;
+        } else {
+            return $componentAccessToken;
+        }
+    }
+
+    /**
+     * 微信开放平台获取预授权码pre_auth_code
+     */
+    public static function getPreAuthCode($open)
+    {
+        $id = $open['id'];
+        $preAuthCode = $open['preAuthCode'];
+        $preAuthCodeTime = $open['preAuthCodeTime'];
+        $now = time();
+        if ($now > strtotime($preAuthCodeTime)) {
+            $token = self::getComponentAccessToken($open);
+            $appId = $open['appId'];
+            $url = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token={$token}";
+            $curl = new curl\Curl();
+            $data = ['component_appid' => $appId];
+            $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+            $result = Json::decode($result);
+            Yii::info($result);
+            if (isset($result['pre_auth_code']) == false || empty($result['pre_auth_code'])) {
+                echo "没有取到pre_auth_code,原因:" . json_encode($result) . " appid:" . $appId . " token:" . $token;
+                Yii::$app->end();
+            }
+            $preAuthCode = $result['pre_auth_code'];
+            $expiresIn = $result['expires_in'];
+            $oData = [];
+            $oData['preAuthCode'] = $preAuthCode;
+            $oData['preAuthCodeTime'] = date("Y-m-d H:i:s", ($now + $expiresIn - 100));//安全起见,将过期时间设置得比微信里还短100秒
+            xhWxOpenService::updateById($id, $oData);
+            return $preAuthCode;
+        } else {
+            return $preAuthCode;
+        }
+    }
+
+    /**
+     * 微信开放平台使用授权码换取公众号的接口调用凭据和授权信息
+     * authorizer_access_token authorizer_refresh_token
+     */
+    public static function getAuthorizer($code)
+    {
+        $id = configDict::getConfig('openId');
+        $open = xhWxOpenService::getById($id);
+        $appId = $open['appId'];
+        $accessToken = self::getComponentAccessToken($open);
+        $url = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token={$accessToken}";
+        $curl = new curl\Curl();
+        $data = ['authorization_code' => $code, 'component_appid' => $appId];
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    //微信开放平台获取授权方的公众号帐号基本信息 shish 2020.3.11
+    public static function getAuthorizerInfo($authorizerAppId)
+    {
+        $open = WxOpenClass::getOpen();
+        $appId = $open['appId'];
+        $accessToken = self::getComponentAccessToken($open);
+        $url = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token={$accessToken}";
+        $curl = new curl\Curl();
+        $data = ['component_appid' => $appId, 'authorizer_appid' => $authorizerAppId];
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
 }