0.0.28 • Published 2 years ago

@huangapple/node-wxapi v0.0.28

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

项目名称

WXAPI的 ts版本实现

运行条件

    //设置appid跟密钥, 然后就都能直接使用了。
WXAPIAPIBaseInstance.setGlobalConfig({ appId: "appid", appSecret: "appSecret" })
let { data } = await WXAPIAccountInstance.getAccountBasicInfo()

被动回复用户消息

//生成回复文本的xml字符串
MessageGen.text({ toUser: "toUser", fromUser: "fromUser", content: "content" })

//这样就会返回如下xml
// <xml>
// <ToUserName><![CDATA[toUser]]></ToUserName>
// <FromUserName><![CDATA[fromUser]]></FromUserName>
// <CreateTime>1681565510</CreateTime>
//
// <MsgType><![CDATA[text]]></MsgType>
// <Content><![CDATA[content]]></Content>
//
// </xml>


//还有image, voice, video, music, news等
MessageGen.image({ toUser: "toUser", fromUser: "fromUser", mediaId: "mediaId" })
MessageGen.voice({ toUser: "toUser", fromUser: "fromUser", mediaId: "mediaId" })
MessageGen.video({
  toUser: "toUser",
  fromUser: "fromUser",
  mediaId: "mediaId",
  title: "title",
  description: "description"
})
MessageGen.music({
  toUser: "toUser",
  fromUser: "fromUser",
  thumbMediaId: "thumbMediaId",
  hqMusicUrl: "hqMusicUrl",
  musicUrl: "musicUrl",
  description: "description",
  title: "title"
})
MessageGen.news({
  toUser: "toUser",
  fromUser: "fromUser",
  articleCount: 2,
  articles: [
    { title: "title1", url: "url1", picUrl: "picUrl1", description: "description1" },
    { title: "title2", url: "url2", picUrl: "picUrl2", description: "description2" }
  ]
})

微信基础消息

签名校验

    let payload = {
  signature: "9c904127b5278e868d97bd04b451668804e51693",
  timestamp: 1681552030,
  nonce: "1937606791"
}

//返回签名校验是否成功
let ok = WXUtil.checkSignature(payload, "1grTZZqtWaLDhjR61xGrpg50R0");

消息XML转json

    let xml = `<xml><ToUserName><![CDATA[gh_fd35603a3406]]></ToUserName>
<FromUserName><![CDATA[oAkeW05qqiR8NOzzA1Und3ufh-Tg]]></FromUserName>
<CreateTime>1681563392</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[小家庭]]></Content>
<MsgId>24074200986519996</MsgId>
</xml>
`

let message: MessagePayload = WXUtil.xml2json(xml)
console.log(JSON.stringify(message, null, 4))
//打印以下结构信息
let temp = {
  "ToUserName": "gh_fd35603a3406",
  "FromUserName": "oAkeW05qqiR8NOzzA1Und3ufh-Tg",
  "CreateTime": 1681563392,
  "MsgType": "text",
  "Content": "小家庭",
  "MsgId": 24074200986519996
}
0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.26

2 years ago

0.0.27

2 years ago

0.0.28

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3-beta1

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago