欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php使用微信登录

程序员文章站 2023-10-31 12:40:22
1.第一步 $hosturl = urlencode('');//异步回调地址 $wechatInfo = WechatInfo::get_wechat(); //查询appid $url = "https://open.weixin.qq.com/connect/oauth2/authorize? ......

1.第一步

$hosturl = urlencode('');//异步回调地址
$wechatinfo = wechatinfo::get_wechat(); //查询appid
$url    = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$wechatinfo['appid']}&redirect_uri={$hosturl}&response_type=code&scope=snsapi_base&state={$user['user_id']}#wechat_redirect";
$result = ['status' => 2, 'msg' => '登陆成功', 'data' => $user, 'url' => $url];

2.异步回调地址

$code = input('code');
$user_id = input('state');
$wechatinfo = wechatinfo::get_wechat();
$appid  = $wechatinfo['appid'];
$secret = $wechatinfo['appsecret'];
$url    = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$secret}&code={$code}&grant_type=authorization_code";
$sdk =jssdk::curlget($url);

 

 

有那些不明白的,可以在评论里留言,我会及时的回复大家的