🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
1.授权登入 ~~~ public function url(Request $request){ $urls=$request->param( 'url'); $appid='wxa5ed04228937e0fc'; $redirect_uri=urlencode($urls); $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 json($url); } ~~~ 2.静默登入 ~~~ public function url2(Request $request){ $appid='wxa5ed04228937e0fc'; $urls=$request->param( 'url'); $redirect_uri=urlencode($urls); $url= 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appid.'&redirect_uri='.$redirect_uri.'&response_type=code&scope=snsapi_base&state=123&redirect_uri=1#wechat_redirect'; return json($url); } ~~~ 3.通过code换取网页授权access_token及openid ~~~ public function access_token($code){ $appid='wxa5ed04228937e0fc'; $secret = 'a3938fdaeac026cce799bb21f9921248'; $url='https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$secret.'&code='.$code.'&grant_type=authorization_code'; $obj=$this->curl($url); $data=json_decode($obj, true); return $data; } ~~~ 4.通过网页授权获取用户资料 ~~~ public function user_get($access_token,$openid){ $url='https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid.'&lang=zh_CN'; $obj = $this->curl_get($url); $data = json_decode($obj, true); return $data; } ~~~