鍍金池/ 問答/PHP  HTML/ 微信掃碼登陸是用公司申請的服務號么?

微信掃碼登陸是用公司申請的服務號么?

開始登陸 login.php

//-------配置
$AppID = 'wx033336c794d4';
$AppSecret = 'd4624c隱藏37af5443d';
$callback = 'http://www.erdangjiade.com/php'; //回調(diào)地址

//微信登錄 login.php

session_start();
//-------生成唯一隨機串防CSRF攻擊
$state = md5(uniqid(rand(), TRUE));
$_SESSION["wx_state"] = $state; //存到SESSION
$callback = urlencode($this->callback);
$wxurl = "https://open.weixin.qq.com/connect/qrconnect?appid=".$AppID."&redirect_uri={$callback}&response_type=code&scope=snsapi_login&state={$state}#wechat_redirect";
header("Location: $wxurl");

回調(diào)地址 callback.php

//驗證CSRF攻擊

if($GET['state']!=$SESSION["wx_state"]){
exit("5001");
}
$AppID = 'wx33333333334d4';
$AppSecret = 'd4624c363333330547af5443d';
$url='https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$AppID.'&secret='.$AppSecret.'&code='.$_GET['code'].'&grant_type=authorization_code';

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$json = curl_exec($ch);
curl_close($ch);

$arr=json_decode($json,1);

//得到 access_token 與 openid
print_r($arr);

$url='https://api.weixin.qq.com/sns/userinfo?access_token='.$arr['access_token'].'&openid='.$arr['openid'].'&lang=zh_CN';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$json = curl_exec($ch);
curl_close($ch);
$arr=json_decode($json,1);

得到 用戶資料
print_r($arr);
感覺不對呀,不知道哪里有問題了?

回答
編輯回答
情未了

出了什么問題?有什么提示?

2017年12月10日 09:29
編輯回答
黑與白

要微信開放平臺賬號!具體步驟在微信開放平臺官網(wǎng)都寫的非常詳細!

2017年8月31日 11:38