import java.util.Calendar; import org.apache.log4j.Logger; import com.chinamobile.openmas.client.Sms; public abstract class SmsServiceUtils { private static final Logger log = Logger.getLogger(SmsServiceUtils.class); private static final String SMS_SERVICE_URL = "xxx"; private static final String APP_ID = "xxxxxx"; private static final String PASSWORD = "xxxxxxx"; public static String sendMobileMsg(String[] phoneAddrs, String message, Calendar sendTime, String extendCode, String appId, String passwd) { String messageId = null;// 定义返回值,网关Id try { log.debug("send phoneAddrs: " + phoneAddrs + " message: " + message); Sms sms = new Sms(SMS_SERVICE_URL); // 普通短信,如果SendTime为空则立即发送,否则为定时发送 if (sendTime == null) { messageId = sms.SendMessage(phoneAddrs, message, extendCode, appId, passwd); } else { messageId = sms.SendMessage(phoneAddrs, message, extendCode, appId, passwd, sendTime); } log.debug("sendMobilseMsg success MessageID:" + messageId); } catch (Exception e) { log.error("sendMobileMsg error: ", e); } return messageId; } public static String sendMobileMsg(String[] phoneAddrs, String message, Calendar sendTime) { return sendMobileMsg(phoneAddrs, message, sendTime, "", APP_ID, PASSWORD); } public static String sendMobileMsg(String[] phoneAddrs, String message) { return sendMobileMsg(phoneAddrs, message, null); } public static String sendMobileMsg(String phone, String message) { String[] phoneAddrs = { phone }; return sendMobileMsg(phoneAddrs, message); } public static void main(String[] args){ sendMobileMsg("",""); } }
openmas java_java发送短信
最新推荐文章于 2024-09-16 07:34:15 发布