Răsfoiți Sursa

国际短信

zoujiajian 3 ani în urmă
părinte
comite
e4461a01d4

+ 8 - 1
netflix-common/src/main/java/com/cyksj/common/util/SmsUtil.java

@@ -41,6 +41,9 @@ public class SmsUtil {
 
     private static final String TENCENT_SMS_TEMPLATE_ID = "1705927";
 
+    //国际腾讯云短信
+    private static final String TENCENT_SMS_INTERNATIONAL_TEMPLATE_ID = "1705927";
+
     private static final Logger log = LoggerFactory.getLogger(SmsUtil.class);
 
     public static void main(String[] args) {
@@ -83,7 +86,7 @@ public class SmsUtil {
         return false;
     }
 
-    public static void sendTencent(String mobile, String msg) {
+    public static void sendTencent(Integer cid, String mobile, String msg) {
         try {
             /* 必要步骤:
              * 实例化一个认证对象,入参需要传入腾讯云账户密钥对secretId,secretKey。
@@ -129,6 +132,9 @@ public class SmsUtil {
 
             /* 模板 ID: 必须填写已审核通过的模板 ID */
             String templateId = TENCENT_SMS_TEMPLATE_ID;
+            if (cid != 86) {
+                templateId = TENCENT_SMS_INTERNATIONAL_TEMPLATE_ID;
+            }
             req.setTemplateId(templateId);
 
             /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */
@@ -137,6 +143,7 @@ public class SmsUtil {
 
             /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号]
              * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */
+            mobile = String.format("+%s%s", cid, mobile);
             String[] phoneNumberSet = {mobile};
             req.setPhoneNumberSet(phoneNumberSet);
 

+ 2 - 1
netflix-service/src/main/java/com/cyksj/service/cps/CpsManageService.java

@@ -17,9 +17,10 @@ public interface CpsManageService {
 	/**
 	 * 获取登录验证码
 	 * @param type 1手机号、2邮箱
+	 * @param cid 国家或地区id +86
 	 * @param login
 	 */
-	void getLoginCode(Integer type, String login);
+	void getLoginCode(Integer type, String login, Integer cid);
 
 	User login(Integer type, String login, String code);
 

+ 5 - 2
netflix-service/src/main/java/com/cyksj/service/cps/impl/CpsManageServiceImpl.java

@@ -41,10 +41,13 @@ public class CpsManageServiceImpl implements CpsManageService {
 	private final UserDistributeMapper userDistributeMapper;
 
 	@Override
-	public void getLoginCode(Integer type, String login) {
+	public void getLoginCode(Integer type, String login, Integer cid) {
 		if (type > 2) {
 			throw BusinessRuntimeException.getInstance("");
 		}
+		if (cid == null) {
+			cid = 86;
+		}
 		//是否是渠道分销用户
 		String phone = null;
 		String email = null;
@@ -63,7 +66,7 @@ public class CpsManageServiceImpl implements CpsManageService {
 			if (!Validator.isMobile(login)) {
 				throw BusinessRuntimeException.getInstance("请输入正确的手机号");
 			}
-			SmsUtil.sendTencent(login, code);
+			SmsUtil.sendTencent(cid, login, code);
 		} else if (type == 2) {
 			if (!Validator.isEmail(login)) {
 				throw BusinessRuntimeException.getInstance("请输入正确的邮箱");

+ 2 - 2
netflix-web/src/main/java/com/cyksj/web/controller/cps/CpsBackLoginController.java

@@ -80,8 +80,8 @@ public class CpsBackLoginController {
 	 */
 	@GetMapping("/get/LoginCode")
 	@NoSubmit
-	public Result getLoginCode(@RequestParam(defaultValue = "1") Integer type, String login) {
-		cpsManageService.getLoginCode(type, login);
+	public Result getLoginCode(@RequestParam(defaultValue = "1") Integer type, String login, Integer cid) {
+		cpsManageService.getLoginCode(type, login, cid);
 		return GatewayResponse.SUCCESS.newBuilder().toResult();
 	}
 

+ 3 - 3
netflix-web/src/main/java/com/cyksj/web/controller/user/AuthorizationController.java

@@ -317,11 +317,11 @@ public class AuthorizationController {
      */
     @GetMapping("/get/phone/code")
     @NoSubmit
-    public Result<String> getPhoneCode(String phone, Integer digit, @RequestParam(defaultValue = "0") Boolean isFree) {
+    public Result<String> getPhoneCode(String phone, Integer digit, @RequestParam(defaultValue = "0") Boolean isFree, Integer cid) {
         if (StrUtil.isBlank(phone) || !Validator.isMobile(phone)) {
             throw BusinessRuntimeException.getInstance("请输入正确手机号");
         }
-
+        if (cid == null) cid = 86;
         PhoneCode phoneCode = phoneCodeMapper.selectOne(Wrappers.lambdaQuery(PhoneCode.class).eq(PhoneCode::getPhone, phone).last("limit 1"));
         if (phoneCode == null) {
             phoneCode = new PhoneCode();
@@ -333,7 +333,7 @@ public class AuthorizationController {
             phoneCodeMapper.insert(phoneCode);
         } else phoneCodeMapper.updateById(phoneCode);
         if (!isFree) {
-            SmsUtil.sendTencent(phone, code);
+            SmsUtil.sendTencent(cid, phone, code);
         } else {
             // 发送短信
             SmsUtil.sendLuoKey2Msg(phone, String.format("尊敬的用户,您的验证码为%s,此验证码仅用于银河录像。【银河录像局】", code));