TNW-开启公众号开发者模式javascript
TNW: TypeScript(The) + Node.js(Next) + WeChat 微信公众号开发脚手架,支持 http 模块扩展、支持任何 Node.js 的服务端框架(Express、NestJS 等)vue
一、下载java
$ npm i tnw
复制代码
二、Express 示例git
三、Nest 示例github
一、下载项目并安装依赖typescript
$ git clone https://github.com/Javen205/TNW.git
或者
$ git clone https://gitee.com/Javen205/TNW.git
$ cd TNW
$ npm install
复制代码
二、编译并运行npm
$ npm run build
$ npm run dev
复制代码
三、完整示例api
// 亦能够读取配置文件
let apiConfig = new ApiConfig("Javen", "wx614c453e0d1dcd12", "19a02e4927d346484fc70327970457f9");
// 支持多公众号
ApiConfigKit.putApiConfig(apiConfig);
// 开启开发模式,方便调试
ApiConfigKit.devMode = true;
复制代码
特别说明安全
支持多公众号配置,如须要能够多实例化 ApiConfig
而后调用 ApiConfigKit.putApiConfig(apiConfig)
进行设置。bash
ApiConfig
参数说明
第一个参数:令牌 Token 能够任意填写
第二个参数:开发者ID appId
第三个参数:开发者密码 appScrect
第四个参数:是否开启加密 encryptMessage 默认值为 false
第五个参数:消息加解密密钥 encodingAesKey 非必须
设置多个公众号配置时默认使用第一个 ApiConfig
切换公众号配置能够调用 ApiConfigKit.setCurrentAppId(appId)
TNW 中验证签名的关键接口以下:
WeChat.checkSignature(signature, timestamp,nonce, echostr)
复制代码
Express 示例以下:
app.get('/msg', (req: any, res: any) => {
console.log('get query...', req.query);
let appId: string = req.query.appId;
if (appId) {
ApiConfigKit.setCurrentAppId(appId);
}
let signature = req.query.signature,//微信加密签名
timestamp = req.query.timestamp,//时间戳
nonce = req.query.nonce,//随机数
echostr = req.query.echostr;//随机字符串
res.send(WeChat.checkSignature(signature, timestamp,
nonce, echostr));
});
复制代码
Nest 示例以下:
@Get('/msg')
getMsg(@Req() request: Request, @Res() response: Response) {
let appId: string = request.query.appId;
if (appId) {
ApiConfigKit.setCurrentAppId(appId);
}
let signature = request.query.signature,//微信加密签名
timestamp = request.query.timestamp,//时间戳
nonce = request.query.nonce,//随机数
echostr = request.query.echostr;//随机字符串
response.send(WeChat.checkSignature(signature, timestamp,nonce, echostr));
}
复制代码
特别说明:
http/https://域名/msg
或者 http/https://域名/msg?appId=xxxxx
false
(上文提到的 ApiConfig
第四个参数)安全模式
推荐使用 FRP 目前Github Start 已超越 2.2w。若有更好的工具欢迎推荐(留言区见)
TNW
微信公众号开发脚手架:gitee.com/javen205/TN…IJPay
让支付触手可及:gitee.com/javen205/IJ…mica
工具集:gitee.com/596392912/m…Avue
一款基于 vue 可配置化的神奇框架:gitee.com/smallweigit…pig
宇宙最强微服务(架构师必备):gitee.com/log4j/pigSpringBlade
完整的线上解决方案(企业开发必备):gitee.com/smallc/Spri…