node-webot / wechat Goto Github PK
View Code? Open in Web Editor NEW微信公共平台消息接口服务中间件
License: Other
微信公共平台消息接口服务中间件
License: Other
当前access_token存在内存中。
意思是在生产环境下也必须安装 connnect ?
那 package.json 里面的 dependencies 就没写对啊。
it didn't work.
npm install wechat
reported "shasum check failed for wechat-0.8.0.tgz"
Expected: 8504e98ceab33823321b52f74f206124bf8d43c4
Actual: 1f577417ef8d6f7ec43552dbcb68d73d2e05f1d8
譬如给用户下发一个列表,由用户回复列表中的选项,类似于运营商的业务短信那样,可否由你的组件代劳实现个大体框架?
RequestError: connect ECONNREFUSED,
把请求的url使用浏览器访问是正常的
Oauth中,获取用户信息时,缺少语言lang的参数。
https://github.com/node-webot/wechat/blob/master/lib/wechat.js#L30 之后几个除了description
之外。既然这些输入都是我们手动指定的,不存在外部输入的问题,为何需要强制escape?这样如果url
里有&
符号都会被强制转义。
感觉这个转义条件应该是开发者自己决定的吧。
Sorry I close the issue by mistake.
The following code based on the sample in readme ends immediately without error message. Please help.
// code starts
var express = require('express')
var connect = require('connect')
var app = express();
var wechat = require('wechat');
app.use(connect.query()); // Or app.use(express.query());
app.use('/wechat', wechat('albert', function (req, res, next) {
// 微信输入信息都在req.weixin上
var message = req.weixin;
if (message.MsgType = 'text') res.reply('Testing. Please ignore');
}));
var data = {
"touser": openid,
"msgtype":"voice",
"image": {
"media_id": mediaId
}
};
应该是voice
我只想获取前一万名用户,如果使用
api.getFollowers(callback);
api.getFollowers('', callback);
但是getFollowers总是回复{ [WeChatAPIError: invalid openid] name: 'WeChatAPIError' }
而且有时还会报错说callback里面的res没有定义
API.prototype.preRequest方法139行
如果从全局获取到的access_token为空,则应该想微信api发起请求.目前逻辑不是这样做的
在 @atian25 的大力推广下, weixin-robot
模块有了一定的用户量,
也很高兴看到你的中间件关注人数也越来越多。
目前看来,两边做的事情有大部分都是相似的,不同的地方则可以互补。
之前看到你也给 weixin-robot 发过 PR ,不知为何后来还是决定自己写一个呢?
如果觉得代码不符合自己习惯,可以发 PR 来重构嘛,比如 @atian25 就基本把我之前
写的 0.0.x 版本完全重写了。而现在我又删了他很多代码。
如果觉得项目不在自己名下,无法掌控,可以建一个组织来协作嘛。
weixin-robot
项目已经分拆成 weixin-robot、 webot-cli、webot-dashboard 三个项目。
计划中这是一整套公共平台API的解决方案,包括命令行工具和一个网页端的后台。
不希望看到更多重复造轮子的事,前端界已经够分裂了。
node 社区也不是没有这样的先例:
比如 node_mailer 就被合并到了 Nodemailer 。
connect.query, connect.cookieParser, connect.session ...... are no longer available.
调用getMedia网络连接超时,node抛出来异常了。
[2014-07-29 10:08:02.006] [ERROR] console - TypeError: Cannot read property 'headers' of undefined
at /home/hanscc/nodejs/wechat-service/node_modules/wechat/lib/common.js:958:26
at /home/hanscc/nodejs/wechat-service/node_modules/wechat/lib/util.js:9:14
at done (/home/hanscc/nodejs/wechat-service/node_modules/wechat/node_modules/urllib/lib/urllib.js:257:5)
at ClientRequest. (/home/hanscc/nodejs/wechat-service/node_modules/wechat/node_modules/urllib/lib/urllib.js:463:5)
at ClientRequest.emit (events.js:95:17)
at Socket.socketErrorListener (http.js:1547:9)
at Socket.emit (events.js:95:17)
at net.js:440:14
at process._tickDomainCallback (node.js:463:13)
在我的项目的package.json里:
"wechat": ">= 0.3.5"
执行npm install时报错:
npm ERR! Error: No compatible version found: bufferhelper@'>=0.2.0'
但是我看 bufferhelper 这个包已然是0.2.0版本的了。。。
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>12345678</CreateTime>
<MsgType><![CDATA[image]]></MsgType>
<Image>
<MediaId><![CDATA[media_id]]></MediaId>
</Image>
<FuncFlag>0</FuncFlag>
</xml>
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>12345678</CreateTime>
<MsgType><![CDATA[voice]]></MsgType>
<Voice>
<MediaId><![CDATA[media_id]]></MediaId>
</Voice>
<FuncFlag>0</FuncFlag>
</xml>
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>12345678</CreateTime>
<MsgType><![CDATA[video]]></MsgType>
<Video>
<MediaId><![CDATA[media_id]]></MediaId>
<ThumbMediaId><![CDATA[thumb_media_id]]></ThumbMediaId>
</Video>
<FuncFlag>0</FuncFlag>
</xml>
除了access_token的问题,还发现access_token实现方式有待商榷.
有2个服务,如果某个服务在access_token未过期时刷新access_token,则另一个进程将无法继续提供服务,直到上一次的access_token过期为止.
解决办法是在全局access_token模式下, 每次发起request时候重新从redis获取access_token.
Would you consider translating the documentation to English?
I can't read Chinese but am in need of your library. ;)
谢谢
npm http GET https://registry.npmjs.org/wechat
npm http 304 https://registry.npmjs.org/wechat
npm http GET https://registry.npmjs.org/wechat/-/wechat-0.7.2.tgz
npm http 200 https://registry.npmjs.org/wechat/-/wechat-0.7.2.tgz
npm ERR! Error: shasum check failed for /var/folders/2m/jc7ycxx97qd6n1nd_xhg8y7r0000gn/T/npm-2041-p2FB497V/1404319660472-0.6132024084217846/tmp.tgz
npm ERR! Expected: a3e47bc8ce0c22a829e0b888a50f877e53ad3fb1
npm ERR! Actual: 8fc39577777eada28da294adaa0809a58653bb47
npm ERR! at /usr/local/lib/node_modules/npm/node_modules/sha/index.js:38:8
npm ERR! at ReadStream.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/sha/index.js:85:7)
npm ERR! at ReadStream.EventEmitter.emit (events.js:117:20)
npm ERR! at _stream_readable.js:920:16
npm ERR! at process._tickCallback (node.js:415:13)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! System Darwin 13.3.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "wechat"
npm ERR! cwd /Users/rocky/DEV/weixin
npm ERR! node -v v0.10.24
npm ERR! npm -v 1.3.21
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/rocky/DEV/weixin/npm-debug.log
npm ERR! not ok code 0
谢谢 :)
结果被'data'包起来了
console.log(result):
{ data:
{ access_token: 'OezXcEiiBSKSxW0eoylIeBjK8ITRYrk_JWfjtULHy5fpq4tnIrgI27BpD7psevpeUCC85evE8hR9KqrEfIg0TcgoVm3XT6HdabAxijfvBPo4uQPu_lMealUR1Kycd9YzwTf6BSR578O4xEwyLxvE0w',
expires_in: 7200,
refresh_token: 'OezXcEiiBSKSxW0eoylIeBjK8ITRYrk_JWfjtULHy5fpq4tnIrgI27BpD7psevpeoFH82IgRFDEGO2OkY3A8wsTkzGJcrus1hhJJfS5kWnCVcQTxl4ZbTn-8ngJSr-niJVzOjIUy2P5na6qoALwNtg',
openid: 'ow6lZuE3X5iCHO2UcCFFwx1qx-bo',
scope: 'snsapi_base',
create_at: 1409305069037 } }
I am new to everything. You are great to provide this module. I want to write a program to process messages sent from wechat users. I tried your sample (those with express/connect in readme) but the program terminates immediately without error message. What's wrong? Please help. Many thanks.
试了两个文件,一个3.1M,一个350KB左右。都是超时。文件读取正常。
{ [WeChatAPIConnectionTimeoutError: Request#2 timeout for 60000ms, POST http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=Eb0562_W9pFq4EY0IM5pHc-ybbeuA00DfBav48ZUGK0JFw4WC__HAZy8_okXJdEwJCQHClRn14ZTz2SiWxKUPf5bBHnZJLVqXLY-ZVuvY1Pz0pp4ZWX0ByA_IAJRQcYmdY64MjHhEdfh9aR88SDhiw&type=voice] name: 'WeChatAPIConnectionTimeoutError' }
服务器没有在大陆,但是反应速度也是可以的。
Explicit is better than implicit.
如果非文本消息都强制成
res.reply({
type: 'voice',
content: {
/// props...
}
})
我能理解,但为什么要对 music 特殊处理?因为比较常用?还是为了向后兼容?但其实现在并没有兼容 0.4.x 以下的写法:
res.reply({
type: 'music',
title: 'xxx',
musicurl: '',
thumb_media_id: ''
});
当我用你们给出的文档, 用app.use('/wechat', wechat.token('xxx') 实用时打开路径localhost/wechat时直接报404错误,
但我用app.get('/wechat', 时报401的invalid signature,
是我少设置了什么地方吗?
望帮忙, 谢谢:)
首先想跟作者说一声谢谢,Contribute 这些代码出来,非常感谢。
我并不是 JS 高手,所以没有了范例代码就完全没有了办法。按照 wechat 的源代码,我必须将 api.sendText() 和用到的参数弄进去 preRequest() 里面... Comment 里面说需要 “封装” 进去 preRequest(),而我是真的想破了头都不知道怎么在 JS 进行代码封装... 我在用 wechat 的时候,也遇到一些怪咖语法的问题。如:
wechat = require 'wechat'
api.use '/wechat', wechat api.locals.wechat_token, (req, res, next) ->
我的想法是,为什么不直接 api.sendText('Hello World') 呢?如果真的需要 preRequest(),为什么不采用 api.preRequest().sendText('') 的方式呢?Mongoose 也是采用这种方式,像我这些对编程不熟悉的人而言,wechat 的接口设计太难懂了。如果代码能够变成下面的方式的话,我觉得比较好理解...
wechat = require 'wechat'
api.use wechat('url','token')
wechat.receivedData = (data,req,res,next) ->
wechat.api.getUser data.FromUserName, (error, result) ->
console.log result
这是我的一些很幼稚的想法。见笑了。如果我的想法有问题的话,不知道可不可以请教一下怎么用 preRequest()。万分感谢。
The table of content collapsed with the content on a narrow browser window such as iPad. You may also reproduce the issue on PC by re-sizing the browser window.
准备升级到最新版本时候发现, d03e9dd 修改了getAccessToken的result, 增加了一层data, 是有意的吗? 不过注释部分没修改~
new result:
{
data:
{
"access_token": "ACCESS_TOKEN",
"expires_in": 7200,
"refresh_token": "REFRESH_TOKEN",
"openid": "OPENID",
"scope": "SCOPE"
}
}
old result:
{
"access_token": "ACCESS_TOKEN",
"expires_in": 7200,
"refresh_token": "REFRESH_TOKEN",
"openid": "OPENID",
"scope": "SCOPE"
}
我要上传一个文件夹的图片到微信服务器,遍历文件夹然后循环对每个文件进行uploadMedia操作,但是返回
{ errcode: 40001, errmsg: 'invalid credential' }
初步猜测是异步的问题,可能微信服务器对特定的access_token一次只能调用一次上传接口。现在不知如何解决。请问有什么方法?谢谢
能在自己的平台对某些关键字转发到其他第三方平台去处理!
/var/api/node_modules/wechat/lib/wechat.js:76
message[key] = (result.xml[key][0] || '').trim();
^
TypeError: Object # has no method 'trim'
at formatMessage (/var/api/node_modules/wechat/lib/wechat.js:76:47)
at respond (/var/api/node_modules/wechat/lib/wechat.js:85:21)
at exports.Parser.Parser.parseString (/var/api/node_modules/wechat/node_modules/xml2js/lib/xml2js.js:235:20)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
I have found that I cannot call the function checkSignature()
in lib/wechat
. Although I can write the checkSignature() in my code, it is better to export it for others to use. Thank you for such nice library.
还有个问题哈,生成出来的QRCode URL页面是空白的。代码如下
app.get('/qrcode', function(req, res) {
var codeType = req.query.codeType || 'temp';
var codeVal = req.query.codeVal || 1;
var codeExp = req.query.codeExp || 1800;
var response = function(err, data) {
if(err) console.log(err);
res.end( api.showQRCodeURL(data.ticket) );
};
if( codeType.toLowerCase() == 'temp' ) {
api.createTmpQRCode(codeVal, codeExp, response);
} else if( codeType.toLowerCase() == 'perm' ) {
api.createLimitQRCode(codeVal, response);
}
});
http://node-webot.github.io/wechat/api.html
侧边栏的索引是有效的,但是主体部分的区内索引是不能跳转的。
链接是:http://node-webot.github.io/wechat/api.html#_API
而目标元素是:
<h3 id="index_
API
" style="padding-top: 50px;">
API
</h3>
是不是doxmate里对索引处理有些问题?
//微信内置表情代码
module.exports = {
wx : '/::)', //微笑
pz : '/::~', //撇嘴
se : '/::B', //色
fd : '/::|', //发呆
dy : '/:8-)', //得意
ll : '/::<', //流泪
hx : '/::$', //害羞
bz : '/::X', //闭嘴
shui : '/::Z', //睡
dk : '/::\'(', //大哭
gg : '/::-|', //尴尬
fn : '/::@', //发怒
tp : '/::P', //调皮
cy : '/::D', //呲牙
jy : '/::O', //惊讶
ng : '/::(', //难过
kuk : '/::+', //酷
lengh : '/:--b', //冷汗
zk : '/::Q', //抓狂
tuu : '/::T', //吐
tx : '/:,@P', //偷笑
ka : '/:,@-D', //可爱
baiy : '/::d', //白眼
am : '/:,@o', //傲慢
jie : '/::g', //饥饿
kun : '/:|-)', //困
jk : '/::!', //惊恐
lh : '/::L', //流汗
hanx : '/::>', //憨笑
db : '/::,@', //大兵
fendou : '/:,@f', //奋斗
zhm : '/::-S', //咒骂
yiw : '/:?', //疑问
xu : '/:,@x', //嘘...
yun : '/:,@@', //晕
zhem : '/::8', //折磨
shuai : '/:,@!', //衰
kl : '/:!!!', //骷髅
qiao : '/:xx', //敲打
zj : '/:bye', //再见
ch : '/:wipe', //擦汗
kb : '/:dig', //抠鼻
gz : '/:handclap', //鼓掌
qd : '/:&-(', //糗大了
huaix : '/:B-)', //坏笑
zhh : '/:<@', //左哼哼
yhh : '/:@>', //右哼哼
hq : '/::-O', //哈欠
bs : '/:>-|', //鄙视
wq : '/:P-(', //委屈
kk : '/::\'|', //快哭了
yx : '/:X-)', //阴险
qq : '/::*', //亲亲
xia : '/:@x', //吓
kel : '/:8*', //可怜
cd : '/:pd', //菜刀
xig : '/:<W>', //西瓜
pj : '/:beer', //啤酒
lq : '/:basketb', //篮球
pp : '/:oo', //乒乓
kf : '/:coffee', //咖啡
fan : '/:eat', //饭
zt : '/:pig', //猪头
mg : '/:rose', //玫瑰
dx : '/:fade', //凋谢
sa : '/:showlove', //示爱
xin : '/:heart', //爱心
xs : '/:break', //心碎
dg : '/:cake', //蛋糕
shd : '/:li', //闪电
zhd : '/:bome', //炸弹
dao : '/:kn', //刀
zq : '/:footb', //足球
pch : '/:ladybug', //瓢虫
bb : '/:shit', //便便
yl : '/:moon', //月亮
ty : '/:sun', //太阳
lw : '/:gift', //礼物
yb : '/:hug', //拥抱
qiang : '/:strong', //强
ruo : '/:weak', //弱
ws : '/:share', //握手
shl : '/:v', //胜利
bq : '/:@)', //抱拳
gy : '/:jj', //勾引
qt : '/:@@', //拳头
cj : '/:bad', //差劲
aini : '/:lvu', //爱你
bu : '/:no', //NO
hd : '/:ok', //OK
aiq : '/:love', //爱情
fw : '/:<L>', //绯闻
tiao : '/:jump', //跳跳
fad : '/:shake', //发抖
oh : '/:<O>', //怄火
zhq : '/:circle', //转圈
kt : '/:kotow', //磕头
ht : '/:turn', //回头
tsh : '/:skip', //跳绳
hsh : '/:oY', //挥手
kaixin : String.fromCharCode(58389), //开心
kouzhao : String.fromCharCode(58380), //口罩
daxiao : String.fromCharCode(58386), //笑出泪来
tushe : String.fromCharCode(58377), //吐舌头
mengle : String.fromCharCode(58384), //懵了
jingya : String.fromCharCode(58381), //惊讶
guichu : String.fromCharCode(57607), //鬼怵
beishang : String.fromCharCode(58371), //悲伤
zhayan : String.fromCharCode(58373), //眨眼
qieyi : String.fromCharCode(58378), //惬意
qie : String.fromCharCode(58382), //切~
mogui : String.fromCharCode(57626), //魔鬼
youling : String.fromCharCode(57627), //幽灵
aixin : String.fromCharCode(58423), //爱心
heshi : String.fromCharCode(58397), //双手合十
jirou : String.fromCharCode(57676), //肌肉
qiandai : String.fromCharCode(57647), //钱袋
dangao : String.fromCharCode(58187), //蛋糕
qingzhu : String.fromCharCode(58130), //庆祝
liwu : String.fromCharCode(57618) //礼物
}
首先,我下载“api-doc-service”示例工程
在根目录下增加了config.js文件,内容如下:
var wechat = require('wechat');
module.exports={
secret:'myweixin',
url:'mongodb://localhost/WeixinManage',
domain:'http://www.aaa.cn',
token:function(callback){
var API = require('wechat').API;
var api = new API('11111111111', '22222222222222222222222222222');
return api.getAccessToken(callback);
}
};
同时,在微信公众平台,将认证信息修改如下:
URL: http://www.aaa.cn/wechat
Token : bbbbb
App.js去掉了不相关的部分,主要内容如下:
var app = connect();
app.set('port', process.env.PORT || 80);
app.use(connect.query());
app.use(connect.cookieParser());
app.use(connect.session({secret: config.secret}));
/下面这行代码一直没有进入呢?是引入token的方式有问题?/
app.use('/wechat', wechat(config.token, wechat.text(function (message, req, res) {
console.log(message);
})));
http.createServer(app).listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});
我在微信上输入的任何消息,都没有响应,控制台输出也没有反映,我主要怀疑是config.js在处理AccessToken有问题?
文档错误
用首页的例子,返回的中文全是乱码。
picurl 这个,导致 weixin-robot 0.4 升级后不可用了
so we could enable proxy?
If ok I can pull a request later.
我是一个node.js新手,我在使用您的等待回复功能时候遇到一个问题:
我依样画葫芦维护着一个List,但是这个List出现了下面两个情况
1、程序的List是在服务器启动时候访问一个url加载的,那么服务器奔溃后,无法自动从新加载List,我的代码: https://github.com/LiSheep/sam_wechat/blob/master/wechat/chat.js#L96
2、这个List是在数据库中维护的,因此可能在运行时改变它。
不知道您有没有什么方法能解决它,或者您在设计这个API的时候,是希望我们怎么使用呢?
Many thanks
添加工作流支持,能够像电话问答一样。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.