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

  • 相关阅读:
    c语言,浮点数转byte array
    go的select 只会执行一个case,就会退出select 块
    【转】pphp中goto的用法
    [转]php 中yield是个什么东西
    z-index 0 和auto的区别,这个例子好好琢磨一下
    SpringMVC框架下实现原生分页功能
    Jackson 高级应用
    Jackson 的 基本用法
    Jackson转换为Collection、Array
    spring处理数据库中Date类型字段转换成时间戳问题
  • 原文地址:https://www.cnblogs.com/newmiracle/p/11856418.html
Copyright © 2011-2022 走看看