php微信扫码登录和公众号登录
发布日期:2021-11-18 19:17:29
浏览次数:13
分类:技术文章
本文共 2129 字,大约阅读时间需要 7 分钟。
/** * 微信授权登录 * @param Request * @return [json] */ public function wxSignin(Request $request){ $code = $request->input('code'); $state = $request->input('state'); $appid = config('wechat.appId'); $secret = config('wechat.secret'); $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$secret&code=$code&grant_type=authorization_code"; $data = $this->getclient($url); $access_token= $data['access_token']; $openid = $data['openid']; $res = "https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid"; $userinfo = $this->getclient($res); $res = $this->post('wx/authorize',$userinfo,[]); if($res['status_code'] == 200) { \Cookie::queue('CG_TK', $res['data']['token'], $minutes = 525600, $path = null, $domain = null, $secure = false, $httpOnly = false); } return redirect('https://www.*******.cn/d/?openid='.$openid); //跳转的路径}
/** * 微信扫码登录 * @param Request * @return [json] */public function qrcodeLogin(Request $request){ $code = $request->input('code'); $state = $request->input('state'); $appid = config('wechat.webappId'); $secret = config('wechat.webappsecret'); $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$secret&code=$code&grant_type=authorization_code"; $data = $this->getclient($url); //微信扫码三次请求 $refresh_token = $data['refresh_token']; $oneUrl = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=$appid&grant_type=refresh_token&refresh_token=$refresh_token"; $oneRequest = $this->getclient($oneUrl); $openid = $oneRequest['openid']; $access_token = $oneRequest['access_token']; $twoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid"; $twoRequest = $this->getclient($twoUrl); $data = $this->post('wx/authorize',$twoRequest,[]); return $data;}
转载地址:https://blog.csdn.net/weixin_39201566/article/details/86063970 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2024年04月14日 04时10分02秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Unity中实现反弹
2019-04-27
U3D游戏开发框架(九)——事件序列
2019-04-27
Unity中解决“SetDestination“ can only be called on an active agent that has been placed on a NavMesh
2019-04-27
Unity中的刚体
2019-04-27
Unity中的坐标转换
2019-04-27
Unity中为什么不能对transform.position.x直接赋值?
2019-04-27
Unity中物体移动方法详解
2019-04-27
使用对象池优化性能
2019-04-27
Unity中的UI方案(基础版)
2019-04-27
Lua(一)——Lua介绍
2019-04-27
Lua(二)——环境安装
2019-04-27
Unity中父子物体的坑
2019-04-27
基础知识——进位制
2019-04-27
Lua(十二)——表
2019-04-27
Lua(十三)——模块与包
2019-04-27
Lua(四)——变量
2019-04-27
Lua(十四)——元表
2019-04-27
Lua(十五)——协同程序
2019-04-27
Lua(十六)——文件
2019-04-27
Lua(十七)——面向对象
2019-04-27