|
|
@@ -2,19 +2,27 @@ package com.ydtech.modules.admin.components;
|
|
|
|
|
|
|
|
|
import com.ydtech.config.properties.WechatCustomerProperties;
|
|
|
-import com.ydtech.modules.admin.components.wechat.customer.request.CustomerGetTokenRequest;
|
|
|
-import com.ydtech.modules.admin.components.wechat.customer.response.CustomerGetTokenResponse;
|
|
|
+import com.ydtech.modules.admin.components.wechat.customer.request.*;
|
|
|
+import com.ydtech.modules.admin.components.wechat.customer.response.*;
|
|
|
import com.ydtech.modules.admin.constants.WechatCustomerEnum;
|
|
|
+import com.ydtech.modules.order.components.InsCrawlerOrderComponents;
|
|
|
import com.ydtech.modules.order.constants.OrderCacheConstant;
|
|
|
import com.ydtech.modules.protocol.utils.AssertionUtils;
|
|
|
import com.ydtech.utils.cache.BaseCacheConfig;
|
|
|
import com.ydtech.utils.cache.RedissonUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
+/**
|
|
|
+ * @description: 【微信客服】 发送请求实体
|
|
|
+ * @author: wenks
|
|
|
+ * @date: 2024/11/28 15:35
|
|
|
+ **/
|
|
|
@Component
|
|
|
@RequiredArgsConstructor
|
|
|
public class WechatCustomerComponents {
|
|
|
@@ -25,24 +33,74 @@ public class WechatCustomerComponents {
|
|
|
|
|
|
private final RedissonUtils redissonUtils;
|
|
|
|
|
|
+ private final InsCrawlerOrderComponents insCrawlerOrderComponents;
|
|
|
+
|
|
|
+ private <T, B extends CustomerBaseResponse> B request(WechatCustomerEnum wechatCustomer, T requestBody, Class<B> responseType, HttpHeaders httpHeaders) {
|
|
|
+ String token = getToken();
|
|
|
+ String url = WechatCustomerEnum.URL + wechatCustomer.getUri() + "?access_token=" + token;
|
|
|
+ return insCrawlerOrderComponents.request(url, "wechatCustomer", wechatCustomer.getDesc(), requestBody, responseType, httpHeaders);
|
|
|
+ }
|
|
|
+
|
|
|
+ public WxCryptUtil getWxCryptUtil(){
|
|
|
+ return new WxCryptUtil(wechatCustomerProperties.getToken(), wechatCustomerProperties.getEncodingAesKey(), wechatCustomerProperties.getCorpId());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取调用凭证access_token
|
|
|
*
|
|
|
* @return access_token
|
|
|
*/
|
|
|
- public String getToken() {
|
|
|
+ private String getToken() {
|
|
|
return redissonUtils.getFromRedis(() -> {
|
|
|
CustomerGetTokenRequest customerGetTokenRequest = new CustomerGetTokenRequest(wechatCustomerProperties.getCorpId(), wechatCustomerProperties.getSecret());
|
|
|
- String url = WechatCustomerEnum.URL + customerGetTokenRequest;
|
|
|
+ String url = WechatCustomerEnum.URL + customerGetTokenRequest.getUrlParams();
|
|
|
CustomerGetTokenResponse customerGetTokenResponse = restTemplate.getForObject(url, CustomerGetTokenResponse.class);
|
|
|
AssertionUtils.isEmpty(customerGetTokenResponse, "获取调用凭证access_token异常");
|
|
|
String accessToken = customerGetTokenResponse.getAccessToken();
|
|
|
- return new BaseCacheConfig<String>()
|
|
|
- .setExpiresIn(customerGetTokenResponse.getExpiresIn())
|
|
|
- .setTimeUnit(TimeUnit.SECONDS)
|
|
|
- .setData(accessToken);
|
|
|
+ return new BaseCacheConfig<String>().setExpiresIn(customerGetTokenResponse.getExpiresIn()).setTimeUnit(TimeUnit.SECONDS).setData(accessToken);
|
|
|
}, OrderCacheConstant.WECHAT_CUSTOMER_TOKEN);
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取客服账号列表
|
|
|
+ *
|
|
|
+ * @param customerListRequest 请求实体
|
|
|
+ * @return 客服账号列表
|
|
|
+ */
|
|
|
+ public CustomerListResponse list(CustomerListRequest customerListRequest) {
|
|
|
+ return request(WechatCustomerEnum.LIST, customerListRequest, CustomerListResponse.class, HttpHeaders.EMPTY);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取客服账号链接
|
|
|
+ *
|
|
|
+ * @param customerAddContactWayRequest 请求实体
|
|
|
+ * @return 客服账号链接
|
|
|
+ */
|
|
|
+ public CustomerAddContactWayResponse addContactWay(CustomerAddContactWayRequest customerAddContactWayRequest) {
|
|
|
+ return request(WechatCustomerEnum.ADD_CONTACT_WAY, customerAddContactWayRequest, CustomerAddContactWayResponse.class, HttpHeaders.EMPTY);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取消息
|
|
|
+ *
|
|
|
+ * @param customerSendMsgOnEventRequest 请求实体
|
|
|
+ * @return 消息信息
|
|
|
+ */
|
|
|
+ public CustomerSendMsgOnEventResponse sendMsgOnEvent(CustomerSendMsgOnEventRequest customerSendMsgOnEventRequest) {
|
|
|
+ return request(WechatCustomerEnum.LIST, customerSendMsgOnEventRequest, CustomerSendMsgOnEventResponse.class, HttpHeaders.EMPTY);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送客服欢迎语
|
|
|
+ *
|
|
|
+ * @param customerSyncMsgRequest 请求实体
|
|
|
+ * @return 成功失败
|
|
|
+ */
|
|
|
+ public CustomerSyncMsgResponse syncMsg(CustomerSyncMsgRequest customerSyncMsgRequest) {
|
|
|
+ return request(WechatCustomerEnum.SYNC_MSG, customerSyncMsgRequest, CustomerSyncMsgResponse.class, HttpHeaders.EMPTY);
|
|
|
+ }
|
|
|
+
|
|
|
}
|