|
|
@@ -1,36 +1,37 @@
|
|
|
package com.ydtech.modules.admin.controller;
|
|
|
|
|
|
-import cn.hutool.core.codec.Base64;
|
|
|
-import cn.hutool.crypto.SecureUtil;
|
|
|
-import cn.hutool.crypto.symmetric.AES;
|
|
|
+import cn.hutool.core.util.XmlUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
|
|
import com.ydtech.core.page.HttpResult;
|
|
|
import com.ydtech.exception.SystemException;
|
|
|
import com.ydtech.modules.admin.model.vo.WechatBindVo;
|
|
|
import com.ydtech.modules.admin.model.vo.WechatLoginVo;
|
|
|
import com.ydtech.modules.admin.model.vo.WechatVo;
|
|
|
+import com.ydtech.modules.admin.model.vo.wechat.WechatCustomerCallbackVo;
|
|
|
+import com.ydtech.modules.admin.model.vo.wechat.WechatEncryptVo;
|
|
|
import com.ydtech.modules.admin.service.WechatService;
|
|
|
import com.ydtech.modules.base.controller.BaseController;
|
|
|
-import com.ydtech.modules.order.utils.AESUtilsWithDataBase;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.models.Xml;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.Data;
|
|
|
import lombok.NoArgsConstructor;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
+import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
|
|
|
+import me.chanjar.weixin.cp.api.WxCpKfService;
|
|
|
+import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgListResp;
|
|
|
+import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgSendRequest;
|
|
|
+import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import javax.servlet.ServletInputStream;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.io.BufferedReader;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStreamReader;
|
|
|
-import java.nio.charset.Charset;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.List;
|
|
|
|
|
|
@Api(tags = "微信业务")
|
|
|
@Slf4j
|
|
|
@@ -64,32 +65,39 @@ public class WechatController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Data
|
|
|
- @AllArgsConstructor
|
|
|
- @NoArgsConstructor
|
|
|
- public static class Test {
|
|
|
-
|
|
|
- private String msgSignature;
|
|
|
-
|
|
|
- private String timestamp;
|
|
|
-
|
|
|
- private String nonce;
|
|
|
-
|
|
|
- private String echostr;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
@GetMapping(path = "/customer/callback")
|
|
|
@ApiOperation(value = "客服回调")
|
|
|
- public HttpResult<String> customerCallback(@RequestParam(value = "msg_signature") String msgSignature,
|
|
|
+ public String customerCallback(@RequestParam(value = "msg_signature") String msgSignature,
|
|
|
@RequestParam(value = "timestamp") String timestamp,
|
|
|
@RequestParam(value = "nonce") String nonce,
|
|
|
@RequestParam(value = "echostr") String echoStr) {
|
|
|
System.out.println(msgSignature + " " + timestamp + " " + nonce + " " + echoStr);
|
|
|
-// HBme3ASL
|
|
|
-// kv1XrZqTDUup27rVatFG3s04DSw2qEAvxg7k9euEROq
|
|
|
-// f1bfbc5dad67cee5ff28b97ee030188c443e12d7 1732671302 1732293939 GOqO+iXVYx2FBoD0uzjwkNcTBEyvOeKKfLkShKrgvQ0GWmAM3cVB4NxXf4KB5w3IDO37yIb8M+9pfSD/xzlwNQ==
|
|
|
- return HttpResult.ok();
|
|
|
+ WxCryptUtil wxCryptUtil = new WxCryptUtil("HBme3ASL", "kv1XrZqTDUup27rVatFG3s04DSw2qEAvxg7k9euEROq", "wwfe67d19509d43ec5");
|
|
|
+ return wxCryptUtil.decryptContent(msgSignature, timestamp, nonce, echoStr);
|
|
|
}
|
|
|
|
|
|
+ @Autowired
|
|
|
+ public WxCpKfService wxCpKfService;
|
|
|
+
|
|
|
+ @PostMapping(path = "/customer/callback", consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE)
|
|
|
+ @ApiOperation(value = "客服回调")
|
|
|
+ public HttpResult customerCallback(@RequestBody String wechatEncrypt) throws JsonProcessingException, WxErrorException {
|
|
|
+ XmlMapper xmlMapper = new XmlMapper();
|
|
|
+ WechatEncryptVo wechatEncryptVo = xmlMapper.readValue(wechatEncrypt, WechatEncryptVo.class);
|
|
|
+ WxCryptUtil wxCryptUtil = new WxCryptUtil("HBme3ASL", "kv1XrZqTDUup27rVatFG3s04DSw2qEAvxg7k9euEROq", "wwfe67d19509d43ec5");
|
|
|
+ String encrypt = wxCryptUtil.decrypt(wechatEncryptVo.getEncrypt());
|
|
|
+ WechatCustomerCallbackVo wechatCustomerCallbackVo = xmlMapper.readValue(encrypt, WechatCustomerCallbackVo.class);
|
|
|
+ WxCpKfMsgListResp wxCpKfMsgListResp = wxCpKfService.syncMsg("", wechatCustomerCallbackVo.getToken(), null, null, wechatCustomerCallbackVo.getOpenKfId());
|
|
|
+ WxCpKfMsgListResp.WxCpKfMsgItem wxCpKfMsgItem = wxCpKfMsgListResp.getMsgList().get(0);
|
|
|
+
|
|
|
+ WxCpKfMsgSendRequest wxCpKfMsgSendRequest = new WxCpKfMsgSendRequest();
|
|
|
+ wxCpKfMsgSendRequest.setMsgType("text");
|
|
|
+ wxCpKfMsgSendRequest.setMsgId(wxCpKfMsgItem.getMsgId());
|
|
|
+ wxCpKfMsgSendRequest.setCode(wxCpKfMsgItem.getEvent().getWelcomeCode());
|
|
|
+ wxCpKfService.sendMsgOnEvent(wxCpKfMsgSendRequest);
|
|
|
+
|
|
|
+ return HttpResult.ok(wxCpKfMsgListResp);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|