在项目中采用发送短信的业务,必须要购买外部的服务(发送短信的API)使用,在时代互联网上下载一个SMSAPI,注册测试使用一下:
转载原API接口说明:
外部使用服务:
package com.unutrip.sms.service;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.unutrip.sms.model.SMSMessage;
import com.unutrip.sms.model.SMSResponse;
import com.unutrip.sms.proxy.SMSProxy;
/**
* 发送短信的服务类
*
* @author longgangbai
*
*/
public class SMSProxyService {
private static Logger logger = Logger.getLogger(SMSProxyService.class
.getName());
private static SMSProxy smsproxy = SMSProxy.getInstance();
/**
* 发送短信的类
*
* @param message
* @return
*/
@SuppressWarnings("unchecked")
public SMSResponse sendSMS(SMSMessage message) {
try {
SMSResponse response = smsproxy.sendSMS(message);
if (response != null) {
logger.log(Level.WARNING, "发送短信成功!");
}
logger.log(Level.WARNING, "发送短信失败!");
return response;
} catch (Exception e) {
logger.log(Level.WARNING, e.getMessage());
}
return null;
}
/**
* 接受短信的类
*
* @param message
* @return
*/
@SuppressWarnings("unchecked")
public SMSResponse receiveSMS() {
try {
SMSResponse response = smsproxy.receiveSMS();
if (response != null) {
logger.log(Level.WARNING, "接受短信成功!");
}
logger.log(Level.WARNING, "接受短信失败!");
return response;
} catch (Exception e) {
logger.log(Level.WARNING, e.getMessage());
}
return null;
}
/**
* 查看账户的信息
*
*/
public SMSResponse infoSMSAccount() throws Exception {
try {
SMSResponse response = smsproxy.infoSMSAccount();
if (response != null) {
logger.log(Level.WARNING, "查看账户短信成功!");
}
logger.log(Level.WARNING, "查看账户短信成功!");
return response;
} catch (Exception e) {
logger.log(Level.WARNING, e.getMessage());
}
return null;
}
}
其他实体类请看源代码: