diff --git a/app/api/controller/Wxserver.php b/app/api/controller/Wxserver.php index 2f49ef71..e7a8f53c 100644 --- a/app/api/controller/Wxserver.php +++ b/app/api/controller/Wxserver.php @@ -16,8 +16,8 @@ class Wxserver extends BaseController public function index() { $obj = new \app\common\library\wxserver\Server(); - $arr = $obj->setDomainDirectly($this->request->domain(true), 'wx1814307a39775007'); - return $this->renderSuccess($arr); + $arr = $obj->setDomain($this->request->domain(true), 'wx1814307a39775007'); + return $this->renderSuccess([$arr]); } @@ -41,7 +41,7 @@ class Wxserver extends BaseController $authorization_code = $this->request->get('auth_code'); if ($authorization_code) { $obj = new \app\common\library\wxserver\Server(); - $obj->authorizationInfo($authorization_code); + $obj->authorizationInfo($authorization_code, $this->request->domain(true)); } echo 'success'; } diff --git a/app/common/library/wxserver/Server.php b/app/common/library/wxserver/Server.php index 9fe3946c..b9058fac 100644 --- a/app/common/library/wxserver/Server.php +++ b/app/common/library/wxserver/Server.php @@ -462,7 +462,14 @@ class Server return $list; } - public function setDomainDirectly($appid, $domain) + /** + * @notes:设置域名 + * @param $appid + * @param $domain + * @return bool + * @author: wanghousheng + */ + public function setDomain($appid, $domain): bool { $url = 'https://api.weixin.qq.com/wxa/modify_domain_directly?access_token=' . $this->authorizerAccessToken($appid); $data['action'] = 'set'; @@ -474,7 +481,10 @@ class Server $data['tcpdomain'] = []; $result = $this->curlPost($url, json_encode($data)); $result = json_decode($result, true); - return $result; + if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { + return true; + } + return false; } public function apiText($authorization_code, $touser) @@ -500,12 +510,13 @@ class Server /** * @notes:获取授权信息 * @param $authorization_code + * @param string $domain * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author: wanghousheng */ - public function authorizationInfo($authorization_code) + public function authorizationInfo($authorization_code, string $domain = '') { $url = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=' . $this->getComponentAccessToken(); $data = []; @@ -541,6 +552,8 @@ class Server $insert_data['create_time'] = time(); $insert_data['update_time'] = time(); $model->insertGetId($insert_data); + //设置域名信息 + $this->setDomain($insert_data['appid'], $domain); } } }