发送应用消息

效果图

发送应用消息 - 图1发送应用消息 - 图2发送应用消息 - 图3
发送应用消息 - 图4发送应用消息 - 图5

源码

TNWX-QySendMsgApi发送应用消息 - 图6

示例

  1. app.get('/sendMsg', (req, res) => {
  2. let type: string = req.query.type;
  3. let agentId = QyApiConfigKit.getApiConfig.getAppId
  4. let toUser = 'Javen'
  5. switch (parseInt(type)) {
  6. case 0:
  7. // 发送文本消息
  8. let text = new QyTextMsg(
  9. new QyText('TNWX 微信系开发脚手架 \n https://gitee.com/javen205/TNWX'),
  10. agentId,
  11. toUser
  12. )
  13. QySendMsgApi.sendTextMessage(text)
  14. .then(data => {
  15. res.send(data);
  16. })
  17. .catch(error =>console.log(error))
  18. break;
  19. case 1:
  20. // 图片消息
  21. let image = new QyImageMsg(
  22. new QyMediaId('1X7ARFWFBZBnOgNEtpRbmSR46LdLuX1aDtoxbJgpBzRqT34EmnQtXxiPk9DfBXzSa'),
  23. agentId,
  24. toUser
  25. )
  26. QySendMsgApi.sendImageMessage(image)
  27. .then(data => {
  28. res.send(data);
  29. })
  30. .catch(error =>console.log(error))
  31. break;
  32. case 2:
  33. // 语音消息
  34. let voice = new QyVoiceMsg(
  35. new QyMediaId('1mxRvPy6x2UkcxFZ22z1CssutVW-Ybez3Oj18N2FfUAY'),
  36. agentId,
  37. toUser
  38. )
  39. QySendMsgApi.sendVoiceMessage(voice)
  40. .then(data => {
  41. res.send(data);
  42. })
  43. .catch(error =>console.log(error))
  44. break;
  45. case 3:
  46. // 视频消息
  47. let video = new QyVideoMsg(
  48. new QyVideo(
  49. '1EWVjcD-veu9ZMOduIEFVwh3IAraTa5JZi6XvCQ6Z4zJZup-2YrnHt4ZhEqjyvbtG',
  50. 'TNWX 视频消息',
  51. 'TNWX 微信系开发脚手架'
  52. ),
  53. agentId,
  54. toUser
  55. )
  56. QySendMsgApi.sendVideoMessage(video)
  57. .then(data => {
  58. res.send(data);
  59. })
  60. .catch(error =>console.log(error))
  61. break;
  62. case 4:
  63. // 文件消息
  64. let file = new QyFileMsg(
  65. new QyMediaId(
  66. '1X7ARFWFBZBnOgNEtpRbmSR46LdLuX1aDtoxbJgpBzRqT34EmnQtXxiPk9DfBXzSa',
  67. ),
  68. agentId,
  69. toUser
  70. )
  71. QySendMsgApi.sendFileMessage(file)
  72. .then(data => {
  73. res.send(data);
  74. })
  75. .catch(error =>console.log(error))
  76. break;
  77. case 5:
  78. // 文本卡片消息
  79. let textcard = new QyTextCardMsg(
  80. new QyTextCard(
  81. 'TNWX 微信系开发脚手架',
  82. 'TNWX: TypeScript + Node.js + WeiXin 微信系开发脚手架,支持微信公众号、微信支付、微信小游戏、微信小程序、企业微信/企业号。最最最重要的是能快速的集成至任何 Node.js 框架(Express、Nest、Egg、Koa 等)',
  83. 'https://gitee.com/javen205/TNWX',
  84. '了解更多'
  85. ),
  86. agentId,
  87. toUser
  88. )
  89. QySendMsgApi.sendTextCardMessage(textcard)
  90. .then(data => {
  91. res.send(data);
  92. })
  93. .catch(error =>console.log(error))
  94. break;
  95. case 6:
  96. // 图文消息
  97. let news = new QyNewsMsg(
  98. new QyArticles(
  99. [
  100. new QyNews(
  101. 'TNWX 微信系开发脚手架',
  102. 'TNWX: TypeScript + Node.js + WeiXin 微信系开发脚手架,支持微信公众号、微信支付、微信小游戏、微信小程序、企业微信/企业号。最最最重要的是能快速的集成至任何 Node.js 框架(Express、Nest、Egg、Koa 等)',
  103. 'https://s2.ax1x.com/2020/02/01/1J9I9P.jpg',
  104. 'https://gitee.com/javen205/TNWX',
  105. ),
  106. new QyNews(
  107. 'IJPay 聚合支付SDK',
  108. '聚合支付,IJPay 让支付触手可及,封装了微信支付、QQ支付、支付宝支付、京东支付、银联支付常用的支付方式以及各种常用的接口。不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。',
  109. 'https://gitee.com/javen205/IJPay/raw/master/assets/img/logo.png',
  110. 'https://javen205.gitee.io/ijpay',
  111. ),
  112. ]
  113. ),
  114. agentId,
  115. toUser
  116. )
  117. QySendMsgApi.sendNewsMessage(news)
  118. .then(data => {
  119. res.send(data);
  120. })
  121. .catch(error =>console.log(error))
  122. break;
  123. case 7:
  124. // 多图文消息
  125. let mpnews = new QyMpNewsMsg(
  126. new QyMpNewsArticles([
  127. new QyMpNews(
  128. 'TNWX 微信系开发脚手架',
  129. '1X7ARFWFBZBnOgNEtpRbmSR46LdLuX1aDtoxbJgpBzRqT34EmnQtXxiPk9DfBXzSa',
  130. 'TNWX: TypeScript + Node.js + WeiXin 微信系开发脚手架,支持微信公众号、微信支付、微信小游戏、微信小程序、企业微信/企业号。最最最重要的是能快速的集成至任何 Node.js 框架(Express、Nest、Egg、Koa 等)',
  131. 'Javen',
  132. 'https://gitee.com/javen205/TNWX',
  133. '了解一下'
  134. )
  135. ]),
  136. agentId,
  137. toUser
  138. )
  139. QySendMsgApi.sendMpNewsMessage(mpnews)
  140. .then(data => {
  141. res.send(data);
  142. })
  143. .catch(error =>console.log(error))
  144. break;
  145. case 8:
  146. // markdown 消息
  147. let markDown = new QyMarkDownMsg(
  148. new QyText(
  149. "Javen 开源项目列表:\n"+
  150. "[TNWX 微信系开发脚手架](https://gitee.com/javen205/TNWX)\n" +
  151. "[IJPay 让支付触手可及](https://gitee.com/javen205/IJPay)\n" +
  152. "[JPay 简易而不简单的支付 SDK](https://gitee.com/javen205/IJPay)\n"
  153. ),
  154. agentId,
  155. toUser
  156. )
  157. QySendMsgApi.sendMarkDownMessage(markDown)
  158. .then(data => {
  159. res.send(data);
  160. })
  161. .catch(error =>console.log(error))
  162. break;
  163. case 9:
  164. // 小程序通知消息
  165. let miniprogram = new QyMiniProgramNoticeMsg(
  166. new QyMiniprogram(
  167. 'wxf30d9b9b316d5de4',
  168. '老铁开源项目了解一下',
  169. [
  170. new QyKv('项目名称', 'TNWX'),
  171. new QyKv('参与人员', '所有开发者'),
  172. ],
  173. 'pages/index',
  174. '2月2日 14:00',
  175. true
  176. ),
  177. agentId,
  178. toUser
  179. )
  180. QySendMsgApi.sendMiniprogramNoticeMessage(miniprogram)
  181. .then(data => {
  182. res.send(data);
  183. })
  184. .catch(error =>console.log(error))
  185. break;
  186. case 10:
  187. // 任务卡片消息
  188. let taskCard = new QyTaskCardMsg(
  189. new QyTaskCard(
  190. '123456789',
  191. '邀请参加TNWX线下活动',
  192. '抽奖时间:15:00<br>礼品:TNWX 周边礼物',
  193. [
  194. new QyTaskCardBtn('receive', '同意', '已同意', 'red', true),
  195. new QyTaskCardBtn('cancel', '取消', '已取消'),
  196. ],
  197. 'https://gitee.com/javen205/TNWX'
  198. ),
  199. agentId,
  200. toUser
  201. )
  202. QySendMsgApi.sendTaskCardMessage(taskCard)
  203. .then(data => {
  204. res.send(data);
  205. })
  206. .catch(error =>console.log(error))
  207. break;
  208. case 11:
  209. // 更新任务卡片消息状态
  210. QyWxApi.updateTaskCard('Javen',agentId,'123456789','receive')
  211. .then(data => {
  212. res.send(data);
  213. })
  214. .catch(error =>console.log(error))
  215. break;
  216. default:
  217. break;
  218. }
  219. });