@xqijia/weixin
v0.0.41
Published
Node.js library for the Weixin MP API
Downloads
94
Maintainers
Readme
WeChat Node.js Library
微信公众号&小程序开发Node.js接口,方便内部使用,功能逐步增加中。
使用方法
- 微信公众号
import { WeixinApi, Configuration } from '@xqijia/weixin'
// type ApiType = 'weapp' | 'offiaccount' | 'thirdparty' | 'webapp'
const configuration = new Configuration({
appID: 'appID',
appSecret: 'appSecret',
apiType: 'offiaccount' // 默认为'offiaccount'
})
const api = new WeixinApi(configuration)
// 验证微信服务器配置
await api.verifySignatureFromWechat('signature', 'timestamp', 'nonce')
// 获取Access Token
await api.createAccessToken()
...
- 微信小程序
import { WeappAPI, Configuration } from '@xqijia/weixin'
// type ApiType = 'weapp' | 'offiaccount' | 'thirdparty' | 'webapp'
const configuration = new Configuration({
apiType: 'weapp',
appID: 'appID',
appSecret: 'appSecret'
})
const api = new WeappAPI(configuration)
// 小程序登录
const res = await api.createCode2Session('code')
...
- 第三方平台服务商API
import { ThirdPartyAPI, Configuration } from '@xqijia/weixin'
// type ApiType = 'weapp' | 'offiaccount' | 'thirdparty' | 'webapp'
const configuration = new Configuration({
apiType: 'thirdparty',
appID: 'appID',
appSecret: 'appSecret'
})
const api = new ThirdPartyAPI(configuration)
- 网站应用
import { WebAppApi, Configuration } from '@xqijia/weixin'
// type ApiType = 'weapp' | 'offiaccount' | 'thirdparty' | 'webapp'
const configuration = new Configuration({
apiType: 'webapp',
appID: 'appID',
appSecret: 'appSecret'
})
const api = new WebAppApi(configuration)