Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -5,8 +5,10 @@ namespace app\controller;
|
|||||||
use EasyWeChat\Factory;
|
use EasyWeChat\Factory;
|
||||||
use EasyWeChat\OfficialAccount\Application;
|
use EasyWeChat\OfficialAccount\Application;
|
||||||
use think\facade\Config;
|
use think\facade\Config;
|
||||||
|
use think\facade\Request;
|
||||||
use think\facade\Route;
|
use think\facade\Route;
|
||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
|
use think\response\Json;
|
||||||
|
|
||||||
class Wechat
|
class Wechat
|
||||||
{
|
{
|
||||||
@@ -29,14 +31,15 @@ class Wechat
|
|||||||
* @Date : 2022/9/9 11:29
|
* @Date : 2022/9/9 11:29
|
||||||
* @Author : <Jason.C>
|
* @Author : <Jason.C>
|
||||||
*/
|
*/
|
||||||
public function url(): string
|
public function url(): Json
|
||||||
{
|
{
|
||||||
$url = $GLOBALS['data']['data']['url'];
|
$url = $GLOBALS['data']['data']['url'];
|
||||||
$redirect = Route::buildUrl('wechat/code', ['callback' => $url])
|
$redirect = Route::buildUrl('wechat/code', ['callback' => $url])
|
||||||
->suffix(false)
|
->suffix(false)
|
||||||
->domain(true);
|
->domain(true);
|
||||||
$this->initWechat();
|
$this->initWechat();
|
||||||
return $this->app->oauth->scopes(['snsapi_userinfo'])->redirect($redirect);
|
|
||||||
|
return show(SUCCESS_MESSAGE,SUCCESS_CODE,$this->app->oauth->scopes(['snsapi_userinfo'])->redirect($redirect));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,8 +52,11 @@ class Wechat
|
|||||||
{
|
{
|
||||||
$this->initWechat();
|
$this->initWechat();
|
||||||
$user = $this->app->oauth->user();
|
$user = $this->app->oauth->user();
|
||||||
$code = $GLOBALS['data']['data']['code'];
|
$callback = Request::get('callback');
|
||||||
$user = $this->app->oauth->userFromCode($code);
|
|
||||||
|
$token = '怎样获得一个 token';
|
||||||
|
return redirect($callback.'?token='.$token);
|
||||||
|
|
||||||
// $user 可以用的方法:
|
// $user 可以用的方法:
|
||||||
// $user->getId(); // 对应微信的 OPENID
|
// $user->getId(); // 对应微信的 OPENID
|
||||||
// $user->getNickname(); // 对应微信的 nickname
|
// $user->getNickname(); // 对应微信的 nickname
|
||||||
|
|||||||
Reference in New Issue
Block a user