給你一個(gè)最簡(jiǎn)單的方法:
創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站制作、網(wǎng)站建設(shè)、高明網(wǎng)絡(luò)推廣、微信小程序開發(fā)、高明網(wǎng)絡(luò)營(yíng)銷、高明企業(yè)策劃、高明品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供高明建站搭建服務(wù),24小時(shí)服務(wù)熱線:18980820575,官方網(wǎng)址:www.rwnh.cn
第一、根據(jù) 拿到WSDL文件。
第二、根據(jù)Axis的jar包,把WSDL文件生成客服端java代碼。(可以把java文件打成jar文件,便于管理。怎么生成java代碼,百度里都有說明我就不寫了。)
第三、在你工程里用AXIS的功能屬性,調(diào)用外部接口;給你一個(gè)格式模板:
MobileCodeWSLocator l=new MobileCodeWSLocator();//MobileCodeWSLocator是WSDL文件生成客服端java類;
MobileCodeWSSoap s=l.getMobileCodeWSSoap();();//MobileCodeWSSoap 是WSDL文件生成客服端java類
String m=s.getMobileCodeInfo("13811534742", "");
如果你用Axis生成的java類,格式和上面一樣;自己參考一下就懂了。
你上面明顯的連接異常,第三方服務(wù)明顯沒有開,WEBSERVICE可以設(shè)置戶名、密碼,像我們行所有的WEBSERVICE都設(shè)置,安全考慮吧。還有不懂的可以call我。
用移動(dòng)短信代理機(jī) 或短信貓等。發(fā)短信是要第三方支持的,java這種弱語言,網(wǎng)絡(luò)方面還行,其他簡(jiǎn)直是胡扯。
這個(gè)首先你要確定一下短信平臺(tái),他們會(huì)給你提供短信實(shí)現(xiàn)的接口文檔。
比如:
public static String doPost(String reqUrl, Map parameters, String recvEncoding)
{
HttpURLConnection url_con = null;
String responseContent = null;
try
{
StringBuffer params = new StringBuffer();
Iterator iter = parameters.entrySet().iterator();
while (iter
.hasNext())
{
Map.Entry element = (Map.Entry)iter.next();
params.append(element.getKey().toString());
params.append("=");
params.append(URLEncoder.encode(element.getValue().toString(),
requestEncoding));
params.append("");
}
if (params.length() 0)
{
params = params.deleteCharAt(params.length() - 1);
}
URL url = new URL(reqUrl);
url_con = (HttpURLConnection)url.openConnection();
url_con.setRequestMethod("POST");
System.setProperty("sun.net.client.defaultConnectTimeout",
String.valueOf(connectTimeOut));
System.setProperty("sun.net.client.defaultReadTimeout",
String.valueOf(readTimeOut));
url_con.setDoOutput(true);
byte[] b = params.toString().getBytes();
url_con.getOutputStream().write(b, 0, b.length);
url_con.getOutputStream().flush();
url_con.getOutputStream().close();
InputStream in = url_con.getInputStream();
BufferedReader rd = new BufferedReader(
new InputStreamReader(in,
recvEncoding));
String tempLine = rd.readLine();
StringBuffer tempStr = new StringBuffer();
String crlf = System.getProperty("line.separator");
while (tempLine != null)
{
tempStr.append(tempLine);
tempStr.append(crlf);
tempLine = rd.readLine();
}
responseContent = tempStr.toString();
rd.close();
in.close();
}
catch (IOException localIOException)
{
}
finally
{
if (url_con != null)
{
url_con.disconnect();
}
}
return responseContent;
}
public static String sendTelCode(String mobile,String telcode){
MapString ,String map = new HashMapString ,String();
map.put("account", "Babo");
map.put("mobile", mobile);
map.put("pswd", "D3dddD");
try {
map.put("msg", java.net.URLEncoder.encode("您的驗(yàn)證碼是"+telcode+",若非本人操作請(qǐng)忽略","utf-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String getValue = doPost("", map, "UTF-8");
System.out.println(getValue);
return getValue;
}
那你要做的就是向這個(gè)URL發(fā)送數(shù)據(jù)就好,給個(gè)例子:
public???class??Httptest1??{
8??
9???????public???static???void??main(String[]?args)??{
10??
11?????????URL?url??=???null?;
12?????????HttpURLConnection?conn??=???null?;
13?????????OutputStream?outStream??=???null?;
14?????????InputStream?inStream??=???null?;
15?????????
16???????????try???{
17?????????????url??=???new??URL(?"??"?);
18?????????????conn??=??(HttpURLConnection)?url.openConnection();
19?????????????conn.setDoOutput(?true?);
20?????????????conn.setDoInput(?true?);
21??
22?????????????String?sendXml??=???"??xml?version=\?"?1.0?\?"??encoding=\?"?UTF?-?16?\?"??!DOCTYPE?SigMailCommand?SYSTEM?\?"?SigMail.dtd\?"?"?;??//?XML數(shù)據(jù)?????
23??????????????sendXml??+=???"?SigMailCommand?Name=\?"?checkuser\?"?Param?Name=\?"?domainname\?"?test.com.cn/Param?"?;
24?????????????sendXml??+=???"?Param?Name=\?"?username\?"?admin/Param/SigMailCommand?"?;
25??
26?????????????outStream??=??conn.getOutputStream();
27??
28??????????????//?準(zhǔn)備通過CONN對(duì)象寫入XML數(shù)據(jù)?
29??????????????BufferedWriter?bw??=???new??BufferedWriter(?new??java.io.OutputStreamWriter(outStream,
30??????????????"?UTF-16?"?));
31?????????????bw.write(sendXml);
32?????????????bw.flush();
33?????????????bw.close();
34?????????????
35??????????????//?DataOutputStream?dataOutStream?=?new?DataOutputStream(outStream);
36??????????????//?dataOutStream.writeChars(xml);
37??????????????//?dataOutStream.flush();
38??????????????//?dataOutStream.close();
39?????????????
40??
41??????????????//?準(zhǔn)備通過CONN對(duì)象讀取返回的XML數(shù)據(jù)?
42??
43?????????????inStream??=??conn.getInputStream();
44?????????????StringBuffer?returnXml??=???new??StringBuffer(?""?);
45?????????????BufferedReader?rd??=???new??BufferedReader(?new??InputStreamReader(inStream,
46??????????????????????"?UTF-16?"?));
47???????????????for??(String?line??=???null?;?(line??=??rd.readLine())??!=???null?;)??{
48?????????????????returnXml.append(line);
49?????????????}?
50?????????????System.out.println(returnXml.toString());
51?????????????rd.close();
52??????????}???catch??(IOException?ex)??{
53?????????????ex.printStackTrace();
54??????????}?finally?{
55???????????????try???{
56??????????????????if??(outStream??!=???null?)
57?????????????????????outStream.close();
58??????????????????if??(inStream??!=???null?)
59?????????????????????inStream.close();
60??????????????????if??(conn??!=???null?)
61?????????????????????conn.disconnect();
62??????????????}???catch??(IOException?e)??{
63??????????????????//??TODO?自動(dòng)生成?catch?塊?
64??????????????????e.printStackTrace();
65?????????????}?
66?????????}?
67??
68?????}?
69??
70?}
JAVA實(shí)現(xiàn)短信群發(fā)的步驟:
1、使用第三方短信平臺(tái)服務(wù)商,接入短信服務(wù);
2、調(diào)用短信提交頁面發(fā)送請(qǐng)求;
3、服務(wù)器向第三方短信平臺(tái)提交發(fā)送請(qǐng)求;
4、短信平臺(tái)通過運(yùn)營(yíng)商將短信下發(fā)至用戶的手機(jī)上。
以下是秒賽短信平臺(tái)JAVA短信驗(yàn)證碼接口代碼示例
package test;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.lang3.StringUtils;
public class Apis {
// 短信發(fā)送接口的http地址,請(qǐng)咨詢客服
private static String url = “xxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
// 編碼格式。發(fā)送編碼格式統(tǒng)一用UTF-8
private static String ENCODING = “UTF-8”;
public static void main(String[] args) throws IOException, URISyntaxException {
// 賬號(hào)
String account = “************************”;
// 密碼
String pswd = “************************”;
// 修改為您要發(fā)送的手機(jī)號(hào),多個(gè)用,分割
String mobile = “13*********”;
// 設(shè)置您要發(fā)送的內(nèi)容
String msg = “【秒賽科技】您的驗(yàn)證碼是:1234”;
// 發(fā)短信調(diào)用示例
System.out.println(Apis.send(account,pswd, mobile, msg));
}
/**
* 發(fā)送短信
*
* @param account
* ? ? ? ? ? ?account
* @param pswd
* ? ? ? ? ? ?pswd
* @param mobile
* ? ? ? ? ? ?手機(jī)號(hào)碼
* @param content
* ? ? ? ? ? ?短信發(fā)送內(nèi)容
*/
public static String send(String account,String pswd, String mobile, String msg) {
NameValuePair[] data = { new NameValuePair(“account”, account),
new NameValuePair(“pswd”, pswd),
new NameValuePair(“mobile”, mobile),
new NameValuePair(“msg”, msg),
new NameValuePair(“needstatus”, “true”),
new NameValuePair(“product”, “”) };
return doPost(url, data);
}
/**
* 基于HttpClient的post函數(shù)
* PH
* @param url
* ? ? ? ? ? ?提交的URL
*
* @param data
* ? ? ? ? ? ?提交NameValuePair參數(shù)
* @return 提交響應(yīng)
*/
private static String doPost(String url, NameValuePair[] data) {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(url);
// method.setRequestHeader(“ContentType”,
// “application/x-www-form-urlencoded;charset=UTF-8”);
method.setRequestBody(data);
// client.getParams()。setContentCharset(“UTF-8”);
client.getParams()。setConnectionManagerTimeout(10000);
try {
client.executeMethod(method);
return method.getResponseBodyAsString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
public interface Calling {
/**
*
* @param callPhoneNo 主叫號(hào)碼
* @param calledPhoneNo 被叫號(hào)碼
* @return 返回接電話成功失敗標(biāo)識(shí)
*/
public int callIn(String callPhoneNo,String calledPhoneNo);
/**
*
* @param calledPhoneNo 被叫號(hào)碼
* @param callPhoneNo 主叫號(hào)碼
* @return返回打電話成功失敗標(biāo)識(shí)
*/
public int callOut(String calledPhoneNo,String callPhoneNo);
/**
*
* @param calledPhoneNo 接收短信號(hào)碼
* @param callPhoneNo發(fā)送短信號(hào)碼
* @param content 短信內(nèi)容
* @return 發(fā)送短信成功標(biāo)識(shí)
*/
public int sendMsg(String calledPhoneNo,String callPhoneNo,String content);
/**
*
* @param callPhoneNo 發(fā)送短信號(hào)碼
* @param calledPhoneNo 接收短信號(hào)碼
* @param content 短信內(nèi)容
* @return 接收短信成功標(biāo)識(shí)
* 備注:其實(shí)不用這個(gè)接口也可以,發(fā)送短信是將短信保存至短信發(fā)送表,然后有進(jìn)程實(shí)時(shí)掃描數(shù)據(jù),然后發(fā)送
*/
public int reciveMsg(String callPhoneNo,String calledPhoneNo,String content);
}
文章標(biāo)題:汕頭java短信接口代碼 汕頭java短信接口代碼是什么
分享路徑:http://www.rwnh.cn/article10/doohgdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、移動(dòng)網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作、關(guān)鍵詞優(yōu)化、虛擬主機(jī)、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)