1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 'use strict';
- const Service = require('egg').Service;
- class WechatService extends Service {
- constructor(ctx) {
- super(ctx);
- this.appid = 'wxa9997e40dea04213';
- }
- // 发送微信模板消息
- 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,
- 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));
- // console.log('url---' + url);
- await this.ctx.curl(url, {
- method: 'post',
- headers: {
- 'content-type': 'application/json',
- },
- dataType: 'json',
- data: JSON.stringify(requestData),
- });
- }
- }
- module.exports = WechatService;
|