3/25 安溪接口优化

dev_ksck_axxyy
wangwei 1 week ago
parent 85a71fbb88
commit b44e1ba287

@ -19,10 +19,7 @@ import com.glxp.api.entity.basic.BasicUnitMaintainEntity;
import com.glxp.api.entity.purchase.CustomerContactEntity;
import com.glxp.api.entity.system.CompanyEntity;
import com.glxp.api.entity.system.SystemParamConfigEntity;
import com.glxp.api.req.auth.CustomerInfoFilterRequest;
import com.glxp.api.req.auth.RegisterCheckRequest;
import com.glxp.api.req.auth.ResetPasswdRequest;
import com.glxp.api.req.auth.UserResisterFilterRequest;
import com.glxp.api.req.auth.*;
import com.glxp.api.req.info.FilterAliCertRequest;
import com.glxp.api.req.system.DeleteRequest;
import com.glxp.api.res.PageSimpleResponse;
@ -38,6 +35,7 @@ import com.glxp.api.service.system.SystemParamConfigService;
import com.glxp.api.util.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.util.LinkedMultiValueMap;
@ -47,6 +45,9 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.util.*;
@ -57,6 +58,9 @@ public class RegisterController {
private static String Url = "http://106.ihuyi.com/webservice/sms.php?method=Submit";
private static final String KEY = "1234567812345678";
private static final String IV = "1234567812345678";
@Resource
UserRegisterService userRegisterService;
@Resource
@ -112,34 +116,14 @@ public class RegisterController {
}
}
int mobile_code = (int) ((Math.random() * 9 + 1) * 100000);
JSONObject json = new JSONObject();
json.put("memPhone", checkCodeRequest.getPhoneNum());
json.put("code", mobile_code);
json.put("createTime", System.currentTimeMillis() + "");
// 先将验证码存入 redis 中
// 先将验证码存入 redis 中
redisUtil.set(Constant.CAPTCHAS + checkCodeRequest.getPhoneNum(), json, 300L);
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>();
int time = 5;
String content = new String("您正在进行手机验证,验证码是" + mobile_code + "" + time + "分钟内有效。");
postParameters.add("account", "C07086222");
postParameters.add("password", "2dddbbf73636c193c5903324bdb47c5c");
postParameters.add("mobile", checkCodeRequest.getPhoneNum());
postParameters.add("content", content);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/x-www-form-urlencoded;charset=GBK");
HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(postParameters, headers);
String response = restTemplate.postForObject(Url, httpEntity, String.class);
if (response.contains("提交成功")) {
return ResultVOUtils.success("发送成功!");
} else {
// 如果短信发送失败,可考虑删除 Redis 中的验证码,这里简单返回错误信息
return ResultVOUtils.error(500, "验证码发送失败");
}
return ResultVOUtils.success("发送成功!请联系维护人员获取验证码");
}
@GetMapping("salewarehouse/register/checkCompany")
@ -210,13 +194,28 @@ public class RegisterController {
}
@PostMapping("salewarehouse/register/save")
public BaseResponse saveRegister(@RequestBody @Valid UserRegisterEntity userRegisterEntity, HttpSession httpSession,
BindingResult bindingResult) {
public BaseResponse saveRegister(@RequestBody @Valid UserRegisterEntityRequest userRegisterEntityRequest, HttpSession httpSession,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
String codeStr = String.valueOf(redisUtil.get(Constant.CAPTCHAS + userRegisterEntity.getMobile()));
try {
userRegisterEntityRequest.setPassword(decrypt(userRegisterEntityRequest.getPassword()));
userRegisterEntityRequest.setMobile(decrypt(userRegisterEntityRequest.getMobile()));
userRegisterEntityRequest.setCheckCode(decrypt(userRegisterEntityRequest.getCheckCode() + ""));
userRegisterEntityRequest.setEmail(decrypt(userRegisterEntityRequest.getEmail()));
userRegisterEntityRequest.setTel(decrypt(userRegisterEntityRequest.getTel()));
userRegisterEntityRequest.setCreditNum(decrypt(userRegisterEntityRequest.getCreditNum()));
userRegisterEntityRequest.setBussinessStatus(decrypt(userRegisterEntityRequest.getBussinessStatus() + ""));
} catch (Exception e) {
e.printStackTrace();
return ResultVOUtils.error(500, "系统错误");
}
String codeStr = String.valueOf(redisUtil.get(Constant.CAPTCHAS + userRegisterEntityRequest.getMobile()));
if (StrUtil.isBlank(codeStr) || "null".equals(codeStr)) {
return ResultVOUtils.error(500, "验证码已过期,请重新获取");
}
@ -230,19 +229,20 @@ public class RegisterController {
if ((System.currentTimeMillis() - lastTime) > 1000 * 60 * 5) {
return ResultVOUtils.error(500, "验证码已过期,请重新获取");
}
if (checkCode != userRegisterEntity.getCheckCode()) {
Integer checkCode1 = Integer.valueOf(userRegisterEntityRequest.getCheckCode());
if (checkCode != checkCode1) {
return ResultVOUtils.error(500, "验证码错误,请重新获取");
}
if (!phoneNum.equals(userRegisterEntity.getMobile())) {
if (!phoneNum.equals(userRegisterEntityRequest.getMobile())) {
return ResultVOUtils.error(500, "手机号与获取验证码不一致");
}
boolean isExitPhone = userRegisterService.isExit(userRegisterEntity.getMobile());
boolean isExitPhone = userRegisterService.isExit(userRegisterEntityRequest.getMobile());
if (isExitPhone) {
return ResultVOUtils.error(500, "该手机号已被注册");
}
//校验邮箱是否正确
if (StrUtil.isNotBlank(userRegisterEntity.getEmail())) {
boolean match = ReUtil.isMatch("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", userRegisterEntity.getEmail());
if (StrUtil.isNotBlank(userRegisterEntityRequest.getEmail())) {
boolean match = ReUtil.isMatch("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", userRegisterEntityRequest.getEmail());
if (!match) {
return ResultVOUtils.error(500, "邮箱格式错误");
}
@ -251,20 +251,21 @@ public class RegisterController {
String company_check = systemParamConfigService.selectValueByParamKey("register_company_check");
if (StrUtil.isNotBlank(company_check) && company_check.equals("1")) {
//新用户注册时根据往来单位字典进行企业名称校验
CustomerInfoEntity customerInfoEntity = customerInfoService.selectById(userRegisterEntity.getCompanyId());
CustomerInfoEntity customerInfoEntity = customerInfoService.selectById(userRegisterEntityRequest.getCompanyId());
if (customerInfoEntity != null) {
return ResultVOUtils.error(500, "该企业已被注册!");
}
}
UserRegisterEntity userRegisterEntity2 = userRegisterService.selectByCname(userRegisterEntity.getCompanyName());
UserRegisterEntity userRegisterEntity2 = userRegisterService.selectByCname(userRegisterEntityRequest.getCompanyName());
if (userRegisterEntity2 != null) {
return ResultVOUtils.error(500, "该企业已被注册!");
}
userRegisterEntity.setRegisterTime(DateUtil.getDateTime());
userRegisterEntity.setCheckType(0);//未审核
userRegisterEntityRequest.setRegisterTime(DateUtil.getDateTime());
userRegisterEntityRequest.setCheckType(0);//未审核
String userName = UuidUtils.getShortUuid(4);
switch (userRegisterEntity.getBussinessStatus()) {
Integer bussinessStatus = Integer.valueOf(userRegisterEntityRequest.getBussinessStatus());
switch (bussinessStatus) {
case 1:
userName = "YY" + userName;
break;
@ -275,20 +276,43 @@ public class RegisterController {
userName = "JYQY" + userName;
break;
}
userRegisterEntity.setUserName(userName);
UserRegisterEntity userRegisterEntity1 = userRegisterService.selectByMobile(userRegisterEntity.getMobile());
userRegisterEntityRequest.setUserName(userName);
UserRegisterEntity userRegisterEntity1 = userRegisterService.selectByMobile(userRegisterEntityRequest.getMobile());
if (userRegisterEntity1 != null) {
userRegisterService.deleteByMobile(userRegisterEntity.getMobile(), 2);
userRegisterService.deleteByMobile(userRegisterEntityRequest.getMobile(), 2);
}
UserRegisterEntity userRegisterEntity = new UserRegisterEntity();
BeanUtils.copyProperties(userRegisterEntityRequest, userRegisterEntity);
userRegisterEntity.setBussinessStatus(bussinessStatus);
boolean b = userRegisterService.insertUserRegister(userRegisterEntity);
if (!b) {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
//注册成功,删除验证码缓存
redisUtil.del(Constant.CAPTCHAS + userRegisterEntity.getMobile());
return ResultVOUtils.success(userRegisterEntity.getUserName());
redisUtil.del(Constant.CAPTCHAS + userRegisterEntityRequest.getMobile());
return ResultVOUtils.success(userRegisterEntityRequest);
}
public static String decrypt(String encryptedData) throws Exception {
// 检查输入的 Base64 字符串是否合法
try {
Base64.getDecoder().decode(encryptedData);
} catch (IllegalArgumentException e) {
System.err.println("输入的 Base64 字符串格式不正确: " + e.getMessage());
return null;
}
SecretKeySpec skeySpec = new SecretKeySpec(KEY.getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
IvParameterSpec ivSpec = new IvParameterSpec(IV.getBytes("UTF-8"));
cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivSpec);
byte[] encrypted = Base64.getDecoder().decode(encryptedData);
byte[] original = cipher.doFinal(encrypted);
return new String(original, "UTF-8");
}
@PostMapping("salewarehouse/reset/passwd")
public BaseResponse resetPasswd(@RequestBody @Valid ResetPasswdRequest resetPasswdRequest, HttpSession httpSession,
BindingResult bindingResult) {

@ -0,0 +1,44 @@
package com.glxp.api.req.auth;
import com.glxp.api.constant.Constant;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
/**
* @author : zhuzhu
* @date : 2025/3/24 15:02
* @modyified By :
*/
@Data
public class UserRegisterEntityRequest {
private Integer id;
private String nickName;
@NotEmpty(message = "请输入密码")
private String password;
private String realName;
private String tel;
private String mobile;
private String userId;
private String email;
private String companyId;
private String companyName;
private String creditNum;
private String area;
private String detailAddr;
private String bussinessStatus;
private Integer checkType;
private String registerTime;
private String checkTime;
private String comments;
private String checkCode;
private String areaCode;
private String userName;
private String licenseUrl;
private String udplatCompanyName;
private String udplatCompanyId;
}
Loading…
Cancel
Save