package com.nuvole.util.sms;
|
|
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.http.HttpUtil;
|
import com.alibaba.fastjson.JSONObject;
|
import com.nuvole.common.domain.emnu.SMSResultEmnu;
|
import com.nuvole.common.domain.result.SMSResult;
|
import com.nuvole.constants.ServiceConstants;
|
import com.nuvole.util.sc.sms.ScSMSUtil;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* 发送短信(统一调度类)
|
*
|
* @Author: lc
|
* @Date: 2019/6/1 11:09
|
*/
|
public class SMSCallUtil {
|
|
/**
|
* 短信接口类型(1.云片 2.四川省内部接口)
|
*/
|
private final static int SMS_TYPE = 1;
|
|
/**
|
* 发送短信
|
*
|
* @param mobile 手机号码字符串 多个号码以逗号分割
|
* @param message 短信内容
|
* @Author: lc
|
* @Date: 2019/6/1 11:27
|
*/
|
public static SMSResult sendSMS(String mobile, String message) {
|
|
//走外网服务调用
|
if (ServiceConstants.SERVICE_TYPE) {
|
Map map = new HashMap() {{
|
put("mobile", mobile);
|
put("message", message);
|
put("smsType", SMS_TYPE);
|
}};
|
String result = HttpUtil.get(ServiceConstants.SERVICE_SMS_URL, map);
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
if (!"0".equals(jsonObject.getString("code"))) {
|
return new SMSResult(SMSResultEmnu.ERROR, jsonObject.getString("msg"));
|
}
|
return new SMSResult(SMSResultEmnu.OK);
|
} else {
|
switch (SMS_TYPE) {
|
case 1:
|
return YpSMSUtil.sendSMS(mobile, message);
|
case 2:
|
return ScSMSUtil.sendSMS(mobile, message);
|
default:
|
break;
|
}
|
return new SMSResult(SMSResultEmnu.ERROR);
|
}
|
}
|
|
public static void main(String[] args) {
|
System.out.println(sendSMS("17803846500", SMSTemplate.getVaildCodeMsg(RandomUtil.randomNumbers(6))));
|
}
|
|
}
|