wx

command module
v0.0.0-...-a727cec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2023 License: BSD-2-Clause Imports: 11 Imported by: 0

README

wx

微信登录中继和AccessToken缓存

安装

二进制程序

请到release页选择适合的平台程序下载

Docker

docker pull syutingsong/wx:latest

从源码编译

go get -u github.com/syutingsong/wx

使用

启动参数

wx [Flags]

  Flags: 
       --version  Displays the program version string.
    -h --help  Displays help with available flag, subcommand, and positional value parameters.
    -d --domains  valid domains for l2 jump
    -a --apps  weixin appId:appSecret pairs
    -l --log-level  log level
    -b --bind  binding ip address default: [::]
    -p --port  binding port number default: 3001
    -c --color  force use color for log output

例子

作为微信登录中继,支持两个域名

wx -d example.com -d xts.so -b 127.0.0.1

同时作为微信登录中继和AccessToken缓存

wx -d example.com -a <appid>:<secret>

显示DEBUG级别的日志

wx -l debug

在docker中使用

参数和直接使用一样,但可能需要暴露端口

docker run -ti --rm -p 80:80 syutingsong/wx -d example.com -p 80

Web API

登录中继

用途

微信登录回调只能是公众号后台预留的URL地址,无法支持多环境多域名使用。 此登录中继服务可以实现登录回调的二传手:将本服务的URL预留在微信公众号后台,然后本服务可以将浏览器跳转到l2参数指定的URL上。

GET /login/l2
参数
name required describe
l2 二次跳转URL,必须为启动参数-d所指定的域名或其子域
code 微信公从号登录返回的code
state 微信公众号登录返回的state
... 其它参数

此登录中继会判断l2参数中的域名是否在白名单中,如果在的话,会将codestate及其它参数URL Encode追加在l2的末尾。

假设微信登录中继服务部署在foo.example.com下,微信登录跳转目标在bar.example.com下。

例子

浏览器来访:

https://example.com/login/l2?l2=https%3A%2F%2Fbar.example.com%2Fwechat%2Fcallback&code=a5472995f0ad2814851f18671830c068&state=abc

中继服务会返回:

HTTP/1.1 307 Temporary Redirect
Date: Mon, 24 Jun 2019 06:24:56 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 0
Location: https://bar.example.com/wechat/callback?code=a5472995f0ad2814851f18671830c068&state=abc

引导浏览器转向实际的服务。

AccessToken 缓存

GET /access_token
参数
name required describe
appid 公众号的AppID,此ID应已在-a启动参数中配置
force 此参数非空字符时,会无视Cache强制从微信服务器获取
返回
{
    "access_token": "22_1pQzga6gduIu11N84ph90GM5e9MEyUnUVXWmCrQO4-zgNbVCuS4pTiAtyoa4bz0EtotUeH98vj2pafKd00n51Ywgu5-4JH5ZXUZ5m78zXkajwDN-n-r9u3WeiBfWBrZPY663Q_W9QG9Cp1sMGKEeABATXR",
    "expires_in": 7118
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
web

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL