|
@@ -1,24 +1,17 @@
|
|
|
package com.caimei365.order.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.caimei365.order.feign.ToolsFeign;
|
|
|
+import com.caimei365.order.feign.UserFeign;
|
|
|
import com.caimei365.order.mapper.MessagePushMapper;
|
|
|
import com.caimei365.order.service.RemoteCallService;
|
|
|
import com.caimei365.order.utils.CodeUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.LinkedMultiValueMap;
|
|
|
-import org.springframework.util.MultiValueMap;
|
|
|
-import org.springframework.web.reactive.function.BodyInserters;
|
|
|
-import org.springframework.web.reactive.function.client.WebClient;
|
|
|
-import reactor.core.publisher.Mono;
|
|
|
-
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.time.Duration;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
@@ -27,7 +20,7 @@ import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
- * 推送服务
|
|
|
+ * 远程调用数据处理
|
|
|
*
|
|
|
* @author : Charles
|
|
|
* @date : 2021/7/15
|
|
@@ -39,8 +32,10 @@ public class RemoteCallServiceImpl implements RemoteCallService {
|
|
|
private String profile;
|
|
|
@Resource
|
|
|
private MessagePushMapper messagePushMapper;
|
|
|
- @Autowired
|
|
|
- private WebClient.Builder webClientBuilder;
|
|
|
+ @Resource
|
|
|
+ private ToolsFeign toolsFeign;
|
|
|
+ @Resource
|
|
|
+ private UserFeign userFeign;
|
|
|
|
|
|
/**
|
|
|
* 生成短链接
|
|
@@ -63,7 +58,7 @@ public class RemoteCallServiceImpl implements RemoteCallService {
|
|
|
/**
|
|
|
* 请求发短信接口
|
|
|
*
|
|
|
- * @param markId 短信类型
|
|
|
+ * @param markId 跳转类型
|
|
|
* @param mobile 手机号
|
|
|
* @param content 内容
|
|
|
*/
|
|
@@ -83,28 +78,14 @@ public class RemoteCallServiceImpl implements RemoteCallService {
|
|
|
Pattern pattern = Pattern.compile(regex);
|
|
|
Matcher matcher = pattern.matcher(mobile);
|
|
|
if (matcher.matches()) {
|
|
|
- //提交参数设置
|
|
|
- MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
|
|
- map.add("mobile", mobile);
|
|
|
- map.add("content", content);
|
|
|
- // 发送服务间调用POST请求
|
|
|
- Mono<String> result = webClientBuilder.build()
|
|
|
- .post()
|
|
|
- .uri("http://CAIMEI365-CLOUD-TOOLS/tools/sms/send")
|
|
|
- .contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
|
|
- .body(BodyInserters.fromFormData(map))
|
|
|
- .retrieve()
|
|
|
- .bodyToMono(String.class)
|
|
|
- // 10秒超时
|
|
|
- .timeout(Duration.ofSeconds(10));
|
|
|
- result.subscribe(log::info);
|
|
|
- result.subscribe(jsonStr -> {
|
|
|
- JSONObject parseObject = JSONObject.parseObject(jsonStr);
|
|
|
- if (0 == parseObject.getInteger("code")){
|
|
|
- messagePushMapper.updateSmsSendCount(markId, 1);
|
|
|
- returnValue.set(true);
|
|
|
- }
|
|
|
- });
|
|
|
+ // 调用 ToolsFeign 发送短信
|
|
|
+ String jsonStr = toolsFeign.getSendSms(mobile, content);
|
|
|
+ JSONObject parseObject = JSONObject.parseObject(jsonStr);
|
|
|
+ if (0 == parseObject.getInteger("code")){
|
|
|
+ // 保存短信发送条数+count
|
|
|
+ messagePushMapper.updateSmsSendCount(markId, 1);
|
|
|
+ returnValue.set(true);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -127,29 +108,17 @@ public class RemoteCallServiceImpl implements RemoteCallService {
|
|
|
AtomicReference<String> resultData = new AtomicReference<>("");
|
|
|
// 获取当前微信小程序的环境
|
|
|
String referer = headers.getFirst("Referer");
|
|
|
- //提交参数设置
|
|
|
- MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
|
|
- map.add("code", code);
|
|
|
- map.add("encryptedData", encryptedData);
|
|
|
- map.add("iv", iv);
|
|
|
- // 发送服务间调用POST请求
|
|
|
- Mono<String> result = webClientBuilder.defaultHeader("Referer", referer).build()
|
|
|
- .post()
|
|
|
- .uri("http://CAIMEI365-CLOUD-USER/user/login/auth/applets")
|
|
|
- .contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
|
|
- .body(BodyInserters.fromFormData(map))
|
|
|
- .retrieve()
|
|
|
- .bodyToMono(String.class)
|
|
|
- // 10秒超时
|
|
|
- .timeout(Duration.ofSeconds(10));
|
|
|
- result.subscribe(log::info);
|
|
|
- result.subscribe(jsonStr -> {
|
|
|
+ try {
|
|
|
+ // 调用 UserFeign 获取物流
|
|
|
+ String jsonStr = userFeign.appletsAuthorization(code, encryptedData, iv, referer);
|
|
|
JSONObject parseObject = JSONObject.parseObject(jsonStr);
|
|
|
if (0 == parseObject.getInteger("code")){
|
|
|
- // 登录成功
|
|
|
+ // 授权登录成功
|
|
|
resultData.set(parseObject.getString("data"));
|
|
|
}
|
|
|
- });
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取微信小程序授权失败:", e);
|
|
|
+ }
|
|
|
return resultData.get();
|
|
|
}
|
|
|
|
|
@@ -163,31 +132,17 @@ public class RemoteCallServiceImpl implements RemoteCallService {
|
|
|
@Override
|
|
|
public String getLogisticsByNumber(String number, String companyCode, String mobile) {
|
|
|
AtomicReference<String> resultData = new AtomicReference<>("");
|
|
|
- // 请求参数
|
|
|
- String params = "?number=" + number;
|
|
|
- if (StringUtils.isNotEmpty(companyCode) && StringUtils.isNotEmpty(mobile)) {
|
|
|
- params = params + ("&companyCode=" + companyCode + "&mobile=" + mobile);
|
|
|
- } else if (StringUtils.isNotEmpty(companyCode)) {
|
|
|
- params = params + ("&companyCode=" + companyCode);
|
|
|
- } else if (StringUtils.isNotEmpty(mobile)) {
|
|
|
- params = params + ("&mobile=" + mobile);
|
|
|
- }
|
|
|
- // 发送服务间调用GET请求
|
|
|
- Mono<String> result = webClientBuilder.build()
|
|
|
- .get()
|
|
|
- .uri("http://CAIMEI365-CLOUD-TOOLS/tools/query/logistics" + params)
|
|
|
- .retrieve()
|
|
|
- .bodyToMono(String.class)
|
|
|
- // 10秒超时
|
|
|
- .timeout(Duration.ofSeconds(10));
|
|
|
- result.subscribe(log::info);
|
|
|
- result.subscribe(jsonStr -> {
|
|
|
+ try {
|
|
|
+ // 调用 ToolsFeign 获取物流
|
|
|
+ String jsonStr = toolsFeign.getLogisticsByNumber(number, companyCode, mobile);
|
|
|
JSONObject parseObject = JSONObject.parseObject(jsonStr);
|
|
|
if (0 == parseObject.getInteger("code")){
|
|
|
// 获取物流信息成功
|
|
|
resultData.set(parseObject.getString("data"));
|
|
|
}
|
|
|
- });
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取物流信息失败:", e);
|
|
|
+ }
|
|
|
return resultData.get();
|
|
|
}
|
|
|
}
|