Commit 63d4a464 authored by Aria's avatar Aria

add wx_sendText

parent 96f08451
Pipeline #19696 passed with stage
in 2 seconds
......@@ -19,7 +19,7 @@ class UserController extends Controller {
const session_key = wx_auth_ret.session_key;
// 检查是否已授权过 是否已入用户表
let user = await ctx.classModel.V4.CourseUser.one({ where: { openid, is_deleted: 0 } });
let user = await ctx.classModel.V4.CourseUser.findOne({ where: { openid, is_deleted: 0 }, order: [[ 'id', 'asc' ]] });
if (!user || !user.uuid) {
const uuid = uuidv4();
user = await ctx.classModel.V4.CourseUser.create({ uuid, openid });
......
......@@ -31,6 +31,44 @@ class WechatService extends Service {
}
async sendMsg(data) {
const { ctx } = this;
if (ctx.isEmpty(data) || ctx.isEmpty(data.MsgType)) {
return;
}
if (data.MsgType === 'miniprogrampage') {
await this.sendImage(data);
} else if (data.MsgType === 'text') {
await this.sendText(data);
}
return;
}
async sendText(data) {
const { ctx } = this;
if (ctx.isEmpty(data) || ctx.isEmpty(data.Content) || !data.Content.includes('在线课程编号:')) {
return;
}
const id = data.Content.replace('在线课程编号:', '');
const classInfo = await ctx.classModel.V4.CourseOnlineClass.findOne({ where: { id } });
const content = ctx.isEmpty(classInfo) || ctx.isEmpty(classInfo.channel) ? '' : classInfo.channel;
const token = await this.getAccessToken();
const url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' + token;
const params = {
access_token: token,
touser: data.FromUserName,
msgtype: 'text',
text: { content },
};
const resp = await ctx.helper.send_request(url, params, { method: 'POST' });
ctx.logger.info('course_wechat_v4_resp: ' + JSON.stringify(resp));
return;
}
async sendImage(data) {
const { ctx, app } = this;
if (ctx.isEmpty(data)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment