wang hou sheng 10 months ago
parent 46845c6b94
commit 02ae5ee9e6
  1. 18
      app/api/controller/Wxserver.php
  2. 7
      app/common/library/wxserver/Server.php

@ -4,7 +4,6 @@ declare (strict_types=1);
namespace app\api\controller;
use cores\BaseController;
use think\facade\Db;
use think\response\Json;
class Wxserver extends BaseController
@ -28,25 +27,10 @@ class Wxserver extends BaseController
public function redirect()
{
$authorization_code = $this->request->get('auth_code');
$expires_in = $this->request->get('expires_in');
$data = $this->request->input();
$datas = $this->request->get();
if ($datas) {
if (is_array($datas)) {
$datas = json_encode($datas);
}
Db::table('yoshop_wx_server')->insertGetId(['content' => '回调数据get&' . $datas . $authorization_code, 'created_at' => date('Y-m-d H:i:s')]);
}
if ($data) {
if (is_array($data)) {
$data = json_encode($data);
}
Db::table('yoshop_wx_server')->insertGetId(['content' => '回调数据input&' . $data . $authorization_code, 'created_at' => date('Y-m-d H:i:s')]);
}
Db::table('yoshop_wx_server')->insertGetId(['content' => '回调授权地址' . $authorization_code, 'created_at' => date('Y-m-d H:i:s')]);
if ($authorization_code) {
$obj = new \app\common\library\wxserver\Server();
$obj->authorizationInfo($authorization_code);
}
echo 'success';
}
}

@ -63,8 +63,7 @@ class Server
$result = $this->curlPost($url, json_encode($data), 10);
$result = json_decode($result, true);
if (!empty($result['component_access_token'])) {
$expire = !empty($result['expires_in']) ? intval($result['expires_in']) : 7200;
Cache::set('ComponentAccessToken', $result['component_access_token'], $expire);
Cache::set('ComponentAccessToken', $result['component_access_token'], 6200);
return $result['component_access_token'];
}
}
@ -117,22 +116,18 @@ class Server
*/
public function authorizationInfo($authorization_code)
{
Db::table('yoshop_wx_server')->insertGetId(['content' => '回调进来了' . $authorization_code, 'created_at' => date('Y-m-d H:i:s')]);
$url = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=' . $this->getComponentAccessToken();
$data = [];
$data['component_appid'] = self::APPID;
$data['authorization_code'] = $authorization_code;
$result = $this->curlPost($url, json_encode($data));
Db::table('yoshop_wx_server')->insertGetId(['content' => $result, 'created_at' => date('Y-m-d H:i:s')]);
$result = json_decode($result, true);
if ($result && !empty($result['authorization_info']) && !empty($result['authorization_info']['authorizer_appid'])) {
Db::table('yoshop_wx_server')->insertGetId(['content' => '获取详情' . $authorization_code, 'created_at' => date('Y-m-d H:i:s')]);
$url = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=' . $this->getComponentAccessToken();
$data = [];
$data['component_appid'] = self::APPID;
$data['authorizer_appid'] = $result['authorization_info']['authorizer_appid'];
$res = $this->curlPost($url, json_encode($data));
Db::table('yoshop_wx_server')->insertGetId(['content' => $res, 'created_at' => date('Y-m-d H:i:s')]);
$res = json_decode($res, true);
if ($res && !empty($res['authorizer_info']) && !empty($res['authorization_info'])) {
$authorizer_info = $res['authorizer_info'];

Loading…
Cancel
Save