1、验证规则
@Slf4j
public class PushUtils {
/**
* 号码验证正则
*/
private static final String pattern = "^((17[0-9])|(14[0-9])|(13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
2、使用
/**
* 发送短信
*/
private static void sendSMS(Map<String, Object> info, String phone) {
String url = CNSPushAddress.SMS.getUrl() + "v1/send";
RestOperations restOperations = new RestTemplate();
if (phone.matches(pattern)) {
//发送消息
info.put("phoneNo", phone);
log.info("发送请求的数据:" + info.toString());
ResponseEntity responseEntity = restOperations.postForEntity(url, JSONObject.toJSON(info), String.class);
log.info("短信发送结果:" + responseEntity.toString());
} else {
log.info("手机号:" + phone + "匹配有误,不能发送信息");
}
}