Comments (4)
首先,这东西(包括其他的api)是不能跨进程复用的。
其次,跨进程部署的时候,需要把accessToken放在数据库、文件、redis之类的共享的地方。
第三,如果你的前台和后台是2个独立的进程(即2个独立的,互不干扰的express工程),那么各自初始化自己的api就好了,无非他们对accessToken的读取和存储是一个位置就好。
from wechat-api.
我是第三种情况,在2个单独的进程汇总都使用如下代码初始化api
var api = new API(AppID, AppSecret, function (callback) {
// 传入一个获取全局token的方法
Weixin.findOne({'AppID':AppID},function(err,weixin){
callback(null, weixin.access_token);//weixin.access_token包含accessToken和expireTime两个字段。
});
}, function (token, callback) {
// 请将token存储到全局,跨进程、跨机器级别的全局,比如写到数据库、redis等
// 这样才能在cluster模式及多机情况下使用,以下为写入到文件的示例
Weixin.update({'AppID':AppID},{$set:{access_token:token}},function(err){
if (err) return callback(err);
});
});
from wechat-api.
Weixin的schema结构:
name:String,//微信名称
number:{type:String,index:{unique: true}},//微信号
AppID:{type:String,index:{unique: true}},
AppSecret:String,
access_token:{}
from wechat-api.
问题找到了
Weixin.update({'AppID':AppID},{$set:{access_token:token}},function(err){
if (err) return callback(err);
这里没有将token回传,加上callback(token);就正常了
});
from wechat-api.
Related Issues (20)
- WeChatAPIJSONResponseFormatError
- 无限重复的post请求 HOT 2
- 什么时候能支持发送【小程序】图文链接? HOT 2
- lib/api_metrial.js HOT 1
- 上传永久素材
- 永久二维码现在支持字符串形式了 希望更新 HOT 1
- getMaterial 接口返回Buffer HOT 1
- WeChatAPIError: 40001
- 40001错误 HOT 1
- Error code: 48001, message: api unauthorized HOT 2
- 如何把 getMaterial 返回的 Buffer 保存为文件? HOT 2
- 上传多媒体的接口貌似不通了, 望你们测试一下 HOT 1
- Error code: 48001: unauthorized api in wechat shop HOT 1
- 希望可以支持下typescript HOT 1
- domain doxmate.cool is expired HOT 4
- 获取二维码地址后,上传到临时素材报错,望指导。 HOT 1
- api文档错误 HOT 1
- 支持MAC和IPAD协议新微信号接入,做机器人,营销系统,客服系统,监管系统的可以看下这个API :http://www.bbaos.com/docs/index HOT 1
- 找不到 doxmate.cool 的服务器 IP 地址。 HOT 1
- 需要最新iPAD协议联系(v:ixiaohe_) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wechat-api.