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

pub" />

国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁(yè) > 營(yíng)銷資訊 > 網(wǎng)站運(yùn)營(yíng) > 關(guān)于微信網(wǎng)頁(yè)授權(quán)

關(guān)于微信網(wǎng)頁(yè)授權(quán)

時(shí)間:2023-05-23 12:33:02 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)

時(shí)間:2023-05-23 12:33:02 來(lái)源:網(wǎng)站運(yùn)營(yíng)

關(guān)于微信網(wǎng)頁(yè)授權(quán):我自己親測(cè)可行 下面貼代碼,希望能給需要幫助的人以幫助

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沒(méi)有相應(yīng)';
}

}
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);
}
}

關(guān)鍵詞:授權(quán)

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點(diǎn)擊下載Chrome瀏覽器
關(guān)閉