12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- package com.caimei.utils;
- import com.alibaba.fastjson.JSONObject;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Component;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- /**
- * @author Aslee
- * @date 2021/7/16
- */
- @Slf4j
- @Component
- public class SmsUtils {
- private static String active;
- @Value("${spring.profiles.active}")
- public void setActive(String active) {
- SmsUtils.active = active;
- }
- private static String core;
- @Value("${caimei.core}")
- public void setCore(String core) {
- SmsUtils.core = core;
- }
- public static Boolean sendSms(Integer type, String mobile, String content) {
- try {
- List<String> passList = new ArrayList<>();
- passList.add("15113936829");
- passList.add("18476937515");
- passList.add("15917362709");
- passList.add("15872950940");
- passList.add("18229303772");
- if ("prod".equals(active) || passList.contains(mobile)) {
- if (StringUtils.isNotBlank(mobile) && mobile.length() == 11) {
- String regex = "^(1[3-9]\\d{9}$)";
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(mobile);
- if (matcher.matches()) {
- Map<String, Object> map = new HashMap<>(3);
- // 短信类型:1通知短信,2验证码短信,3营销短信
- map.put("type", type);
- map.put("content", content);
- map.put("mobile", mobile);
- String url = core + "/tools/sms/send";
- String result = HttpRequest.sendPost(url, map);
- JSONObject parseObject = JSONObject.parseObject(result);
- Integer code = parseObject.getInteger("code");
- if (code != 0) {
- log.info("短信发送失败,手机号>>>>" + mobile);
- } else {
- log.info("挑战赛短信发送成功"+mobile);
- return true;
- }
- }
- }
- } else {
- return true;
- }
- } catch (Exception e) {
- log.error("短信推送异常", e);
- }
- return false;
- }
- }
|