提交 954b433f authored 作者: huyufan's avatar huyufan

Merge remote-tracking branch 'origin/v7.0_small_version_fix_20231120' into test

# Conflicts: # performance-web/pom.xml
......@@ -110,7 +110,7 @@ public enum PerformanceResultEnum implements ResultEnum {
TOKEN_IS_FAIL(1908, "token失效,请重新获取token"),
PASSWORD_RESET_IS_FAIL(1909, "重置密码出现异常"),
PASSWORD_CHECK_FAIL(1910, "交易密码填写错误,请重新输入"),
SLIDER_CHECK_FAIL(1911, "滑块验证错误"),
;
private final int code;
private final String msg;
......
......@@ -16,4 +16,13 @@ public class SendMobileCaptchaParam {
@NotBlank(message = "手机号")
private String mobile;
@ApiModelProperty(value = "会话ID", required = true, example = "XXX", dataType = "String")
private String sessionId;
@ApiModelProperty(value = "签名串", required = true, example = "XXX", dataType = "String")
private String sig;
@ApiModelProperty(value = "请求唯一标识", required = true, example = "XXX", dataType = "String")
private String token;
@ApiModelProperty(value = "场景标识", required = true, example = "XXX", dataType = "String")
private String scene;
}
......@@ -265,6 +265,17 @@
<systemPath>${pom.basedir}/libs/openBasicSDK-1.7.0.jar</systemPath>
</dependency>
<dependency>
<groupId>com.aliyun.core</groupId>
<artifactId>machineCheckCore</artifactId>
<version>3.0.6</version>
</dependency>
<dependency>
<groupId>com.aliyun.afs</groupId>
<artifactId>machineCheckAfs</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
......
......@@ -2,11 +2,13 @@ package com.clx.performance.aspect;
import cn.hutool.json.JSONUtil;
import com.clx.performance.annotation.ResetPassword;
import com.clx.performance.component.SendMessageMachineCheckComponent;
import com.clx.performance.constant.RedisConstants;
import com.clx.performance.enums.PerformanceResultEnum;
import com.clx.performance.param.app.CheckMobileParam;
import com.clx.performance.param.app.InformationParam;
import com.clx.performance.param.app.ResetPasswordParam;
import com.clx.performance.param.app.SendMobileCaptchaParam;
import com.msl.common.exception.ServiceSystemException;
import com.msl.common.result.Result;
import org.apache.commons.lang3.StringUtils;
......@@ -18,7 +20,10 @@ import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
......@@ -30,6 +35,9 @@ public class ResetPasswordAnnotationAop {
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Autowired
private SendMessageMachineCheckComponent sendMessageMachineCheckComponent;
@Pointcut("@annotation(com.clx.performance.annotation.ResetPassword)")
private void annotationPointCut() {
}
......@@ -54,7 +62,11 @@ public class ResetPasswordAnnotationAop {
}
break;
case "sendMobileCaptcha":
mobile = JSONUtil.parse(jp.getArgs()[0]).getByPath("mobile").toString();
SendMobileCaptchaParam sendMobileCaptchaParam = JSONUtil.toBean(JSONUtil.parse(jp.getArgs()[0]).toString(), SendMobileCaptchaParam.class);
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = sra.getRequest();
sendMessageMachineCheckComponent.sendMessageMachineSelectCheck(request, sendMobileCaptchaParam);
mobile = sendMobileCaptchaParam.getMobile();
String content = redisTemplate.opsForValue().get(RedisConstants.MESSAGE_MOBILE_CAPTCHA + mobile);
if (StringUtils.isNoneBlank(content)) {
token = UUID.randomUUID().toString();
......
package com.clx.performance.component;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.afs.model.v20180112.AuthenticateSigRequest;
import com.aliyuncs.afs.model.v20180112.AuthenticateSigResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.clx.performance.config.AliSliderConfig;
import com.clx.performance.enums.PerformanceResultEnum;
import com.clx.performance.param.app.SendMobileCaptchaParam;
import com.msl.common.exception.ServiceSystemException;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
/**
* @author cuiwanzhe
* @description
* @date 2020/9/1 4:58 下午
*/
@Service
@Slf4j
@AllArgsConstructor
public class SendMessageMachineCheckComponent {
private final AliSliderConfig aliSliderConfig;
/**
* 滑动验证
*
* @throws
*/
public void sendMessageMachineSelectCheck(HttpServletRequest request, SendMobileCaptchaParam param) throws ServiceSystemException {
if (StringUtils.isBlank(param.getSessionId())) {
throw new ServiceSystemException(PerformanceResultEnum.SLIDER_CHECK_FAIL);
}
if (StringUtils.isBlank(param.getSig())) {
throw new ServiceSystemException(PerformanceResultEnum.SLIDER_CHECK_FAIL);
}
if (StringUtils.isBlank(param.getToken())) {
throw new ServiceSystemException(PerformanceResultEnum.SLIDER_CHECK_FAIL);
}
if (StringUtils.isBlank(param.getScene())) {
throw new ServiceSystemException(PerformanceResultEnum.SLIDER_CHECK_FAIL);
}
Integer responseCode = machineCheckSelect(request, param);
if (responseCode >= 400) {
throw new ServiceSystemException(PerformanceResultEnum.SLIDER_CHECK_FAIL);
}
}
private Integer machineCheckSelect(HttpServletRequest req, SendMobileCaptchaParam param) {
Integer resultCode = null;
IClientProfile profile = DefaultProfile.getProfile(aliSliderConfig.getRegionId(), aliSliderConfig.getAccessKeyId(), aliSliderConfig.getAccessKeySecret());
IAcsClient client = new DefaultAcsClient(profile);
try {
DefaultProfile.addEndpoint(aliSliderConfig.getRegionId(), aliSliderConfig.getRegionId(), aliSliderConfig.getProduct(), aliSliderConfig.getDomain());
} catch (ClientException e) {
e.printStackTrace();
}
String ip = getIpAddress(req);
log.info("=滑动验证=mobile==========>>" + param.getMobile() + "==sessionId========>>" + param.getSessionId() + "==sig=====>>>" + param.getSig() +
"==token=====>>>" + param.getToken() + "==scene=====>>>" + param.getScene() + "==ip=====>>>" + ip);
AuthenticateSigRequest request = new AuthenticateSigRequest();
request.setSessionId(param.getSessionId());// 会话ID。必填参数,从前端获取,不可更改。
request.setSig(param.getSig());// 签名串。必填参数,从前端获取,不可更改。
request.setToken(param.getToken());// 请求唯一标识。必填参数,从前端获取,不可更改。
request.setScene(param.getScene());// 场景标识。必填参数,从前端获取,不可更改。
request.setAppKey("FFFF0N00000000009691");// 应用类型标识。必填参数,后端填写。
request.setRemoteIp(ip);// 客户端IP。必填参数,后端填写。
try {
//response的code枚举:100验签通过,900验签失败
AuthenticateSigResponse response = client.getAcsResponse(request);
resultCode = response.getCode();
// TODO
} catch (Exception e) {
e.printStackTrace();
}
return resultCode;
}
/**
* 获取客户端IP地址
*
* @param request
* @return
*/
private String getIpAddress(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || "unknow".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
if (ip.equals("127.0.0.1")) {
//根据网卡取本机配置的IP
InetAddress inet = null;
try {
inet = InetAddress.getLocalHost();
} catch (Exception e) {
e.printStackTrace();
}
ip = inet.getHostAddress();
}
}
// 多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
if (ip != null && ip.length() > 15) {
if (ip.indexOf(",") > 0) {
ip = ip.substring(0, ip.indexOf(","));
}
}
return ip;
}
}
package com.clx.performance.config;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@Getter
@Setter
@ConfigurationProperties(prefix = "ali.slider")
public class AliSliderConfig {
private String accessKeyId;
private String accessKeySecret;
private String regionId;
private String product;
private String domain;
}
......@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
import java.util.List;
@Slf4j
......@@ -41,19 +42,19 @@ public class LargeScreenController {
@ApiOperation(value = "收货地址", notes = "<br>By:胡宇帆")
@GetMapping("/receiveAddress")
public String receiveAddress(@RequestParam(value = "addressId") Integer addressId) {
public String receiveAddress(@RequestParam(value = "addressId")@NotNull Integer addressId) {
return largeScreenService.receiveAddress(addressId);
}
@ApiOperation(value = "发货地址", notes = "<br>By:胡宇帆")
@GetMapping("/sendAddress")
public String sendAddress(@RequestParam(value = "addressId") Integer addressId) {
public String sendAddress(@RequestParam(value = "addressId") @NotNull Integer addressId) {
return largeScreenService.sendAddress(addressId);
}
@ApiOperation(value = "线路", notes = "<br>By:胡宇帆")
@GetMapping("/lineString")
public String lineString(@RequestParam(value = "addressId") Integer addressId) {
public String lineString(@RequestParam(value = "addressId")@NotNull Integer addressId) {
return largeScreenService.routeLine(addressId);
}
......
package com.clx.performance;
import cn.hutool.json.JSONObject;
import com.clx.message.feign.ClxMessageOpenapiFeign;
import com.clx.message.req.message.AliSmsMessageReq;
import com.clx.order.feign.OrderFeign;
import com.clx.performance.component.GoodsOrderTruckRecordComponent;
import com.clx.performance.component.OrderGoodsStatusLazyComponent;
import com.clx.performance.config.ClxMessageConfig;
import com.clx.performance.constant.RedisConstants;
import com.clx.performance.dao.LargeScreenAddressRouteDao;
import com.clx.performance.dao.OrderGoodsDao;
import com.clx.performance.service.LargeScreenService;
import com.clx.performance.service.OrderCancelService;
import com.clx.performance.service.OwnerAccountService;
import com.msl.common.result.Result;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;
......@@ -42,21 +51,37 @@ public class JobTest {
@Autowired
private LargeScreenService largeScreenService;
@Autowired
private LargeScreenAddressRouteDao largeScreenAddressRouteDao;
@Autowired
private OwnerAccountService ownerAccountService;
@Autowired
private ClxMessageOpenapiFeign clxMessageOpenapiFeign;
@Autowired
private ClxMessageConfig config;
@Autowired
private RedisTemplate<String,String> redisTemplate;
@Test
public void test1() {
String jsonObject = largeScreenService.receiveAddress(27);
System.out.println(jsonObject);
// OrderCancelMqParam mqParam = new OrderCancelMqParam();
// mqParam.setType("2");
// mqParam.setOrderNo("123");
// Message message = MessageBuilder.withBody(JSONUtil.parse(mqParam).toString().getBytes()).build();
// rabbitTemplate.send(
// RabbitKeyConstants.ORDER_CANCEL_EXCHANGE, RabbitKeyConstants.ORDER_CANCEL_ROUTE_KEY, message
// );
//orderCancelService.ownerCancelOrderPre("PT2023102700473");
//orderCancelService.ownerCancelOrder("PT2023102600466");
recordComponent.deleteTruckRecord("123");
System.out.println();
AliSmsMessageReq req = new AliSmsMessageReq();
req.setTemplateCode(config.getCaptchaTemplateCode());
JSONObject jsonObject = new JSONObject();
jsonObject.set("code", "222");
jsonObject.set("time", "12");
req.setChannelId(41);
req.setAppId("7134802354519449600");
req.setMobile("17610126377");
req.setContent(jsonObject.toString());
req.setExpire(300L);
Result<String> stringResult = clxMessageOpenapiFeign.sendAliSms(req);
System.out.println(stringResult);
String content = redisTemplate.opsForValue().get(RedisConstants.MESSAGE_MOBILE_CAPTCHA + "17610126377");
System.out.println(content);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论