wang hou sheng 9 months ago
parent 131df33601
commit 153dfe7734
  1. 6
      app/api/controller/Wxserver.php
  2. 19
      app/common/library/wxserver/Server.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';
}

@ -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);
}
}
}

Loading…
Cancel
Save