PHP微信授权登录用于多个域名的方法

PHP微信授权登录用于多个域名的方法
appid和 回调地址换下就好了

<pre>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
<title>微信授权</title>
</head>
<body>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script>
var appid = 'wxbcaea9c853066c75'; // 公众号ID
var shouquandizhi='*********'; //授权地址
var callbackurl; // 公众号ID


$(function(){
var Request=GetRequest();
var code=Request['code'];
var play_id=Request['play_id'];
callbackurl = shouquandizhi+'?play_id='+play_id;
if (typeof(code)=="undefined" || code=='' || code==null){
oauth2();
}else{
//授权登录后 url后缀自带code
window.location.href='****最终要跳转的地址********?code='+code;
}
})

function oauth2() {
var oauth2Url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="
+ appid
+ "&redirect_uri="
+ encodeURIComponent(callbackurl)
+ "&response_type=code&scope=snsapi_userinfo#wechat_redirect";
window.location.href = oauth2Url;
}
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
var strs = str.split("&");
for ( var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
</script>
</body>
</html>
</pre>

PHP收到code 然后处理获取用户信息即可

猜你喜欢

转载自www.cnblogs.com/newmiracle/p/11856418.html
今日推荐