package com.product.text.message.util;
|
|
import com.product.core.config.Global;
|
import com.product.core.exception.BaseException;
|
import com.product.text.message.util.ide.ISMSConfiguration;
|
import org.apache.commons.httpclient.HttpClient;
|
import org.apache.commons.httpclient.NameValuePair;
|
import org.apache.commons.httpclient.methods.PostMethod;
|
import org.dom4j.Document;
|
import org.dom4j.DocumentHelper;
|
import org.dom4j.Element;
|
import org.springframework.stereotype.Component;
|
|
import java.io.BufferedReader;
|
import java.io.InputStreamReader;
|
import java.io.UnsupportedEncodingException;
|
import java.net.MalformedURLException;
|
import java.net.URL;
|
import java.net.URLEncoder;
|
|
/**
|
* @author GHQ
|
* @version 创建时间:2017年3月27日 下午2:36:08
|
*
|
*/
|
@Component
|
public class SendSMSUtil implements ISMSConfiguration {
|
private static String Url = "http://106.ihuyi.cn/webservice/sms.php?method=Submit";
|
private static String CorpID="CDJS003057";//账户名
|
private static String Pwd="zm0513@";//密码
|
private static String Signature="【企业管理平台】";//签名 德润美家 企业管理平台 成都龙欣科技
|
|
@Deprecated
|
public static String SendSMS(String phoneNum, boolean is_orignal) {
|
HttpClient client = new HttpClient();
|
PostMethod method = new PostMethod(Url);
|
|
client.getParams().setContentCharset("GBK");
|
method.setRequestHeader("ContentType","application/x-www-form-urlencoded;charset=GBK");
|
|
int mobile_code = (int)((Math.random()*9+1)*100000);
|
|
String content = new String("您的验证码是:" + mobile_code + "。请不要把验证码泄露给其他人。");
|
|
NameValuePair[] data = {//提交短信
|
new NameValuePair("account", "C12266072"), //查看用户名请登录用户中心->验证码、通知短信->帐户及签名设置->APIID
|
new NameValuePair("password", "6ddd7e53bc51fe1f666386564e0ee54f"), //查看密码请登录用户中心->验证码、通知短信->帐户及签名设置->APIKEY
|
//new NameValuePair("password", util.StringUtil.MD5Encode("密码")),
|
new NameValuePair("mobile", phoneNum),
|
new NameValuePair("content", content),
|
};
|
method.setRequestBody(data);
|
try {
|
client.executeMethod(method);
|
String SubmitResult =method.getResponseBodyAsString();
|
//System.out.println(SubmitResult);
|
Document doc = DocumentHelper.parseText(SubmitResult);
|
Element root = doc.getRootElement();
|
|
String code = root.elementText("code");
|
// String msg = root.elementText("msg");
|
// String smsid = root.elementText("smsid");
|
|
System.out.println(code);
|
// System.out.println(msg);
|
// System.out.println(smsid);
|
if("2".equals(code)){
|
return mobile_code+"";
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
return "";
|
}
|
return "";
|
}
|
|
@Override
|
public String SendSMS(String phoneNum) {
|
int mobile_code = (int)((Math.random()*9+1)*100000);
|
String content = new String("您的验证码是:" + mobile_code + ",请不要把验证码泄露给其他人。");
|
int result;
|
try {
|
result = sendSMS(phoneNum, content, "");
|
if (result > 0) {
|
return mobile_code + "";
|
}
|
} catch (Exception e) {
|
return "-2";
|
}
|
return result + "";
|
}
|
|
/**林凱-發送短信接口*/
|
public int sendSMS(String Mobile,String Content,String send_time)throws BaseException {
|
URL url = null;
|
//通过配置文件获取公司签名
|
Signature = Global.getSystemConfig("org.message.signatures","");
|
Content+=Signature;
|
String send_content= null;//发送内容
|
try {
|
send_content = URLEncoder.encode(Content.replaceAll("<br/>", " "), "GBK");
|
url = new URL("https://sdk2.028lk.com/sdk2/BatchSend2.aspx?CorpID="+CorpID+"&Pwd="+Pwd+"&Mobile="+Mobile+"&Content="+send_content+"&Cell=&SendTime="+send_time);
|
} catch (UnsupportedEncodingException | MalformedURLException e) {
|
throw new BaseException("public int sendSMS(String Mobile,String Content,String send_time)throws BaseException",e.getMessage());
|
}
|
|
// url = new URL("https://sdk2.028lk.com/sdk2/SelSum.aspx?CorpID="+CorpID+"&Pwd="+Pwd); // 查询短信剩余条数
|
BufferedReader in = null;
|
int inputLine = 0;
|
try {
|
System.out.println("开始发送短信手机号码为 :"+Mobile);
|
in = new BufferedReader(new InputStreamReader(url.openStream()));
|
inputLine = new Integer(in.readLine()).intValue();
|
} catch (Exception e) {
|
e.printStackTrace();
|
System.out.println("网络异常,发送短信失败!");
|
throw new BaseException("网络异常,发送短信失败!-2",e.getMessage());
|
}
|
System.out.println("结束发送短信返回值: "+inputLine);
|
return inputLine;
|
}
|
//
|
// public static void main(String[] args) {
|
// SendSMSUtil smsUtil = new SendSMSUtil();
|
// System.out.println(smsUtil.SendSMS("15928438186"));
|
//
|
// }
|
}
|