wechat open platform message crypt solution for nodejs
npm install wxbizmsgcryptbash
npm install wxbizmsgcrypt --save
`
+ 消息体加密
`javascript
var WxBizMsgCrypt = require('wxbizmsgcrypt').WxBizMsgCrypt;
var wxbizmsgcrypt = new WxBizMsgCrypt(token,encodingAesKey,appId);
console.log(wxbizmsgcrypt.encryptMsg('待加密文本','时间戳','随机字符串'));
`
+ 消息体解密(由于使用的xml2js库来解析XML文档,而xml2js解码时使用了回调函数,故本程序在解码XML时使用了Promise包装)
`javascript
var WxBizMsgCrypt = require('wxbizmsgcrypt').WxBizMsgCrypt;
var wxbizmsgcrypt = new WxBizMsgCrypt(token,encodingAesKey,appId);
wxbizmsgcrypt.decryptMsg('msg_signature','时间戳','随机字符串','加密的XML').then(function(xml) {
console.log(xml);
});
`使用方法[TS]
+ 消息体加密
`typescript
import {WxBizMsgCrypt} from 'wxbizmsgcrypt';
const wxbizmsgcrypt = new WxBizMsgCrypt(token,encodingAesKey,appId);
console.log(wxbizmsgcrypt.encryptMsg('待加密文本','时间戳','随机字符串'));
`
+ 消息体解密
`typescript
import {WxBizMsgCrypt} from 'wxbizmsgcrypt';
const wxbizmsgcrypt = new WxBizMsgCrypt(token,encodingAesKey,appId);
wxbizmsgcrypt.decryptMsg('msg_signature','时间戳','随机字符串','加密的XML').then(function(xml) {
console.log(xml);
});``