微信公众号授权,常做登录用
微信公众号授权,常做登录用
// 微信公众号授权
public function WxAhref(){
$appid="wx9999999999999";
$redirect_uri="https://z.fuls.top/login/WxgetUser";
$url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
return redirect($url);
}
// 获取微信公众号用户的openid
public function WxgetUser(){
//file_get_contents("http://le.fuls.top/log/w?title=微信授权信息->跳转返回&data=".json_encode( input('param.') ) );
$appid="wx9999999999999";
$code=input('code');
$secret="9999999";
$url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$secret&code=$code&grant_type=authorization_code";
$res=json_decode(file_get_contents($url),true);
//file_get_contents("http://le.fuls.top/log/w?title=微信授权信息->再次请求返回&data=".json_encode( $res ) );
//获取用户信息
$ak=$res['access_token'];
$openid=$res['openid'];
$url="https://api.weixin.qq.com/sns/userinfo?access_token=$ak&openid=$openid&lang=zh_CN";
$res=json_decode(file_get_contents($url),true);
//file_get_contents("http://le.fuls.top/log/w?title=微信授权信息->授权用户信息&data=".json_encode( $res ) );
$is=Db::name("wxgzh_user")->where("openid",$res['openid'])->find();
if($is){
return "不可重复绑定";
}
Db::name("wxgzh_user")->insert([
'openid'=>$res['openid'],
'nickname'=>filter_Emoji($res['nickname']),
'headimgurl'=>$res['headimgurl'],
'type'=>0,
'status'=>1,
'addtime'=>time()
]);
return "绑定成功";
}
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 阿牛哥
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果