Coder Social home page Coder Social logo

wechat-token-proxy's Introduction

wechat-token-proxy

wechat-token-proxy 是一个获取微信 access_tokenticket 的服务。它能使调用微信公众号各接口的各个业务逻辑点共享 access_tokenticket ,避免产生冲突。

说到这个冲突,就得先了解微信的 access_token 。引用微信官方的描述:

access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token。开发者需要进行妥善保存。access_token的存储至少要保留512个字符空间。access_token的有效期目前为2个小时,需定时刷新,重复获取将导致上次获取的access_token失效。

如果第三方不使用中控服务器,而是选择各个业务逻辑点各自去刷新access_token,那么就可能会产生冲突,导致服务不稳定。

详见微信官网

微信限定每天只能调用2000次刷新access_token的接口。换言之,每次调用公众号接口时都刷新access_token的话,很有可能超出2000次/日的限制。

开发 wechat-token-proxy 的目的,是为了让众多的业务逻辑点能和谐调用微信公众号的接口,共享access_token,减少一个令业务服务不稳定的因素。

项目文件说明

文件名 功能简介
conf/wx_config.json 设置微信 app_id 和 app_secret
destinations/wx_flush_access_token.js 获取access_token
shipper.js 将access_token写到文件, 或读取access_token
refresher/wx_access_token.json 此文件保存access_token的值
schedule.js 定时执行wx_flush_access_token.js
app.js 通过http方式输出json格式的access_token
conf/access.json 设置允许访问此服务的 IP 或 域名

如何使用

由于使用了 express 框架,启动 wechat-token-proxy 只需要执行 app.js 文件。具体步骤如下:

  • clone 项目
git clone https://github.com/sggdv/wechat-token-proxy.git
  • 进入 wechat-token-proxy 文件夹,并安装依赖模块
cd wechat-token-proxy
npm install
  • 设置 conf/wx_config.jsonconf/access.json 两个文件。 wx_config.json 内容如下:
{
	"app_id": "微信公众号的AppID",
	"app_secret": "微信公众号的AppSecret"
}

access.json 内容如下:

{
	"ip": ["127.0.0.1"],
	"hostname": ["localhost"]
}
  • 启动项目
node app.js

License

MIT

wechat-token-proxy's People

Contributors

sggdv avatar kimckm avatar

Watchers

wensincai avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.