微信PC端末のウェブページのスキャンコードは登録します
2049 ワード
redirect_uri ,
//
$(document).ready(function()
{
var obj = new WxLogin({
self_redirect:true,
id:"login_container",//div id
appid: "wx261b47711837b0b6",// appid
scope: "snsapi_login",//
redirect_uri: encodeURI("http://new8.dianziqingtie.com/login_success/wx_login"),
state: "1",
style: "black",//
href: ""
});
});
public function wx_loginAction(){
$code = $this->common->Get("code");
$user = new userModel();
$data = $user->getWxaccesstokenBycode($code);
$_SESSION['openid'] = $data['openid'];
}
appid、secret url code access_token openid
openid
access_token openid
public function getWxaccesstokenBycode($code){
$appid=$GLOBALS['config_account']['WX_APPID'];
$secret=$GLOBALS['config_account']['WX_SECRET'];
// access_token openid
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$secret}&code={$code}&grant_type=authorization_code";
$redata =json_decode($this->common->get_webHtml($url),true) ;
/* $_SESSION['redata']=$redata;*/
if($redata["access_token"]!="" && $redata["access_token"]!=null){
$access_token= $redata["access_token"];
$openaid= $redata["openid"];
$reuserdata = json_decode($this->common->
get_webHtml("https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$openid}&lang=zh_CN"),true);
return $reuserdata;
}else{
return false;
}
}