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

推荐订阅源

G
GRAHAM CLULEY
T
Tenable Blog
Know Your Adversary
Know Your Adversary
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Privacy International News Feed
S
Security Affairs
NISL@THU
NISL@THU
O
OpenAI News
Attack and Defense Labs
Attack and Defense Labs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Schneier on Security
Schneier on Security
S
SegmentFault 最新的问题
S
Schneier on Security
G
Google Developers Blog
V
V2EX
C
Check Point Blog
U
Unit 42
Google DeepMind News
Google DeepMind News
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
S
Secure Thoughts
博客园 - 司徒正美
Recorded Future
Recorded Future
P
Proofpoint News Feed
Spread Privacy
Spread Privacy
K
Kaspersky official blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
AI
AI
博客园 - 聂微东
N
News and Events Feed by Topic
SecWiki News
SecWiki News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Vulnerabilities – Threatpost
P
Palo Alto Networks Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
Recent Commits to openclaw:main
Recent Commits to openclaw:main
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
The Hacker News
The Hacker News
The Last Watchdog
The Last Watchdog
Project Zero
Project Zero
W
WeLiveSecurity
博客园 - Franky

轶哥博客

blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog
blog
2018-09-02 · via 轶哥博客

数天前,为解决微信二维码扫码登陆在Electorn跳转处理繁琐的问题,写一个微信开放平台扫码登陆解析处理工具😊,将frame数据处理为图片或Base64图片数据返回客户端进行扫码。解决Chrome70中open.weixin.qq.com腾讯SSL证书不被信任的问题(微信官方于2018年8月23日更换了域名证书),解决Chrome68中frame跨域被拦截的问题。

此方案最大特点扫码登录无跳转🤠。

Node.js 版本 Demohttps://weixin.openapi.site/demo

PHP 版本 Demohttps://apio.xyz/weixin-login-php/

须知

  此方案仅适用于微信开放平台-网站应用

Node.js版本为什么不封为NPM库?   这个功能的代码比较简单,https和URL库都是nodejs自带的,直接复制过去用就好了。

Node.js版本使用方法

请阅读WeixinLoginClientHandler.js文件。 第一步:获取微信UUID; 第二步:根据微信UUID获取二维码图片; 第三步:获取微信服务器返回的Code(详见微信开放平台文档)。

测试方法

在线测试

直接请求https://weixin.openapi.site/img?appid=您的appid&redirect_uri=您在微信开放平台后台设置的授权回调域,获取二维码和UUID。

再次请求https://weixin.openapi.site/check?uuid=上一步得到的UUID,获得登录结果的数据。

您要是懒得部署一套,可以直接使用以上地址。

本地测试

先阅读源码,修改server.js里面的配置信息,使用npm start启动项目。

访问http://localhost:65533/login/weixin/demo即可进行测试。

API

weixinLoginClientHandler.weixinUUID().then(r => console.log(r)) \\ 获取微信uuid(用于获取微信二维码和Ajax轮询结果所需参数)

weixinLoginClientHandler.weixinQRCodeImgURL().then(r => console.log(r)) \\ 可以直接获取二维码图片

weixinLoginClientHandler.weixinQRCodeImgBase64().then(r => console.log(r)) \\ 获取二维码图片的Base64数据(主要用于Chrome70中腾讯所使用的赛门铁克证书失效的情况)

weixinLoginClientHandler.getCode(uuid, params.last).then(r => console.log(r)) \\ 获取微信服务器返回的Code(第一个连接是长连接,当用户处于“扫描成功,请在微信中点击确认即可登录”状态时可能会变为轮询,这主要由腾讯服务器控制)

Example

import WeixinLoginClientHandler from './WeixinLoginClientHandler.js'

const weixinLoginClientHandler = new WeixinLoginClientHandler({
  appid: 'wx827225356b689e24',
  redirect_uri: 'https://qq.jd.com/',
  state: ''
})

weixinLoginClientHandler.weixinUUID().then(r => {
  console.log(r)
  weixinLoginClientHandler.weixinQRCodeImgBase64(r).then(r => console.log(r))
})

weixinLoginClientHandler.weixinQRCodeImgURL().then(r => console.log(r))

PHP版本使用方法

第一步:根据Appid及授权回调域获取二维码图片和微信UUID; 第二步:获取微信服务器返回的Code(详见微信开放平台文档)。

测试方法

直接请求https://apio.xyz/weixin-login-php/weixin.php?appid=您的appid&redirect_uri=您在微信开放平台后台设置的授权回调域,获取二维码和UUID。

再次请求https://apio.xyz/weixin-login-php/weixin.php?uuid=上一步得到的UUID,获得登录结果的数据。

您要是懒得部署一套,可以直接使用以上地址。

小提示

  1. 这个方案可能只适合少部分应用。
  2. 使用此方法,无需经由服务器端跳转,可以直接获得code。如果是Electron环境,可以直接在渲染进程请求。
  3. 建议为该功能单独部署,可在您所有项目中使用同一个接口。PHP版本方便部署到虚拟主机等免维护环境,简单方便。
  4. 该文件使用原生Node.js方法,ES6写法,type=module。
  5. 理论上你可以模拟任何网站的二维码,但是没有私钥就算拿到code也没有用。

源码

Node.js:https://github.com/yi-ge/weixin-login

PHP:https://github.com/yi-ge/weixin-login-php