wechat.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. require('../util/constants');
  3. const Service = require('egg').Service;
  4. class WechatService extends Service {
  5. constructor(ctx) {
  6. super(ctx);
  7. this.appid = 'wxdf3ed83c095be97a';
  8. }
  9. // 发送微信模板消息
  10. async sendTemplateMsg(templateid, openid, first, keyword1, keyword2, keyword3, remark) {
  11. const url = this.ctx.app.config.sendDir + this.appid;
  12. const requestData = { // 发送模板消息的数据
  13. touser: openid,
  14. template_id: templateid,
  15. url: 'http://weixin.qq.com/download',
  16. data: {
  17. first: {
  18. value: first,
  19. color: '#173177',
  20. },
  21. keyword1: {
  22. value: keyword1,
  23. color: '#1d1d1d',
  24. },
  25. keyword2: {
  26. value: keyword2,
  27. color: '#1d1d1d',
  28. },
  29. keyword3: {
  30. value: keyword3,
  31. color: '#1d1d1d',
  32. },
  33. remark: {
  34. value: remark,
  35. color: '#173177',
  36. },
  37. },
  38. };
  39. const result = await this.ctx.curl(url, {
  40. method: 'post',
  41. body: requestData,
  42. });
  43. console.log(result);
  44. }
  45. }
  46. module.exports = WechatService;