package com.github.paicoding.forum.web.front.login.wx.helper;
import com.github.paicoding.forum.api.model.vo.user.wx.BaseWxMsgResVo;
import com.github.paicoding.forum.api.model.vo.user.wx.WxImgTxtItemVo;
import com.github.paicoding.forum.api.model.vo.user.wx.WxImgTxtMsgResVo;
import com.github.paicoding.forum.api.model.vo.user.wx.WxTxtMsgResVo;
import com.github.paicoding.forum.core.util.CodeGenerateUtil;
import com.github.paicoding.forum.service.chatai.service.ChatgptService;
import com.github.paicoding.forum.service.user.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
@Slf4j
@Component
public class WxAckHelper {
@Autowired
private LoginService sessionService;
@Autowired
private WxLoginHelper qrLoginHelper;
@Autowired
private ChatgptService chatgptService;
/**
* 返回自动响应的文本
*
* @return
*/
public BaseWxMsgResVo buildResponseBody(String eventType, String content, String fromUser) {
// 返回的文本消息
String textRes = null;
// 返回的是图文消息
List<WxImgTxtItemVo> imgTxtList = null;
if ("subscribe".equalsIgnoreCase(eventType)) {
textRes = "欢迎关注派coding公众号!在这里,我会定期分享关于程序人生和技术干货的精彩内容。\n" +
"\n" +
"无论你是想了解Java、Spring、MySQL、Redis、计算机网络、操作系统、消息队列、分布式等技术,还是对编程职业生涯有任何疑问,都可以在公众号留言提问,我会尽力解答。\n" +
"\n" +
"如果你也有技术分享的意愿,非常欢迎投稿,让我们一起交流学习,共同进步!\n" +
"\n" +
"期待在公众号与你相遇,一起探索编程的无限可能。\n";
}
// 下面是关键词回复
else if (chatgptService.inChat(fromUser, content)) {
try {
textRes = chatgptService.chat(fromUser, content);
} catch (Exception e) {
log.error("派coding 访问异常! content: {}", content, e);
textRes = "派coding 出了点小状况,请稍后再试!";
}
}
else if ("admin".equalsIgnoreCase(content) || "后台".equals(content) || "002".equals(content)) {
// admin后台登录,返回对应的用户名 + 密码
// textRes = "技术派后台游客登录账号\n-----------\n登录用户名: guest\n登录密码: 123456";
}
// 微信公众号登录
else if (CodeGenerateUtil.isVerifyCode(content)) {
sessionService.autoRegisterWxUserInfo(fromUser);
if (qrLoginHelper.login(content)) {
textRes = "登录成功,开始愉快的玩耍技术派吧!";
} else {
textRes = "验证码过期了,刷新登录页面重试一下吧";
}
} else {
}
if (textRes != null) {
WxTxtMsgResVo vo = new WxTxtMsgResVo();
vo.setContent(textRes);
return vo;
} else {
WxImgTxtMsgResVo vo = new WxImgTxtMsgResVo();
vo.setArticles(imgTxtList);
vo.setArticleCount(imgTxtList.size());
return vo;
}
}
}
回复