本次开发 使用# EasyWeChat进行开发的
地址:https://www.easywechat.com/docs/master/overvie

这里一定选择3.x 已经标明了请注意:
1-使用命令在我们的tp5框架中安装
命令:composer require overtrue/wechat:~3.1 -vvv
结果:

配置文件地址:
https://blog.youkuaiyun.com/qq_37138818/article/details/88082822

步骤解释:
(A)用户打开客户端以后,客户端要求用户给予授权。
(B)用户同意给予客户端授权。
(C)客户端使用上一步获得的授权,向认证服务器申请令牌。
(D)认证服务器对客户端进行认证以后,确认无误,同意发放令牌。
(E)客户端使用令牌,向资源服务器申请获取资源。
(F)资源服务器确认令牌无误,同意向客户端开放资源。
代码1:
//引导用户授权
public function index()
{
//得到配置文件
$config = config("weixin");
$app = new Application($config);
$oauth = $app->oauth; //网页 授权
return $oauth->redirect(); //发起授权
}
测试如下:
域名或者ip/index/wechat/indedx 出现以下结果:
代码2:
//回调方法
public function call(){
//得到配置文件
$config = config("weixin");
$app = new Application($config);
$oauth = $app->oauth;
// 获取 OAuth 授权结果用户信息
$user = $oauth->user();
var_dump($user->toArray());
/*
$_SESSION['wechat_user'] = $user->toArray();
$targetUrl = empty($_SESSION['target_url']) ? '/' : $_SESSION['target_url'];
header('location:'. $targetUrl);*/
}
说明:修改回调的地址 在config的文件中的
/**
* OAuth 配置
*
* scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login
* callback:OAuth授权完成后的回调页地址
*/
'oauth' => [
'scopes' => ['snsapi_userinfo'],
'callback' => '/wechat/index/call',
],
3-- 测试
域名:http://www.xxx或者ip.cn/wechat/index/index 发送给 测试号点击地址出现;
或者其他的一些错误:
按照下图所示:添加你的域名或者你的ip

就可以的出现以下 并且得到当前用户的一些信息
结果:
//回调方法
public function call(){
//得到配置文件
$config = config("weixin");
$app = new Application($config);
$oauth = $app->oauth;
// 获取 OAuth 授权结果用户信息
$user = $oauth->user();
/* 可以的根据具体的业务需求下逻辑
---------------
--------------*/
var_dump($user->toArray());
/*
$_SESSION['wechat_user'] = $user->toArray();
$targetUrl = empty($_SESSION['target_url']) ? '/' : $_SESSION['target_url'];
header('location:'. $targetUrl);*/
}

328

被折叠的 条评论
为什么被折叠?



