• 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 然后处理获取用户信息即可

  • 相关阅读:
    React组件的生命周期
    机器人api
    智能机器人
    已复制该虚拟机 之后需要的处理工作
    在虚拟机上安装CentOS6.5(minimal)
    fastdfs
    redis安装
    FtpClient上传文件异常:java.net.SocketException: Connection reset
    redis的学习笔记
    git命令2
  • 原文地址:https://www.cnblogs.com/newmiracle/p/11856418.html
Copyright © 2020-2023  润新知