zoukankan      html  css  js  c++  java
  • 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 然后处理获取用户信息即可

  • 相关阅读:
    Linux系统下安装rz/sz命令及使用说明
    Linux 下Beanstalk安装
    Jetty中间件
    JBOSS应用中间件
    IBM 存储高可用HA解决方案和DR连续性解决方案
    Nginx负载均衡与反向代理的配置和优化
    NFS挂载网络存储
    使用集中式身份管理服务详解
    配置链路聚合(端口聚合)
    配置ssh远程访问策略
  • 原文地址:https://www.cnblogs.com/newmiracle/p/11856418.html
Copyright © 2011-2022 走看看