先贴代码
public static boolean sendSmsActivateFriends(String mobile, String content, String type) {
//短信发送开关
if(UN_SMS_SWITCH.equals("1")){
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(SMSURL);
client.getParams().setContentCharset("UTF-8");
method.setRequestHeader("ContentType","application/x-www-form-urlencoded;charset=UTF-8");
NameValuePair[] data = {//提交短信参数
new NameValuePair("account",SMS_ACCOUNT),
new NameValuePair("password",SMSPASSWORD),
new NameValuePair("mobile", mobile),
new NameValuePair("content", content),
};
method.setRequestBody(data);
try {
client.executeMethod(method);
String SubmitResult =method.getResponseBodyAsString();
Document doc = DocumentHelper.parseText(SubmitResult);
Element root = doc.getRootElement();
String code = root.elementText("code"); //返回状态码枚举
String msg = root.elementText("msg"); //提交结果的描述
//String smsid = root.elementText("smsid"); //此消息的id,在发送成功的时候返回
LOGGER.info("互易无线短信发送状态【{}】,手机号为【{}】,结果【{}】", new Object[]{code,mobile,msg});
if("2".equals(code)){
return true;
}
} catch (Exception e) {
LOGGER.error("Exception:【{}】", e);
LOGGER.error(e.getLocalizedMessage());
}
return false;
}else{
return true;
}
}
反正大概能看明白怎么个意思,就是对于HTTP的东西不了解,故而在网上找到了一哥们儿写的文,挺通俗易懂的,请自行打开链接阅读。
http://blog.csdn.net/chenyi_home/article/details/17240457
可能对接不同的短信第三方方法参数不太一样,原理上应该差不多。贴出来备用,万一能用上呢?