소스 검색

国际短信

zoujiajian 3 년 전
부모
커밋
6952eb05f1

+ 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);
 

+ 29 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/PhoneAreaCode.java

@@ -0,0 +1,29 @@
+package com.cyksj.model.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Getter;
+import lombok.Setter;
+
+/*
+ *项目名: netflix
+ *文件名: PhoneAreaCode
+ *创建者: JavaZou
+ *创建时间:2023/6/21 14:48
+ */
+@Getter
+@Setter
+public class PhoneAreaCode {
+	@TableId(type = IdType.AUTO)
+	private Integer id;
+
+	private String nameCn;
+
+	private String nameUs;
+
+	private Integer areaCode;
+
+	private String continent;
+
+	private Integer sorted;
+}

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/PhoneCode.java

@@ -15,4 +15,6 @@ public class PhoneCode extends BaseEntity{
 	private String phone;
 
 	private String code;
+
+	private Integer cid;
 }

+ 28 - 0
netflix-dao/src/main/java/com/cyksj/model/views/PhoneAreaCodeView.java

@@ -0,0 +1,28 @@
+package com.cyksj.model.views;
+
+import com.ejlchina.searcher.bean.SearchBean;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+
+/*
+ *项目名: netflix
+ *文件名: PhoneAreaCodeView
+ *创建者: JavaZou
+ *创建时间:2023/6/21 14:16
+ */
+@Getter
+@Setter
+@SearchBean(tables = "phone_area_code",
+		orderBy = "sorted desc")
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class PhoneAreaCodeView implements Serializable {
+
+	private String nameCn;
+
+	private String nameUs;
+
+	private Integer areaCode;
+}

+ 1 - 0
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -609,6 +609,7 @@ public class RedisService {
         QUESTION_RESPONSE_KEY("question_response_key:%s", "问卷回答key", 60 * 60 * 24L),
         IMPORT_ACCOUNT_CACHE_KEY("import_account_cache_key:%s", "导入缓存key", 60 * 10L),
         MAKERTING_MSG_KEY("makerting_msg_key", "营销短信", 60 * 60 * 24 * 30),
+        PHONE_AREA_CODE("phone_area_code:key", "国家或地区码", 60 * 60 * 24 * 15),
         ;
 
         private String name;

+ 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);
 

+ 8 - 5
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;
@@ -60,10 +63,10 @@ public class CpsManageServiceImpl implements CpsManageService {
 		}
 		String code = StringUtil.getRandomCodeStr(6);
 		if (type == 1) {
-			if (!Validator.isMobile(login)) {
+			if (StrUtil.isEmpty(login) || (86 == cid && !Validator.isMobile(phone))) {
 				throw BusinessRuntimeException.getInstance("请输入正确的手机号");
 			}
-			SmsUtil.sendTencent(login, code);
+			SmsUtil.sendTencent(cid, login, code);
 		} else if (type == 2) {
 			if (!Validator.isEmail(login)) {
 				throw BusinessRuntimeException.getInstance("请输入正确的邮箱");
@@ -90,13 +93,13 @@ public class CpsManageServiceImpl implements CpsManageService {
 		}
 		String CACHE_LOGIN_KEY = RedisService.key.CPS_BACK_LOGIN_KEY.getName();
 		if (type == 1) {
-			if (!Validator.isMobile(phone)) {
+			if (StrUtil.isEmpty(phone)) {
 				throw BusinessRuntimeException.getInstance("请输入正确的手机号");
 			}
 			CACHE_LOGIN_KEY += phone;
 		} else if (type == 2) {
 			if (!Validator.isEmail(email)) {
-				throw BusinessRuntimeException.getInstance("请输入正确的手机号");
+				throw BusinessRuntimeException.getInstance("请输入正确的邮箱");
 			}
 			CACHE_LOGIN_KEY += email;
 		}

+ 1 - 2
netflix-service/src/main/java/com/cyksj/service/gzh/factory/EventMsgService.java

@@ -1,6 +1,5 @@
 package com.cyksj.service.gzh.factory;
 
-import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -245,7 +244,7 @@ public class EventMsgService implements GzhMsgService {
 	}
 
 	public void userBind(Long userId, String sceneKey, String loginPhone) {
-		if (StrUtil.isNotBlank(loginPhone) && Validator.isMobile(loginPhone)) {
+		if (StrUtil.isNotBlank(loginPhone)) {
 			log.info("pc端用户phone:{}购买车票后,微信扫描公众号二维码进行用户信息绑定", loginPhone);
 			try {
 				bindTaskService.bindPhone(userId, loginPhone, null, false);

+ 1 - 2
netflix-service/src/main/java/com/cyksj/service/phone/impl/PhoneCodeServiceImpl.java

@@ -2,7 +2,6 @@ package com.cyksj.service.phone.impl;
 
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
-import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.exception.BusinessRuntimeException;
@@ -29,7 +28,7 @@ public class PhoneCodeServiceImpl implements PhoneCodeService {
 
 	@Override
 	public void checkPhone(String phone, String code) {
-		if (!Validator.isMobile(phone)) {
+		if (StrUtil.isEmpty(phone)) {
 			throw BusinessRuntimeException.getInstance("请输入正确的手机号码");
 		}
 		DateTime now = DateTime.now();

+ 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();
 	}
 

+ 6 - 5
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) {
-        if (StrUtil.isBlank(phone) || !Validator.isMobile(phone)) {
-            throw BusinessRuntimeException.getInstance("请输入正确手机号");
+    public Result<String> getPhoneCode(String phone, Integer digit, @RequestParam(defaultValue = "0") Boolean isFree, Integer cid) {
+        if (StrUtil.isBlank(phone) || (86 == cid && !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();
@@ -330,10 +330,11 @@ public class AuthorizationController {
         String code = StringUtil.getRandomCodeStr(digit);
         phoneCode.setCode(code);
         if (phoneCode.getId() == null) {
+            phoneCode.setCid(cid);
             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));

+ 55 - 0
netflix-web/src/main/java/com/cyksj/web/controller/user/PhoneAreaCodeController.java

@@ -0,0 +1,55 @@
+package com.cyksj.web.controller.user;
+
+import cn.hutool.core.util.StrUtil;
+import com.cyksj.common.util.Jsons;
+import com.cyksj.dto.Result;
+import com.cyksj.enums.GatewayResponse;
+import com.cyksj.model.views.PhoneAreaCodeView;
+import com.cyksj.redis.RedisService;
+import com.ejlchina.searcher.BeanSearcher;
+import com.ejlchina.searcher.util.MapUtils;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/*
+ *项目名: netflix
+ *文件名: PhoneAreaCodeController
+ *创建者: JavaZou
+ *创建时间:2023/6/21 14:09
+ */
+@RestController
+@RequestMapping("/applets/phone")
+@Slf4j
+@RequiredArgsConstructor
+public class PhoneAreaCodeController {
+	private final BeanSearcher beanSearcher;
+
+	private final RedisService redisService;
+
+	/**
+	 * 获取国家或地区手机号代码
+	 */
+	@GetMapping("/get/areaCode")
+	public Result<List<PhoneAreaCodeView>> getPhoneAreaCode(String name) throws Exception {
+		String key = RedisService.key.PHONE_AREA_CODE.getName();
+		Object value = redisService.get(key);
+		List<PhoneAreaCodeView> phoneAreaCodeViews = null;
+		if (value == null) {
+			phoneAreaCodeViews = beanSearcher.searchAll(PhoneAreaCodeView.class, MapUtils.builder().build());
+			redisService.setNx(key, Jsons.toJson(phoneAreaCodeViews), RedisService.key.PHONE_AREA_CODE.getTimeout());
+		}
+		if (phoneAreaCodeViews == null) {
+			phoneAreaCodeViews = Jsons.parseList(value.toString(), PhoneAreaCodeView.class);
+		}
+		if (StrUtil.isNotBlank(name)) {
+			phoneAreaCodeViews = phoneAreaCodeViews.stream().filter(view -> view.getNameCn().contains(name)).collect(Collectors.toList());
+		}
+		return GatewayResponse.SUCCESS.newBuilder().toResult(phoneAreaCodeViews);
+	}
+}