diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index 3129e2d6..513918dc 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -18,6 +18,7 @@ ruoyi-common-sensitive ruoyi-common-datascope ruoyi-common-datasource + ruoyi-common-sms ruoyi-common diff --git a/ruoyi-common/ruoyi-common-sms/pom.xml b/ruoyi-common/ruoyi-common-sms/pom.xml new file mode 100644 index 00000000..eb3915b2 --- /dev/null +++ b/ruoyi-common/ruoyi-common-sms/pom.xml @@ -0,0 +1,59 @@ + + + + com.ruoyi + ruoyi-common + 3.6.4 + + 4.0.0 + + ruoyi-common-sms + + + ruoyi-common-sms 短信模块 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + + + + org.junit.jupiter + junit-jupiter-api + 5.7.0 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.7.0 + test + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + + + \ No newline at end of file diff --git a/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/XunDaYunXinAutoConfiguration.java b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/XunDaYunXinAutoConfiguration.java new file mode 100644 index 00000000..14ada60c --- /dev/null +++ b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/XunDaYunXinAutoConfiguration.java @@ -0,0 +1,24 @@ +package com.ruoyi.common.sms; + +import com.ruoyi.common.sms.component.SmsComponent; +import com.ruoyi.common.sms.properties.XunDaYunXinProperties; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +@Configuration +@EnableConfigurationProperties(XunDaYunXinProperties.class) +public class XunDaYunXinAutoConfiguration { + + @Bean + public SmsComponent smsComponent() { + return new SmsComponent(); + } + + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } +} diff --git a/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/component/SmsComponent.java b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/component/SmsComponent.java new file mode 100644 index 00000000..43e83526 --- /dev/null +++ b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/component/SmsComponent.java @@ -0,0 +1,145 @@ +package com.ruoyi.common.sms.component; + +import com.ruoyi.common.sms.entity.response.SmsEntity; +import com.ruoyi.common.sms.entity.response.SmsResponse; +import com.ruoyi.common.sms.properties.XunDaYunXinProperties; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +import java.util.*; + +@Slf4j +public class SmsComponent { + @Autowired + private XunDaYunXinProperties properties; + + @Autowired + private RestTemplate restTemplate; + + /** + * 点对点 + * + * @param mobileContentKvp 号码内容键值对 示例 {"15100000000":"【测试】test1","15100000001":"【测试】test2"} + * @return SmsResponse + */ + public SmsResponse sendP2PMsg(Map mobileContentKvp) { + Map extraParams = new HashMap<>(); + + for (Map.Entry entry : mobileContentKvp.entrySet()) { + String oldValue = entry.getValue(); + String newValue = replaceCode(properties.getTemplate(), oldValue); + entry.setValue(newValue); + } + extraParams.put("mobileContentKvp", mobileContentKvp); + return sendSmsRequest("p2p", extraParams, new ParameterizedTypeReference() { + }); + } + + + /** + * 发送群发信息 + * + * @param mobile 电话号码按照,分割 示例 "15100000000,15100000001" + * @param content 内容 一般为验证码 + * @return SmsResponse + */ + public SmsResponse sendGroupMsg(String mobile, String content) { + Map extraParams = new HashMap<>(); + extraParams.put("mobile", removeDuplicates(mobile)); + extraParams.put("content", replaceCode(properties.getTemplate(), content)); + return sendSmsRequest("send", extraParams, new ParameterizedTypeReference>() { + }); + } + + + public SmsResponse checkBalance() { + String url = properties.getBaseUrl() + "/smsv2"; + Map params = new HashMap<>(); + params.put("action", "balance"); + params.put("account", properties.getAccount()); + params.put("password", properties.getPassword()); + HttpEntity> requestEntity = new HttpEntity<>(params); + ResponseEntity> responseEntity = restTemplate.exchange( + url, + HttpMethod.POST, + requestEntity, + new ParameterizedTypeReference>() { + } + ); + return responseEntity.getBody(); + } + + /** + * 发送短信请求的通用方法,适用于不同的短信操作。 + * + * @param action 短信操作的类型,例如 "p2p"、"send" "balance"。 + * @param extraParams 附加的请求参数,具体取决于短信操作的需求。可以为 null。 + * @param responseType 返回值的泛型类型,用于指定响应的具体类型。 + * @param 响应体中泛型的类型参数。 + * @return 包含响应结果的 SmsResponse 对象,响应体中可能包含不同类型的数据。 + */ + private T sendSmsRequest(String action, Map extraParams, ParameterizedTypeReference responseType) { + // 拼接请求的 URL 地址 + String url = properties.getBaseUrl() + "/smsv2"; + + // 创建请求参数 Map,并填充必需的账户信息和操作类型 + Map params = new HashMap<>(); + params.put("action", action); // 设置请求的操作类型,如发送短信或查询余额 + params.put("account", properties.getAccount()); // 设置账户名 + params.put("password", properties.getPassword()); // 设置密码 + params.put("extno", properties.getExtno()); // 虚拟接入码 + + // 如果有额外的参数,则将它们添加到请求参数中 + if (extraParams != null) { + params.putAll(extraParams); + } + // 构建 HttpEntity 实体,包含请求参数 + HttpEntity> requestEntity = new HttpEntity<>(params); + + // 使用 RestTemplate 的 exchange 方法发送 POST 请求,并指定返回的泛型类型 + ResponseEntity responseEntity = restTemplate.exchange( + url, // 请求 URL + HttpMethod.POST, // HTTP 方法类型为 POST + requestEntity, // 请求体包含请求参数 + responseType // 指定返回类型的泛型引用,用于保留泛型信息 + ); + + // 返回响应体(根据调用方法传入的类型) + return responseEntity.getBody(); + } + + + /** + * 相同号码去重 + * + * @param input 字符串电话号码 逗号分隔符分割 + * @return String 去重之后的手机电话号码 + */ + private String removeDuplicates(String input) { + // 使用 LinkedHashSet 保持插入顺序并去重 + Set uniqueSet = new LinkedHashSet<>(Arrays.asList(input.split(","))); + if (uniqueSet.size() >= 1000) { + throw new IllegalArgumentException("群发不建议超过1000个电话号码"); + } + // 将去重后的集合转换回字符串 + return String.join(",", uniqueSet); + } + + /** + * 模板替换占位符 + * + * @param template 模板 + * @param code 实际值 + * @return 替换之后的模板 + */ + public String replaceCode(String template, String code) { + return template.replace("{code}", code); + } + + +} diff --git a/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/entity/package-info.java b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/entity/package-info.java new file mode 100644 index 00000000..b9279f72 --- /dev/null +++ b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/entity/package-info.java @@ -0,0 +1 @@ +package com.ruoyi.common.sms.entity; \ No newline at end of file diff --git a/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/entity/request/package-info.java b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/entity/request/package-info.java new file mode 100644 index 00000000..e5e92bf2 --- /dev/null +++ b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/entity/request/package-info.java @@ -0,0 +1 @@ +package com.ruoyi.common.sms.entity.request; \ No newline at end of file diff --git a/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/entity/response/SmsEntity.java b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/entity/response/SmsEntity.java new file mode 100644 index 00000000..d6ea9a76 --- /dev/null +++ b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/entity/response/SmsEntity.java @@ -0,0 +1,32 @@ +package com.ruoyi.common.sms.entity.response; + +public class SmsEntity { + private String mid; + private String mobile; + private int result; + + // Getters and Setters + public String getMid() { + return mid; + } + + public void setMid(String mid) { + this.mid = mid; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } + + public int getResult() { + return result; + } + + public void setResult(int result) { + this.result = result; + } +} diff --git a/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/entity/response/SmsResponse.java b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/entity/response/SmsResponse.java new file mode 100644 index 00000000..81927c34 --- /dev/null +++ b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/entity/response/SmsResponse.java @@ -0,0 +1,12 @@ +package com.ruoyi.common.sms.entity.response; + +import lombok.Data; + +import java.util.List; + +@Data +public class SmsResponse { + private Integer status; + private Integer balance; + private List list; +} diff --git a/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/properties/XunDaYunXinProperties.java b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/properties/XunDaYunXinProperties.java new file mode 100644 index 00000000..d277f006 --- /dev/null +++ b/ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/properties/XunDaYunXinProperties.java @@ -0,0 +1,40 @@ +package com.ruoyi.common.sms.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * 迅达云信短信 配置类 + */ +@Data +@ConfigurationProperties(prefix = "xundayunxin") +public class XunDaYunXinProperties { + /** + * 请求地址 + */ + private String baseUrl = "http://47.96.236.136:7862/"; + /** + * 账号 + */ + private String account = "932425"; + /** + * 密码 + */ + private String password = "alDE77Gmo"; + + /** + * 虚拟接入码 + */ + private String extno = "10690367"; + + /** + * 是否启用手机号加密 + */ + private boolean encryptionEnabled; + + /** + * 短信模板 + */ + private String template = "【信用秒租】验证码为:{code},您正在登录信用秒租,请在3分钟内完成验证,如非本人操作,请忽略本短信。"; + +} diff --git a/ruoyi-common/ruoyi-common-sms/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/ruoyi-common/ruoyi-common-sms/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..7d5434ba --- /dev/null +++ b/ruoyi-common/ruoyi-common-sms/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1,2 @@ +com.ruoyi.common.sms.XunDaYunXinAutoConfiguration +com.ruoyi.common.sms.component.SmsComponent \ No newline at end of file diff --git a/ruoyi-modules/ruoyi-system/pom.xml b/ruoyi-modules/ruoyi-system/pom.xml index b5708a5f..9af35a97 100644 --- a/ruoyi-modules/ruoyi-system/pom.xml +++ b/ruoyi-modules/ruoyi-system/pom.xml @@ -76,6 +76,17 @@ mybatis-plus-boot-starter + + org.springframework.boot + spring-boot-starter-test + + + + com.ruoyi + ruoyi-common-sms + 3.6.4 + + diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CommonController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CommonController.java index b85bf974..3cff17e4 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CommonController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CommonController.java @@ -33,12 +33,13 @@ public class CommonController extends BaseController /** * H5发送验证码 - * @param phone - * @return + * @param phone 手机号码 + * @return AjaxResult */ @GetMapping("/sendSms") - public AjaxResult getChannelBySign(@RequestParam("phone")String phone, HttpServletRequest request){ - return commonService.sendSms(phone); + public AjaxResult sendSms(@RequestParam("phone")String phone, HttpServletRequest request){ + String header = request.getHeader("x-sms-source"); + return commonService.sendSms(phone,header); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CustomerController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CustomerController.java index ca7bb8e9..e9f2a604 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CustomerController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CustomerController.java @@ -175,4 +175,10 @@ public class CustomerController extends BaseController { return success(merchantService.findAllMerchantList()); } + + + @PostMapping("/v1/saveCustomerInfo") + public AjaxResult v1SaveCustomerInfo(@RequestBody Customer customer, HttpServletRequest request){ + return customerService.v1SaveCustomerInfo(customer,request); + } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/MerchantController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/MerchantController.java index 64b2ba1a..01e2c0a9 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/MerchantController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/MerchantController.java @@ -148,4 +148,10 @@ public class MerchantController extends BaseController } + @GetMapping("/v1/getMatchMerchant") + public AjaxResult V1GetMatchMerchant(HttpServletRequest request){ + return merchantService.V1GetMatchMerchant(request); + } + + } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/ProcessHandler.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/ProcessHandler.java new file mode 100644 index 00000000..5ae449f0 --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/ProcessHandler.java @@ -0,0 +1,12 @@ +package com.ruoyi.system.process; + +import com.ruoyi.common.core.web.domain.AjaxResult; + +/** + *根据流程类型 执行不同的处理器 + */ +public interface ProcessHandler { + + + AjaxResult invoke(); +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/enums/ProcessHandlerEnum.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/enums/ProcessHandlerEnum.java new file mode 100644 index 00000000..c2c53f2b --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/enums/ProcessHandlerEnum.java @@ -0,0 +1,36 @@ +package com.ruoyi.system.process.enums; + +import com.ruoyi.common.core.exception.ServiceException; + +public enum ProcessHandlerEnum { + + H5_HANDLER("H5_HANDLER", "H5Handler"), + HALF_HANDLER("HALF_HANDLER", "HalfHandler"); + final String code; + + final String name; + + public String getCode() { + return code; + } + + public String getName() { + return name; + } + + ProcessHandlerEnum(String code, String name) { + this.code = code; + this.name = name; + } + + public static String getNameByCode(String code) { + ProcessHandlerEnum[] processHandlerEnums = values(); + for (ProcessHandlerEnum processHandlerEnum : processHandlerEnums) { + if (processHandlerEnum.getCode().equals(code)) { + return processHandlerEnum.getName(); + } + } + String msg = String.format("请检查对应的流程处理器是否实现,编码为:%s", code); + throw new ServiceException(msg, 500); + } +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/handler/H5Handler.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/handler/H5Handler.java new file mode 100644 index 00000000..e7bbf24c --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/handler/H5Handler.java @@ -0,0 +1,14 @@ +package com.ruoyi.system.process.handler; + +import com.ruoyi.common.core.web.domain.AjaxResult; +import com.ruoyi.system.process.ProcessHandler; +import org.springframework.stereotype.Component; + +@Component(value = "H5Handler") +public class H5Handler implements ProcessHandler { + @Override + public AjaxResult invoke() { + return null; + + } +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/handler/HalfHandler.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/handler/HalfHandler.java new file mode 100644 index 00000000..a20a6877 --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/handler/HalfHandler.java @@ -0,0 +1,13 @@ +package com.ruoyi.system.process.handler; + +import com.ruoyi.common.core.web.domain.AjaxResult; +import com.ruoyi.system.process.ProcessHandler; +import org.springframework.stereotype.Component; + +@Component(value = "HalfHandler") +public class HalfHandler implements ProcessHandler { + @Override + public AjaxResult invoke() { + return null; + } +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/package-info.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/package-info.java new file mode 100644 index 00000000..b5f86171 --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/process/package-info.java @@ -0,0 +1 @@ +package com.ruoyi.system.process; \ No newline at end of file diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ICommonService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ICommonService.java index b8de1bbb..e2a04094 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ICommonService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ICommonService.java @@ -20,5 +20,5 @@ public interface ICommonService * @param phone * @return */ - AjaxResult sendSms(String phone); + AjaxResult sendSms(String phone,String smsSource); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ICustomerService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ICustomerService.java index 11dd7587..17d3bf69 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ICustomerService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ICustomerService.java @@ -109,4 +109,6 @@ public interface ICustomerService extends IService * @return */ AjaxResult saveCustomerInfo(Customer customer, HttpServletRequest request); + + AjaxResult v1SaveCustomerInfo(Customer customer, HttpServletRequest request); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/IMerchantService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/IMerchantService.java index b61f53e5..e6b7e877 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/IMerchantService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/IMerchantService.java @@ -93,4 +93,6 @@ public interface IMerchantService extends IService AjaxResult H5applyMerchant(Long merchantId, HttpServletRequest request); AjaxResult getMatchMerchantNew(); + + AjaxResult V1GetMatchMerchant(HttpServletRequest request); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java index 059576c0..0232f8e9 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java @@ -3,43 +3,100 @@ package com.ruoyi.system.service.impl; import com.ruoyi.common.core.constant.RedisConstant; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.redis.service.RedisService; +import com.ruoyi.common.sms.component.SmsComponent; import com.ruoyi.system.service.ICommonService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; + import java.security.SecureRandom; +import java.util.*; import java.util.concurrent.TimeUnit; /** * 渠道配置Service业务层处理 - * + * * @author ruoyi * @date 2024-09-15 */ @Service -public class CommonServiceImpl implements ICommonService -{ +public class CommonServiceImpl implements ICommonService { @Autowired private RedisService redisService; + @Autowired + private SmsComponent smsComponent; + + + @Autowired + private Environment environment; + @Override - public AjaxResult sendSms(String phone) { - if (StringUtils.isEmpty(phone)){ + public AjaxResult sendSms(String phone, String smsSource) { + if (StringUtils.isEmpty(phone)) { return AjaxResult.error("手机号未空"); } - if (phone.length()!=11){ + if (phone.length() != 11) { return AjaxResult.error("手机号长度异常"); } - //发送验证码 - SecureRandom secureRandom = new SecureRandom(); - int code = secureRandom.nextInt(9000) + 1000; - - //发送验证码工具类 + //正式环境发送验证码 pc4位 h5注册页6位 + String code; + // 判断是否为正式环境 + if (isProductionProfileActive()) { + //正式环境操作 + code = smsSource.equalsIgnoreCase("h5") ? generateCode(6) : generateCode(4); + // 发送短信 + Map params = new HashMap<>(); + params.put(phone, code); + smsComponent.sendP2PMsg(params); + } else { + // 非正式环境直接设置固定验证码 + code = smsSource.equalsIgnoreCase("h5") ? "123456" : "1234"; + } //放入缓存 3分钟 - redisService.setCacheObject(RedisConstant.H5_LOGIN_CACHE+phone,1234,3*60l, TimeUnit.SECONDS); - + redisService.setCacheObject(RedisConstant.H5_LOGIN_CACHE + phone, code, 3 * 60L, TimeUnit.SECONDS); return AjaxResult.success("发送成功"); } + + /** + * 判断当前活跃环境是否是 正式环境 + * if (isProductionProfileActive()) { + * // 进行与生产环境相关的逻辑处理 + * } else { + * // 进行非生产环境的处理 + * } + * + * @return + */ + public boolean isProductionProfileActive() { + // 获取当前应用的活跃环境 + String[] activeProfiles = environment.getActiveProfiles(); + + // 定义线上环境列表 + List proList = new ArrayList<>(Arrays.asList("prod", "pro")); + + // 检查活跃环境是否包含在 proList 中 + for (String profile : activeProfiles) { + if (proList.contains(profile)) { + return true; // 如果有活跃环境在 proList 中,返回 true + } + } + return false; // 如果没有匹配的环境,返回 false + } + + /** + * 定义生成验证码的方法 + * + * @param length 验证码长度 + * @return + */ + private String generateCode(int length) { + SecureRandom secureRandom = new SecureRandom(); + int bound = (int) Math.pow(10, length); + int min = bound / 10; + return String.valueOf(secureRandom.nextInt(bound - min) + min); + } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CustomerServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CustomerServiceImpl.java index 89e0cc42..a565529f 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CustomerServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CustomerServiceImpl.java @@ -254,5 +254,29 @@ public class CustomerServiceImpl extends ServiceImpl i return AjaxResult.success("保存成功"); } + @Override + public AjaxResult v1SaveCustomerInfo(Customer customer, HttpServletRequest request) { + String authorization = request.getHeader("Authorization"); + Long customerId = customerTokenService.getCustomerId(authorization, false); + String sign = request.getHeader("sign"); + if (StringUtils.isEmpty(sign)) { + return AjaxResult.error("渠道标识不存在"); + } + Channel channel = redisService.getCacheObject(CacheConstants.CHANNEL_SIGN + sign); + if (customerId == null) { + return AjaxResult.error("用户不存在或未登录"); + } + + if (StringUtils.isEmpty(customer.getActurlName())) { + return AjaxResult.error("姓名不能为空"); + } + customer.setId(customerId); + customer.setChannelId(channel.getId()); + customer.setIsAuth(true); + customer.setStatus(1); + updateById(customer); + return AjaxResult.success("保存成功"); + } + } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/MerchantServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/MerchantServiceImpl.java index 49e7f8bd..9efc4cb7 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/MerchantServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/MerchantServiceImpl.java @@ -235,6 +235,28 @@ public class MerchantServiceImpl extends ServiceImpl i return AjaxResult.success(results); } + @Override + public AjaxResult V1GetMatchMerchant(HttpServletRequest request) { + + String authorization = request.getHeader("Authorization"); + Long customerId = customerTokenService.getCustomerId(authorization, false); + if (customerId==null){ + return AjaxResult.error("用户不存在或未登录"); + } + Customer customer = customerMapper.selectById(customerId); + List merchants = matchMerchant(customer); + List merchantListDtos = new ArrayList<>(); + for (Merchant merchant:merchants) { + MerchantListDto merchantListDto = new MerchantListDto(); + merchantListDto.setMerchantName(merchant.getMerchantName()); + merchantListDto.setMerchantDescribe(merchant.getMerchantDescribe()); + merchantListDto.setMerchantUrl(merchant.getHitUrl()); + merchantListDto.setMerchantId(merchant.getId()); + merchantListDtos.add(merchantListDto); + } + return AjaxResult.success(merchantListDtos); + } + private List getMerchantLists() { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().eq(Merchant::getStatus, true); diff --git a/ruoyi-modules/ruoyi-system/src/test/java/com/ruoyi/system/RuoYiSystemApplicationTest.java b/ruoyi-modules/ruoyi-system/src/test/java/com/ruoyi/system/RuoYiSystemApplicationTest.java new file mode 100644 index 00000000..db1ef545 --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/test/java/com/ruoyi/system/RuoYiSystemApplicationTest.java @@ -0,0 +1,48 @@ +package com.ruoyi.system; + +import cn.hutool.json.JSONUtil; +import com.ruoyi.common.sms.component.SmsComponent; +import com.ruoyi.common.sms.entity.response.SmsResponse; +import org.assertj.core.util.Maps; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.HashMap; +import java.util.Map; + +import static cn.hutool.extra.spring.SpringUtil.getActiveProfile; + +@SpringBootTest +public class RuoYiSystemApplicationTest { + + @Autowired + SmsComponent smsComponent; + + @Test + public void testGroupMsg(){ + + String mobile = "15826189779,15826189779,17382317154"; + String content = "123456"; + + SmsResponse groupMsg = smsComponent.sendGroupMsg(mobile, content); + System.out.println(JSONUtil.toJsonStr(groupMsg)); + } + + @Test + public void testP2pMsg(){ + + String content = "123456"; + Map params = new HashMap<>(); + params.put("15826189779", content); + SmsResponse sendP2PMsg = smsComponent.sendP2PMsg(params); + System.out.println(JSONUtil.toJsonStr(sendP2PMsg)); + } + + @Test + public void getActivePro(){ + + String activeProfile = getActiveProfile(); + System.out.println(activeProfile); + } +}