Closed zhouzhongyuan closed 7 years ago
自定义菜单
{
"menu": {
"button": [
{
"type": "view",
"name": "芝麻开门吧",
"url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx739b9f74ab475e99redirect_uri=http%3A%2F%2F192.168.1.106%2F%23%2Fhome%2FReceiptViewresponse_type=codescope=snsapi_userinfostate=STATEconnect_redirect=1#wechat_redirect",
"sub_button": [ ]
},
{
"name": "菜单",
"sub_button": [
{
"type": "view",
"name": "中原",
"url": "http://blog.zhouzhongyuan.com/",
"sub_button": [ ]
},
{
"type": "view",
"name": "视频",
"url": "http://v.qq.com/",
"sub_button": [ ]
},
{
"type": "click",
"name": "赞一下我们",
"key": "V1001_GOOD",
"sub_button": [ ]
}
]
}
]
}
}
现在的自定义菜单
{
"button": [
{
"type": "view",
"name": "芝麻开门吧Alibaba",
"url": "http://wechat.zhouzhongyuan.com/map",
"sub_button": [ ]
}
]
}
自动回复 接收消息
router.post('/', function (req, res, next) {
res.writeHead(200, {'Content-Type': 'application/xml'});
var data = req.body.xml;
var resMsg = '<xml>' +
'<ToUserName><![CDATA[' + data.fromusername + ']]></ToUserName>' +
'<FromUserName><![CDATA[' + data.tousername + ']]></FromUserName>' +
'<CreateTime>' + parseInt(new Date().valueOf() / 1000) + '</CreateTime>' +
'<MsgType><![CDATA[text]]></MsgType>' +
'<Content><![CDATA['+data.content+']]></Content>' +
'</xml>';
console.log(resMsg);
res.end(resMsg);
});
需要body-parser-xml:
//解析xml
var bodyParser = require('body-parser');
require('body-parser-xml')(bodyParser);
app.use(bodyParser.xml({
limit: '1MB', // Reject payload bigger than 1 MB
xmlParseOptions: {
normalize: true, // Trim whitespace inside text nodes
normalizeTags: true, // Transform tags to lowercase
explicitArray: false // Only put nodes in array if >1
}
}));
基础支持: 多媒体文件上传接口 /media/upload 请求地址: http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=4Y7cMJ8Nm6dkQRxhkvhAJ9pcYggn6nsUYQFnjOvyuOhvwFHu--poLlLYEHmGPfFLN8shyjiCepHAbbnrLcz2_9VMJZ6iWgF-nAmeKXXzsoZ7hsbco6g3UhIXqogIqJWlTYEaABAJOU&type=image 返回结果:
{
"type": "image",
"media_id": "z36yLDpsYmZLgF8SEFDgrL9GXdl3ZRR_4tHLcibosGYD7AE3c7EXLIgY7K9-Jtym",
"created_at": 1486522605
}
这是一张黄图
多媒体文件有大小限制。
Allegro fro
google drive intro xOmvljHGmtue37scDoNXCMHi4GGOW8_HrLAXf1D9juEClsbKDplYacde2zh_ZCMY
图片(image): 1M,支持JPG格式 语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式 视频(video):10MB,支持MP4格式 缩略图(thumb):64KB,支持JPG格式 媒体文件在后台保存时间为3天,即3天后media_id失效。
Invalid Signature
微信配置页面的安全域名应该是这样子的
测试账号地址
开发者工具
在线调试工具
如何获取ACCESS_TOKEN ?
http://jezhang.ngrok.cc/token