Git Product home page Git Product logo

suizifish / codetoany Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 7 KB

从微信公众号接口“网页授权获取用户信息”中获取get参数code后,再将其通过get方式跳转传递给任何域名下的url。解决了在微信公众平台只能设置一个“网页授权回调页面域名”造成的不能将get参数code传递给其他多个域名的问题。

Home Page: http://lionsay.com/codetoany.html

PHP 100.00%

codetoany's Introduction

codetoany

从微信公众号接口“网页授权获取用户信息”中获取get参数code后,再将其通过get方式跳转传递给任何域名下的url。解决了在微信公众平台只能设置一个“网页授权回调页面域名”造成的不能将get参数code传递给其他多个域名的问题。

环境需求

  • php >= 5.4.0;

快速使用

  1. 假设将微信公众平台中“网页授权回调页面域名”设置为www.example.com
  2. 打开codetoany/getcodetourl.php,将变量$appId的值改成自己的微信公众号id
  3. 将codetoany中的所有文件部署到http://www.example.com/codetoany/
  4. 微信内或使用微信web开发者工具访问http://www.example.com/codetoany/getcodetourl.php?rk=lionsay。顺利的话,页面将跳转到类似这样的url:http://lionsay.com/?a=123&b=test&code=0318PVx00bTFzB1JOny00YMRx008PVxS&state=STATE。这样就实现了将get参数code传递给了自定义设置的urlhttp://lionsay.com/?a=123&b=test

深度理解

  1. 跳转url:在codetoany/getcodetourl.php中,变量$redirectUrl就是跳转url的配置,是一维数组,元素的键作为get参数rk的值,元素的值即为具体的跳转url,get参数code将附加到该url中进行跳转。具体跳转到哪一个url由其对应的键决定,而该键将从get参数rk中获取。可以设置一个或多个元素;
  2. 特殊get参数
    • rk:rk值的作用是确定具体跳转的url。可以自定义rk这个名称,在codetoany/getcodetourl.php中调用类方法\lion\weixin\library::getCodeToUrl()时,为其第二个参数传递一个字符串,这个参数的默认值为rk
    • scopestate:微信公众号接口“网页授权获取用户信息”中的参数scope和state可以作为get参数传递给codetoany/getcodetourl.php,进而再传递给该接口。get参数scope的默认值为snsapi_baseget参数state的默认值为STATE。参数的含义请参考微信公众平台开发者文档
    • __lion_from_weixin=yes:如果不跳转或跳转不合法,url中就会出现此参数,这是程序内部使用的,用户无需关心;
  3. get参数的保持和覆盖:除了get参数rk外,传递给codetoany/getcodetourl.php的任何get参数都将继续传递给跳转url。当传递给codetoany/getcodetourl.php的get参数与跳转url中的get参数有同名参数时,可以选择是否覆盖,在codetoany/getcodetourl.php中调用类方法\lion\weixin\library::getCodeToUrl()时,为其第三个参数传递一个布尔值,这个参数的默认值为false即不覆盖,但无论如何这三个get参数code、scope和state总是强制覆盖;
  4. https:如果微信公众平台“网页授权回调页面域名”使用https方式访问,在codetoany/getcodetourl.php中实例化类\lion\weixin\library\Authorize时,请务必为其构造函数的第二个参数传递布尔值true,这个参数的默认值为false即不使用https

问题反馈

codetoany's People

Contributors

lionskys avatar

Watchers

James Cloos avatar cleave avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.