Commit 640b7af1 authored by Hsinli's avatar Hsinli

add

parents b1984a2c 7c3a4e01
Pipeline #19702 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,52 @@ class WechatService extends Service {
}
async sendMsg(data) {
const { ctx } = this;
ctx.logger.info('111');
if (ctx.isEmpty(data) || ctx.isEmpty(data.MsgType)) {
ctx.logger.info(JSON.stringify(data));
return;
}
ctx.logger.info(data.MsgType);
if (data.MsgType === 'miniprogrampage') {
ctx.logger.info('------------miniprogrampage---------');
await this.sendImage(data);
} else if (data.MsgType === 'text') {
ctx.logger.info('------------sendText------');
await this.sendText(data);
}
return;
}
async sendText(data) {
const { ctx } = this;
if (ctx.isEmpty(data) || ctx.isEmpty(data.Content) || !data.Content.includes('在线课程编号:')) {
ctx.logger.info(data.Content);
ctx.logger.info(data.Content.includes('在线课程编号:'));
return;
}
const id = data.Content.replace('在线课程编号:', '');
const classInfo = await ctx.classModel.V4.CourseOnlineClass.findOne({ where: { id } });
ctx.logger.info('course_v4: ' + JSON.stringify(classInfo));
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 },
};
ctx.logger.info('course_wechat_v4_param: ' + JSON.stringify(params));
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