zoukankan      html  css  js  c++  java
  • 用户点击确认登录,自动跳转下面地址得到code

    PHP获取微信openid 简单教程

     WEB   2014年10月29日  10868浏览  6评论

    获取code

    https://open.weixin.qq.com/connect/oauth2/authorize?appid=这里是你的公众号的APPID&redirect_uri=http://www.xx.com/getcode&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect

    用户点击确认登录,自动跳转下面地址得到code

    http://www.xiaohuang.cc/post/437.html

    http://www.xx.com/getcode 这个是你自己的跳转地址

    http://www.xx.com/getcode?code=0064f7afef7af7b395147bfe8b51f7bf&state=123

    后面的这个 ?code=……123   是微信自动跳转添加的,不是你自己加的

    下面是PHP语言,写在getcode这个页面里

    1
    2
    3
    4
    5
    $code $_GET['code'];//获取code
    $weixin =  file_get_contents("https://api.weixin.qq.com/sns/oauth2/access_token?appid=这里是你的APPID&secret=这里是你的SECRET&code=".$code."&grant_type=authorization_code");//通过code换取网页授权access_token
    $jsondecode = json_decode($weixin); //对JSON格式的字符串进行编码
    $array = get_object_vars($jsondecode);//转换成数组
    $openid $array['openid'];//输出openid

    怎么样,是不是灰常的简单?!小皇研究了三四天整理出这么简单的方法

    别谢哥,谢国家!

    本文禁止转载!

  • 相关阅读:
    补码原理
    清风徐来,水波不兴
    月尾和周尾
    又一春又一季
    9.11
    晨光无限
    9.18
    心悠
    小事一桩
    一周岁啦
  • 原文地址:https://www.cnblogs.com/u0mo5/p/5015217.html
Copyright © 2011-2022 走看看