12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- '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.sendDir + this.appid;
- const requestData = { // 发送模板消息的数据
- touser: openid,
- template_id: templateid,
- url: 'http://weixin.qq.com/download',
- 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',
- },
- },
- };
- const result = await this.ctx.curl(url, {
- method: 'post',
- body: requestData,
- });
- console.log(result);
- }
- }
- module.exports = WechatService;
|