1、注入@Component
@Slf4j
@Component
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}$";
/**
* 基础资源服务
*/
@Autowired
private BaseResourceService baseResourceService;
private static PushUtils pushUtils;
/**
* 引入service层
*/
@PostConstruct
public void init() {
pushUtils = this;
pushUtils.baseResourceService = this.baseResourceService;
}
2、使用
public static Boolean pushSmsToOne(Integer areaId, Integer informType,String message, String orderNumber,String phone) {
Map<String, Object> postParameters = new HashMap<>();
String areaName = pushUtils.baseResourceService.getAreaNameByAreaId(areaId);
String areaNumber = pushUtils.baseResourceService.getAreaNumberByAreaId(areaId);
postParameters.put("areaNo", areaNumber);
postParameters.put("sendType", informType);
postParameters.put("areaName", areaName);
postParameters.put("status", message);
postParameters.put("orderNumber", orderNumber);
//为每个号码发送信息
try {
sendSMS(postParameters, phone);
return true;
} catch (Exception jpc) {
jpc.printStackTrace();
return false;
}
}
}