Jelajahi Sumber

获取手机临时验证码接口

zoujiajian 1 tahun lalu
induk
melakukan
cb13bfc193

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/corp/CorpUserService.java

@@ -23,4 +23,6 @@ public interface CorpUserService {
 	void markCorpUser(CorpCommonReq corpCommonReq) throws Exception;
 
 	void spotifySelfService(Long orderId);
+
+	String getPhoneTmpCode(String phone);
 }

+ 18 - 0
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpUserServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.common.util.StringUtil;
 import com.cyksj.config.corp.WeChatCorpFactory;
 import com.cyksj.mapper.*;
 import com.cyksj.mapper.corp.CorpFollowMapper;
@@ -74,6 +75,8 @@ public class CorpUserServiceImpl implements CorpUserService {
 
 	private final CmsUserMapper cmsUserMapper;
 
+	private final PhoneCodeMapper phoneCodeMapper;
+
 	@Override
 	public YHLXUserDetailView getUserDetailView(String externalUserid, String corpId) throws Exception {
 		CorpUser corpUser = getExternalUserId(corpId, externalUserid);
@@ -267,6 +270,21 @@ public class CorpUserServiceImpl implements CorpUserService {
 		}
 	}
 
+	@Override
+	public String getPhoneTmpCode(String phone) {
+		PhoneCode phoneCode = phoneCodeMapper.selectOne(Wrappers.lambdaQuery(PhoneCode.class)
+				.eq(PhoneCode::getPhone, phone).last("limit 1"));
+		if (phoneCode == null) {
+			phoneCode = new PhoneCode();
+		}
+		String code = StringUtil.getRandomCodeStr(null);
+		phoneCode.setCode(code);
+		if (phoneCode.getId() == null) {
+			phoneCodeMapper.insert(phoneCode);
+		} else phoneCodeMapper.updateById(phoneCode);
+		return code;
+	}
+
 	public CorpUser getExternalUserId(String corpId, String externalUserid) throws Exception {
 		WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpId);
 

+ 16 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/corp/WxCorpController.java

@@ -553,4 +553,20 @@ public class WxCorpController {
 		chatGptAccountService.clearGptNum(relationId);
 		return GatewayResponse.SUCCESS.newBuilder().toResult();
 	}
+
+	/**
+	 * 获取手机临时验证码
+	 */
+	@GetMapping("/get/tmp/code")
+	public Result<String> getPhoneTmpCode(String phone) throws Exception {
+		String corpUuid = getCorpUuid();
+		if (StrUtil.isEmpty(corpUuid)) {
+			return GatewayResponse.SUCCESS.newBuilder().toResult();
+		}
+		if (StrUtil.isEmpty(phone)) {
+			throw BusinessRuntimeException.getInstance("请输入手机号");
+		}
+		String code = corpUserService.getPhoneTmpCode(phone);
+		return GatewayResponse.SUCCESS.newBuilder().toResult(code);
+	}
 }