zoukankan      html  css  js  c++  java
  • 微信网页授权获取用户基本信息

    微信开发文档:http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html

    首先引导用户去授权页面:
    地址:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appid&redirect_uri=redirect_uri&response_type=code&scope=SCOPE&state=STATE#wechat_redirect";
    用户同意授权后,页面将跳转至 redirect_uri/?code=CODE&state=STATE

    1.//通过code换取token  
     2.$code = $_GET['code'];  
     3.$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=appid&secret=SECRET&code=$code&grant_type=authorization_code";  
     4.$json = file_get_contents($url);  
     5.$arr = json_decode($json,true);  
     6.$token = $arr['access_token'];  
     7.$openid = $arr['openid'];  
     8.//拿到token后就可以获取用户基本信息了  
     9.$url = "https://api.weixin.qq.com/sns/userinfo?access_token=$token&openid=$openid ";  
     10.$json = file_get_contents($url);//获取微信用户基本信息  
     11.$arr = json_decode($json,true);  
     12.$name = $arr['nickname'];//昵称  
     13.$imgURL = $arr['headimgurl'];//头像地址  
     14.$sex = $arr['sex'];//性别  
     15.$province = $arr['province'];//用户个人资料填写的省份  
     16.$city= $arr['city'];//普通用户个人资料填写的城市  
     17.$country= $arr['country'];//国家,如中国为CN  
    学如逆水行舟,不进则退。
  • 相关阅读:
    http 学习 1-1 chapter1-HTTP概述
    2048 游戏实现原理
    safari 日期对象新建new Date( timeStr ) 参数TimeStr格式
    js
    js 常见弹出框学习
    JS引入CSS文件
    JAVA 遍历文件夹下的所有文件(递归调用和非递归调用)
    java复制文件 转
    Map键值对,一种思路
    写入excel表格数据
  • 原文地址:https://www.cnblogs.com/dhsx/p/5000696.html
Copyright © 2011-2022 走看看