123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 'use strict';
- require('../util/constants');
- const Service = require('egg').Service;
- class WechatService extends Service {
- constructor(ctx) {
- super(ctx);
- this.appid = 'wxdf3ed83c095be97a';
- }
- // 发送微信模板消息
- async sendTemplateMsg(templateid, openid, first, keyword1, keyword2, keyword3, remark) {
- const url = this.ctx.app.config.sendDirMq + this.ctx.app.config.appid;
- const requestData = { // 发送模板消息的数据
- touser: openid,
- template_id: templateid,
- url: '',
- data: {
- first: {
- value: first,
- color: '#173177',
- },
- keyword1: {
- value: keyword1,
- color: '#1d1d1d',
- },
- keyword2: {
- value: keyword2,
- color: '#1d1d1d',
- },
- keyword3: {
- value: keyword3,
- color: '#1d1d1d',
- },
- remark: {
- value: remark,
- color: '#173177',
- },
- },
- };
- console.log('templateid---' + templateid);
- console.log('openid---' + openid);
- console.log('requestData---' + JSON.stringify(requestData));
- await this.ctx.curl(url, {
- method: 'post',
- headers: {
- 'content-type': 'application/json',
- },
- dataType: 'json',
- data: JSON.stringify(requestData),
- });
- }
- }
- module.exports = WechatService;
|