惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
D
Docker
Vercel News
Vercel News
IT之家
IT之家
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
I
InfoQ
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - Franky
The Cloudflare Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
T
Tenable Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Security Latest
Security Latest
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
F
Full Disclosure
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
Project Zero
Project Zero

博客园 - 晴窗笔记

javascript的严格模式:use strict Ionic在线打包IOS平台应用 安装nodejs6.9x以后,原来在nodejs4.2.x中运行正常的ionic项目出现问题的解决 cordova插件分类 ionic 启用sass ngCordova 为Asp.net WebApi 添加跨域支持 使用ionic framework创建一个简单的APP 研究主题 近两天让我羞愧难当的遭遇 cordova环境配置 正则表达式基础 2016年读书计划 红皇后假说 2016年碎语 Apache + PHP 环境搭建 各种环境配置 技术名词记 使用新浪云(SAE)实现基于mySql和微信公众平台的关键字请求响应服务
微信OAuth2.0网页授权
晴窗笔记 · 2016-04-15 · via 博客园 - 晴窗笔记

    这是一个实用且通用的功能,说通俗点就是用微信帐号登录第三方网站,经用户确认后,允许网站获取用户基本资料。

    技术资料参见微信官方文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842&token=&lang=zh_CN

    1、实现这一功能需要先设置授权回调页面域名,如下图:

2、主要代码(只获取用户信息,登录网站部分略)

<?php
if(isset($_GET['code'])){
    $code = $_GET['code'];
    $userInfo = getUserInfo($code);
    echo $userInfo;
}
else{
    echo "Error!";
}

function getUserInfo($code){
    $appid = "wx04d2578db7e1b736";
    $appsecret = "43b9557d223737d01ababb39a4b4b14d";
    $accessToken = "";
    
    //根据code获取token
    $tokenURL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$appsecret&code=$code&grant_type=authorization_code";
    $tokenJson = https_request($tokenURL);
    $tokenArray = json_decode($tokenJson,true);
    $accssToken = $tokenArray['access_token'];
    $openid = $tokenArray['openid'];
    
    
    //拉取用户信息
    $userInfoURL = "https://api.weixin.qq.com/sns/userinfo?access_token=$accssToken&openid=$openid";
    $userInfoJson = https_request($userInfoURL);
    $userInfoArray = json_decode($userInfoJson,true);
        
    return $userInfoJson;
}

function https_request($url){
    
    //return $url;
    $curl = curl_init();
    curl_setopt($curl,CURLOPT_URL,$url);
    curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
    curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
    $data = curl_exec($curl);
    if(curl_errno($curl)){
        return 'ERROR'.curl_error($curl);
    }
    curl_close($curl);
    return $data;
}
?>

3,最后按以下格式访问,获得用户信息

https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx04d2578db7e1b736&redirect_uri=http://essays.duapp.com/getUserInfo.php&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect

返回信息大致如下(未经处理)

{
    "openid": "owThxwlQQV8WQynaTZmMI6yi29-s",
    "nickname": "自由行走",
    "sex": 1,
    "language": "zh_CN",
    "city": "Kunming",
    "province": "Yunnan",
    "country": "CN",
    "headimgurl": "http://wx.qlogo.cn/mmopen/eGrUpN8dpomatpwS0VrRIh6n9deJACV9S9F8vqxjmxicd0Gt5QLl0BNC4zeKSoS24umarmibP7rzf1obOJibVvG9d8icK7cjibTiaE/0",
    "privilege": [ ]
}