mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-08 17:27:31 +00:00
feat: 全局格式化代码
This commit is contained in:
@@ -5,8 +5,8 @@ import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public abstract class AbstractBuilder {
|
||||
public abstract WxCpXmlOutMessage build(String content, WxCpXmlMessage wxMessage, WxCpService service);
|
||||
public abstract WxCpXmlOutMessage build(String content, WxCpXmlMessage wxMessage, WxCpService service);
|
||||
}
|
||||
|
||||
@@ -6,19 +6,19 @@ import me.chanjar.weixin.cp.bean.message.WxCpXmlOutImageMessage;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class ImageBuilder extends AbstractBuilder {
|
||||
|
||||
@Override
|
||||
public WxCpXmlOutMessage build(String content, WxCpXmlMessage wxMessage,
|
||||
WxCpService service) {
|
||||
@Override
|
||||
public WxCpXmlOutMessage build(String content, WxCpXmlMessage wxMessage,
|
||||
WxCpService service) {
|
||||
|
||||
WxCpXmlOutImageMessage m = WxCpXmlOutMessage.IMAGE().mediaId(content)
|
||||
.fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
||||
.build();
|
||||
WxCpXmlOutImageMessage m = WxCpXmlOutMessage.IMAGE().mediaId(content)
|
||||
.fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
||||
.build();
|
||||
|
||||
return m;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,17 +6,17 @@ import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpXmlOutTextMessage;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class TextBuilder extends AbstractBuilder {
|
||||
|
||||
@Override
|
||||
public WxCpXmlOutMessage build(String content, WxCpXmlMessage wxMessage,
|
||||
WxCpService service) {
|
||||
WxCpXmlOutTextMessage m = WxCpXmlOutMessage.TEXT().content(content)
|
||||
.fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
||||
.build();
|
||||
return m;
|
||||
}
|
||||
@Override
|
||||
public WxCpXmlOutMessage build(String content, WxCpXmlMessage wxMessage,
|
||||
WxCpService service) {
|
||||
WxCpXmlOutTextMessage m = WxCpXmlOutMessage.TEXT().content(content)
|
||||
.fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
||||
.build();
|
||||
return m;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,18 +27,17 @@ import java.util.stream.Collectors;
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(WxCpProperties.class)
|
||||
public class WxCpConfiguration {
|
||||
private static Map<Integer, WxCpMessageRouter> routers = Maps.newHashMap();
|
||||
private static Map<Integer, WxCpService> cpServices = Maps.newHashMap();
|
||||
private final LogHandler logHandler;
|
||||
private final UnsubscribeHandler unsubscribeHandler;
|
||||
private NullHandler nullHandler;
|
||||
private LocationHandler locationHandler;
|
||||
private MenuHandler menuHandler;
|
||||
private MsgHandler msgHandler;
|
||||
private final UnsubscribeHandler unsubscribeHandler;
|
||||
private SubscribeHandler subscribeHandler;
|
||||
private WxCpProperties properties;
|
||||
|
||||
private static Map<Integer, WxCpMessageRouter> routers = Maps.newHashMap();
|
||||
private static Map<Integer, WxCpService> cpServices = Maps.newHashMap();
|
||||
|
||||
@Autowired
|
||||
public WxCpConfiguration(LogHandler logHandler, NullHandler nullHandler, LocationHandler locationHandler,
|
||||
MenuHandler menuHandler, MsgHandler msgHandler, UnsubscribeHandler unsubscribeHandler,
|
||||
@@ -86,40 +85,40 @@ public class WxCpConfiguration {
|
||||
|
||||
// 自定义菜单事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.MenuButtonType.CLICK).handler(this.menuHandler).end();
|
||||
.event(WxConsts.MenuButtonType.CLICK).handler(this.menuHandler).end();
|
||||
|
||||
// 点击菜单链接事件(这里使用了一个空的处理器,可以根据自己需要进行扩展)
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.MenuButtonType.VIEW).handler(this.nullHandler).end();
|
||||
.event(WxConsts.MenuButtonType.VIEW).handler(this.nullHandler).end();
|
||||
|
||||
// 关注事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.EventType.SUBSCRIBE).handler(this.subscribeHandler)
|
||||
.end();
|
||||
.event(WxConsts.EventType.SUBSCRIBE).handler(this.subscribeHandler)
|
||||
.end();
|
||||
|
||||
// 取消关注事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.EventType.UNSUBSCRIBE)
|
||||
.handler((WxCpMessageHandler) this.unsubscribeHandler).end();
|
||||
.event(WxConsts.EventType.UNSUBSCRIBE)
|
||||
.handler((WxCpMessageHandler) this.unsubscribeHandler).end();
|
||||
|
||||
// 上报地理位置事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.EventType.LOCATION).handler(this.locationHandler)
|
||||
.end();
|
||||
.event(WxConsts.EventType.LOCATION).handler(this.locationHandler)
|
||||
.end();
|
||||
|
||||
// 接收地理位置消息
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.LOCATION)
|
||||
.handler(this.locationHandler).end();
|
||||
.handler(this.locationHandler).end();
|
||||
|
||||
// 扫码事件(这里使用了一个空的处理器,可以根据自己需要进行扩展)
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.EventType.SCAN).handler((WxCpMessageHandler) this.nullHandler).end();
|
||||
.event(WxConsts.EventType.SCAN).handler((WxCpMessageHandler) this.nullHandler).end();
|
||||
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxCpConsts.EventType.CHANGE_CONTACT).handler(new ContactChangeHandler()).end();
|
||||
.event(WxCpConsts.EventType.CHANGE_CONTACT).handler(new ContactChangeHandler()).end();
|
||||
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxCpConsts.EventType.ENTER_AGENT).handler(new EnterAgentHandler()).end();
|
||||
.event(WxCpConsts.EventType.ENTER_AGENT).handler(new EnterAgentHandler()).end();
|
||||
|
||||
// 默认
|
||||
newRouter.rule().async(false).handler(this.msgHandler).end();
|
||||
|
||||
@@ -13,36 +13,36 @@ import java.util.List;
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "wechat.cp")
|
||||
public class WxCpProperties {
|
||||
/**
|
||||
* 设置企业微信的corpId
|
||||
*/
|
||||
private String corpId;
|
||||
|
||||
private List<AppConfig> appConfigs;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class AppConfig {
|
||||
/**
|
||||
* 设置企业微信应用的AgentId
|
||||
* 设置企业微信的corpId
|
||||
*/
|
||||
private Integer agentId;
|
||||
private String corpId;
|
||||
|
||||
/**
|
||||
* 设置企业微信应用的Secret
|
||||
*/
|
||||
private String secret;
|
||||
private List<AppConfig> appConfigs;
|
||||
|
||||
/**
|
||||
* 设置企业微信应用的token
|
||||
*/
|
||||
private String token;
|
||||
@Getter
|
||||
@Setter
|
||||
public static class AppConfig {
|
||||
/**
|
||||
* 设置企业微信应用的AgentId
|
||||
*/
|
||||
private Integer agentId;
|
||||
|
||||
/**
|
||||
* 设置企业微信应用的EncodingAESKey
|
||||
*/
|
||||
private String aesKey;
|
||||
/**
|
||||
* 设置企业微信应用的Secret
|
||||
*/
|
||||
private String secret;
|
||||
|
||||
}
|
||||
/**
|
||||
* 设置企业微信应用的token
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 设置企业微信应用的EncodingAESKey
|
||||
*/
|
||||
private String aesKey;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class WeixinServerController {
|
||||
|
||||
@PostMapping(value = "/weixin/check")
|
||||
public String weixinMsg(@RequestBody String requestBody, @RequestParam("signature") String signature,
|
||||
@RequestParam("timestamp") String timestamp, @RequestParam("nonce") String nonce) {
|
||||
@RequestParam("timestamp") String timestamp, @RequestParam("nonce") String nonce) {
|
||||
|
||||
log.debug("requestBody:{}", requestBody);
|
||||
log.debug("signature:{}", signature);
|
||||
|
||||
@@ -7,7 +7,6 @@ import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
|
||||
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.ruoyi.common.core.utils.JsonUtils;
|
||||
|
||||
import org.ruoyi.config.WxCpConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -27,63 +26,63 @@ public class WxPortalController {
|
||||
private Integer agentId;
|
||||
|
||||
|
||||
@GetMapping(produces = "text/plain;charset=utf-8")
|
||||
public String authGet(
|
||||
@RequestParam(name = "msg_signature", required = false) String signature,
|
||||
@RequestParam(name = "timestamp", required = false) String timestamp,
|
||||
@RequestParam(name = "nonce", required = false) String nonce,
|
||||
@RequestParam(name = "echostr", required = false) String echostr) {
|
||||
log.info("\n接收到来自微信服务器的认证消息:signature = [{}], timestamp = [{}], nonce = [{}], echostr = [{}]",
|
||||
signature, timestamp, nonce, echostr);
|
||||
@GetMapping(produces = "text/plain;charset=utf-8")
|
||||
public String authGet(
|
||||
@RequestParam(name = "msg_signature", required = false) String signature,
|
||||
@RequestParam(name = "timestamp", required = false) String timestamp,
|
||||
@RequestParam(name = "nonce", required = false) String nonce,
|
||||
@RequestParam(name = "echostr", required = false) String echostr) {
|
||||
log.info("\n接收到来自微信服务器的认证消息:signature = [{}], timestamp = [{}], nonce = [{}], echostr = [{}]",
|
||||
signature, timestamp, nonce, echostr);
|
||||
|
||||
if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
|
||||
throw new IllegalArgumentException("请求参数非法,请核实!");
|
||||
if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
|
||||
throw new IllegalArgumentException("请求参数非法,请核实!");
|
||||
}
|
||||
|
||||
final WxCpService wxCpService = WxCpConfiguration.getCpService(agentId);
|
||||
if (wxCpService == null) {
|
||||
throw new IllegalArgumentException(String.format("未找到对应agentId=[%d]的配置,请核实!", agentId));
|
||||
}
|
||||
|
||||
if (wxCpService.checkSignature(signature, timestamp, nonce, echostr)) {
|
||||
return new WxCpCryptUtil(wxCpService.getWxCpConfigStorage()).decrypt(echostr);
|
||||
}
|
||||
|
||||
return "非法请求";
|
||||
}
|
||||
|
||||
final WxCpService wxCpService = WxCpConfiguration.getCpService(agentId);
|
||||
if (wxCpService == null) {
|
||||
throw new IllegalArgumentException(String.format("未找到对应agentId=[%d]的配置,请核实!", agentId));
|
||||
@PostMapping(produces = "application/xml; charset=UTF-8")
|
||||
public String post(
|
||||
@RequestBody String requestBody,
|
||||
@RequestParam("msg_signature") String signature,
|
||||
@RequestParam("timestamp") String timestamp,
|
||||
@RequestParam("nonce") String nonce) {
|
||||
log.info("\n接收微信请求:[signature=[{}], timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ",
|
||||
signature, timestamp, nonce, requestBody);
|
||||
|
||||
final WxCpService wxCpService = WxCpConfiguration.getCpService(1000002);
|
||||
WxCpXmlMessage inMessage = WxCpXmlMessage.fromEncryptedXml(requestBody, wxCpService.getWxCpConfigStorage(),
|
||||
timestamp, nonce, signature);
|
||||
log.debug("\n消息解密后内容为:\n{} ", JsonUtils.toJson(inMessage));
|
||||
WxCpXmlOutMessage outMessage = this.route(1000002, inMessage);
|
||||
if (outMessage == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String out = outMessage.toEncryptedXml(wxCpService.getWxCpConfigStorage());
|
||||
log.debug("\n组装回复信息:{}", out);
|
||||
return out;
|
||||
}
|
||||
|
||||
if (wxCpService.checkSignature(signature, timestamp, nonce, echostr)) {
|
||||
return new WxCpCryptUtil(wxCpService.getWxCpConfigStorage()).decrypt(echostr);
|
||||
private WxCpXmlOutMessage route(Integer agentId, WxCpXmlMessage message) {
|
||||
try {
|
||||
return WxCpConfiguration.getRouters().get(agentId).route(message);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return "非法请求";
|
||||
}
|
||||
|
||||
@PostMapping(produces = "application/xml; charset=UTF-8")
|
||||
public String post(
|
||||
@RequestBody String requestBody,
|
||||
@RequestParam("msg_signature") String signature,
|
||||
@RequestParam("timestamp") String timestamp,
|
||||
@RequestParam("nonce") String nonce) {
|
||||
log.info("\n接收微信请求:[signature=[{}], timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ",
|
||||
signature, timestamp, nonce, requestBody);
|
||||
|
||||
final WxCpService wxCpService = WxCpConfiguration.getCpService(1000002);
|
||||
WxCpXmlMessage inMessage = WxCpXmlMessage.fromEncryptedXml(requestBody, wxCpService.getWxCpConfigStorage(),
|
||||
timestamp, nonce, signature);
|
||||
log.debug("\n消息解密后内容为:\n{} ", JsonUtils.toJson(inMessage));
|
||||
WxCpXmlOutMessage outMessage = this.route(1000002, inMessage);
|
||||
if (outMessage == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String out = outMessage.toEncryptedXml(wxCpService.getWxCpConfigStorage());
|
||||
log.debug("\n组装回复信息:{}", out);
|
||||
return out;
|
||||
}
|
||||
|
||||
private WxCpXmlOutMessage route(Integer agentId, WxCpXmlMessage message) {
|
||||
try {
|
||||
return WxCpConfiguration.getRouters().get(agentId).route(message);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,10 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ReceiveMessage {
|
||||
/**
|
||||
* 消息ID 64位
|
||||
*/
|
||||
String msgId;
|
||||
/**
|
||||
* 开发者微信号
|
||||
*/
|
||||
@@ -24,10 +28,6 @@ public class ReceiveMessage {
|
||||
* 文本消息内容
|
||||
*/
|
||||
private String content;
|
||||
/**
|
||||
* 消息ID 64位
|
||||
*/
|
||||
String msgId;
|
||||
/**
|
||||
* 消息的数据ID 消息来自文章才有
|
||||
*/
|
||||
@@ -47,12 +47,12 @@ public class ReceiveMessage {
|
||||
|
||||
public String getReplyTextMsg(String msg) {
|
||||
String xml = "<xml>\n"
|
||||
+ " <ToUserName><![CDATA[" + getFromUserName() + "]]></ToUserName>\n"
|
||||
+ " <FromUserName><![CDATA[" + getToUserName() + "]]></FromUserName>\n"
|
||||
+ " <CreateTime>" + System.currentTimeMillis() + "</CreateTime>\n"
|
||||
+ " <MsgType><![CDATA[text]]></MsgType>\n"
|
||||
+ " <Content><![CDATA[" + msg + "]]></Content>\n"
|
||||
+ " </xml>";
|
||||
+ " <ToUserName><![CDATA[" + getFromUserName() + "]]></ToUserName>\n"
|
||||
+ " <FromUserName><![CDATA[" + getToUserName() + "]]></FromUserName>\n"
|
||||
+ " <CreateTime>" + System.currentTimeMillis() + "</CreateTime>\n"
|
||||
+ " <MsgType><![CDATA[text]]></MsgType>\n"
|
||||
+ " <Content><![CDATA[" + msg + "]]></Content>\n"
|
||||
+ " </xml>";
|
||||
return xml;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
|
||||
import org.ruoyi.builder.TextBuilder;
|
||||
import org.ruoyi.common.core.utils.JsonUtils;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class LocationHandler extends AbstractHandler {
|
||||
|
||||
//上报地理位置事件
|
||||
log.info("\n上报地理位置,纬度 : {}\n经度 : {}\n精度 : {}",
|
||||
wxMessage.getLatitude(), wxMessage.getLongitude(), String.valueOf(wxMessage.getPrecision()));
|
||||
wxMessage.getLatitude(), wxMessage.getLongitude(), String.valueOf(wxMessage.getPrecision()));
|
||||
|
||||
//TODO 可以将用户地理位置信息保存到本地数据库,以便以后使用
|
||||
|
||||
|
||||
@@ -15,20 +15,20 @@ import java.util.Map;
|
||||
@Component
|
||||
public class MenuHandler extends AbstractHandler {
|
||||
|
||||
@Override
|
||||
public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService cpService,
|
||||
WxSessionManager sessionManager) {
|
||||
@Override
|
||||
public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService cpService,
|
||||
WxSessionManager sessionManager) {
|
||||
|
||||
String msg = String.format("type:%s, event:%s, key:%s",
|
||||
wxMessage.getMsgType(), wxMessage.getEvent(),
|
||||
wxMessage.getEventKey());
|
||||
if (MenuButtonType.VIEW.equals(wxMessage.getEvent())) {
|
||||
return null;
|
||||
String msg = String.format("type:%s, event:%s, key:%s",
|
||||
wxMessage.getMsgType(), wxMessage.getEvent(),
|
||||
wxMessage.getEventKey());
|
||||
if (MenuButtonType.VIEW.equals(wxMessage.getEvent())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return WxCpXmlOutMessage.TEXT().content(msg)
|
||||
.fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
||||
.build();
|
||||
}
|
||||
|
||||
return WxCpXmlOutMessage.TEXT().content(msg)
|
||||
.fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
|
||||
|
||||
import org.ruoyi.builder.TextBuilder;
|
||||
|
||||
import org.ruoyi.service.IChatVxService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@ import java.util.Map;
|
||||
@Component
|
||||
public class NullHandler extends AbstractHandler {
|
||||
|
||||
@Override
|
||||
public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService cpService,
|
||||
WxSessionManager sessionManager) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService cpService,
|
||||
WxSessionManager sessionManager) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ public interface IChatVxService {
|
||||
|
||||
/**
|
||||
* 企业微信应用回复
|
||||
*
|
||||
* @param prompt 提示词
|
||||
* @return 回复内容
|
||||
*/
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 微信公众号登录
|
||||
* 微信公众号登录
|
||||
*
|
||||
* @author ageerle@163.com
|
||||
* date 2025/4/30
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.ruoyi.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.ruoyi.common.chat.entity.chat.ChatCompletion;
|
||||
import org.ruoyi.common.chat.entity.chat.ChatCompletionResponse;
|
||||
import org.ruoyi.common.chat.entity.chat.Message;
|
||||
@@ -26,11 +25,11 @@ public class ChatVxServiceImpl implements IChatVxService {
|
||||
Message message = Message.builder().role(Message.Role.USER).content(prompt).build();
|
||||
messageList.add(message);
|
||||
ChatCompletion chatCompletion = ChatCompletion
|
||||
.builder()
|
||||
.messages(messageList)
|
||||
.model("gpt-4o-mini")
|
||||
.stream(false)
|
||||
.build();
|
||||
.builder()
|
||||
.messages(messageList)
|
||||
.model("gpt-4o-mini")
|
||||
.stream(false)
|
||||
.build();
|
||||
ChatCompletionResponse chatCompletionResponse = openAiStreamClient.chatCompletion(chatCompletion);
|
||||
return chatCompletionResponse.getChoices().get(0).getMessage().getContent().toString();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class WeixinUserServiceImpl implements WeixinUserService {
|
||||
|
||||
@Override
|
||||
public void checkSignature(String signature, String timestamp, String nonce) {
|
||||
String[] arr = new String[] {token, timestamp, nonce};
|
||||
String[] arr = new String[]{token, timestamp, nonce};
|
||||
Arrays.sort(arr);
|
||||
StringBuilder content = new StringBuilder();
|
||||
for (String str : arr) {
|
||||
|
||||
@@ -20,16 +20,14 @@ import java.time.LocalDateTime;
|
||||
@RequiredArgsConstructor
|
||||
public class WeixinApiUtil {
|
||||
|
||||
private final ConfigService configService;
|
||||
|
||||
private static String QR_CODE_URL_PREFIX = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=";
|
||||
|
||||
private static String ACCESS_TOKEN = null;
|
||||
private static LocalDateTime ACCESS_TOKEN_EXPIRE_TIME = null;
|
||||
/**
|
||||
* 二维码 Ticket 过期时间
|
||||
*/
|
||||
private static int QR_CODE_TICKET_TIMEOUT = 10 * 60;
|
||||
private final ConfigService configService;
|
||||
|
||||
/**
|
||||
* 获取 access token
|
||||
@@ -41,7 +39,7 @@ public class WeixinApiUtil {
|
||||
return ACCESS_TOKEN;
|
||||
}
|
||||
String api = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + getKey("appid") + "&secret="
|
||||
+ getKey("secret");
|
||||
+ getKey("secret");
|
||||
String result = HttpUtil.get(api);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
ACCESS_TOKEN = jsonObject.getString("access_token");
|
||||
@@ -51,7 +49,7 @@ public class WeixinApiUtil {
|
||||
|
||||
/**
|
||||
* 获取二维码 Ticket
|
||||
*
|
||||
* <p>
|
||||
* https://developers.weixin.qq.com/doc/offiaccount/Account_Management/Generating_a_Parametric_QR_Code.html
|
||||
*
|
||||
* @return
|
||||
@@ -59,14 +57,14 @@ public class WeixinApiUtil {
|
||||
public WeixinQrCode getQrCode() {
|
||||
String api = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + getAccessToken();
|
||||
String jsonBody = String.format("{\n"
|
||||
+ " \"expire_seconds\": %d,\n"
|
||||
+ " \"action_name\": \"QR_STR_SCENE\",\n"
|
||||
+ " \"action_info\": {\n"
|
||||
+ " \"scene\": {\n"
|
||||
+ " \"scene_str\": \"%s\"\n"
|
||||
+ " }\n"
|
||||
+ " }\n"
|
||||
+ "}", QR_CODE_TICKET_TIMEOUT, KeyUtils.uuid32());
|
||||
+ " \"expire_seconds\": %d,\n"
|
||||
+ " \"action_name\": \"QR_STR_SCENE\",\n"
|
||||
+ " \"action_info\": {\n"
|
||||
+ " \"scene\": {\n"
|
||||
+ " \"scene_str\": \"%s\"\n"
|
||||
+ " }\n"
|
||||
+ " }\n"
|
||||
+ "}", QR_CODE_TICKET_TIMEOUT, KeyUtils.uuid32());
|
||||
String result = HttpUtil.post(api, jsonBody);
|
||||
log.info("get qr code params:{}", jsonBody);
|
||||
log.info("get qr code result:{}", result);
|
||||
|
||||
Reference in New Issue
Block a user