15158846557 在线咨询 在线咨询
15158846557 在线咨询
所在位置: 首页 > 营销资讯 > 网站运营 > 关于微信网页授权

关于微信网页授权

时间:2023-05-23 12:33:02 | 来源:网站运营

时间:2023-05-23 12:33:02 来源:网站运营

关于微信网页授权:我自己亲测可行 下面贴代码,希望能给需要帮助的人以帮助

class WeixinController extends Controller{
public $appId = 'wx...';
public $appSecret = 'f3....';

public function getaccesstoken()
{
$js_code = $_GET['code'];
if($js_code){
//dump($js_code);
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$this->appId&secret=$this->appSecret&code=$js_code&grant_type=authorization_code";
//dump($url);
$res = WeixinController::getJson($url);

$openid = $res['openid'];
$access_token = $res['access_token'];
$url1 = "https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid&lang=zh_CN ";
$date = WeixinController::getJson($url1);
//dump($date);die;
$_SESSION['headImgUrl'] = $date['headimgurl'];
$_SESSION['nickName'] = $date['nickname'];
dump($_SESSION['headImgUrl']);
if(session('headImgUrl')){
$this->redirect('Login/login');
}

}else{
echo 'code没有相应';
}

}
public static function getJson($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output, true);
}
}

关键词:授权

74
73
25
news

版权所有© 亿企邦 1997-2025 保留一切法律许可权利。

为了最佳展示效果,本站不支持IE9及以下版本的浏览器,建议您使用谷歌Chrome浏览器。 点击下载Chrome浏览器
关闭