feat: 1:手机号发送验证码

2:手机号验证码登录
This commit is contained in:
2026-01-22 16:10:32 +08:00
parent 98304d27b7
commit 8d8ec86a8a
34 changed files with 2466 additions and 641 deletions
@@ -24,4 +24,9 @@ public interface ServiceNameConstants {
String FILE_SERVICE = "file-center";
String ORDER_SERVICE = "order-center";
/**
* 消息中心服务
*/
String MSG_SERVICE = "msg-center";
}
@@ -0,0 +1,45 @@
package com.central.common.feign;
import com.central.common.constant.ServiceNameConstants;
import com.central.common.feign.fallback.MsgCenterServiceFallbackFactory;
import com.central.common.model.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* 消息中心服务 Feign客户端
*/
@FeignClient(name = ServiceNameConstants.MSG_SERVICE, fallbackFactory = MsgCenterServiceFallbackFactory.class, dismiss404 = true)
public interface MsgCenterService {
/**
* 发送验证码短信(使用默认服务商)
*
* @param phone 手机号
* @param code 验证码
* @return 发送结果
*/
@PostMapping("/sms/send-verify-code")
Result<?> sendVerifyCode(@RequestParam("phone") String phone, @RequestParam("code") String code);
/**
* 发送验证码短信(使用腾讯云)
*
* @param phone 手机号
* @param code 验证码
* @return 发送结果
*/
@PostMapping("/sms/tencent/send-verify-code")
Result<?> sendTencentVerifyCode(@RequestParam("phone") String phone, @RequestParam("code") String code);
/**
* 发送验证码短信(使用阿里云)
*
* @param phone 手机号
* @param code 验证码
* @return 发送结果
*/
@PostMapping("/sms/aliyun/send-verify-code")
Result<?> sendAliyunVerifyCode(@RequestParam("phone") String phone, @RequestParam("code") String code);
}
@@ -8,6 +8,7 @@ import com.central.common.model.SysUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@@ -91,4 +92,13 @@ public interface UserService {
*/
@GetMapping(value = "/tenant/hierarchy/son/tenantId", params = "tenantId")
List<String> getSonTenantIds(@RequestParam("tenantId") String tenantId);
/**
* 通过手机号注册用户(返回用户信息,包含openId)
*
* @param mobile 手机号
* @return 注册后的用户信息
*/
@PostMapping(value = "/users-anon/register/mobile")
SysUser registerByMobile(@RequestParam("mobile") String mobile);
}
@@ -0,0 +1,35 @@
package com.central.common.feign.fallback;
import com.central.common.feign.MsgCenterService;
import com.central.common.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
/**
* MsgCenterService降级工厂
*/
@Slf4j
public class MsgCenterServiceFallbackFactory implements FallbackFactory<MsgCenterService> {
@Override
public MsgCenterService create(Throwable throwable) {
return new MsgCenterService() {
@Override
public Result<?> sendVerifyCode(String phone, String code) {
log.error("发送验证码短信异常, phone:{}", phone, throwable);
return Result.failed("短信服务不可用");
}
@Override
public Result<?> sendTencentVerifyCode(String phone, String code) {
log.error("发送腾讯云验证码短信异常, phone:{}", phone, throwable);
return Result.failed("腾讯云短信服务不可用");
}
@Override
public Result<?> sendAliyunVerifyCode(String phone, String code) {
log.error("发送阿里云验证码短信异常, phone:{}", phone, throwable);
return Result.failed("阿里云短信服务不可用");
}
};
}
}
@@ -89,6 +89,12 @@ public class UserServiceFallbackFactory implements FallbackFactory<UserService>
log.error("获取自己以及子孙租户列表异常:{}", tenantId, throwable);
return Collections.emptyList();
}
@Override
public SysUser registerByMobile(String mobile) {
log.error("通过手机号注册用户异常:{}", mobile, throwable);
return null;
}
};
}
}
@@ -1,2 +1,3 @@
com.central.common.feign.fallback.UserServiceFallbackFactory
com.central.common.feign.fallback.MsgCenterServiceFallbackFactory
com.central.common.lock.LockAspect