簡訊平台介面調用方法參考

來源:互聯網
上載者:User

標籤:val   spec   amr   send   end   imp   cto   comm   tco   

http請求

//說明:此處需引用httpclient、httpcore、commons-logging三個jar包

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.security.MessageDigest;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.*;
import javax.crypto.SecretKey;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.SecretKeyFactory;
import javax.crypto.Cipher;

public static void main(String[] args) {
String url="http://xxx.com/api/MsgSend.asmx/SendMes";

List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("userCode", "使用者名稱"));
nvps.add(new BasicNameValuePair("userPass", "密碼"));
nvps.add(new BasicNameValuePair("DesNo", "手機號"));
nvps.add(new BasicNameValuePair("Msg", "簡訊內容【簽名】"));
nvps.add(new BasicNameValuePair("Channel", "通道號"));
String post=httpPost(url,nvps); //post請求

String getparam="userCode=使用者名稱&userPass=密碼&DesNo=手機號&Msg=簡訊內容【簽名】&Channel=通道號";
String result=httpGet(url,getparam); //get請求
}

public static String httpPost(String url,List<NameValuePair> params) {
String result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instreams = entity.getContent();
result = convertStreamToString(instreams);
System.out.println(result);
}
} catch (Exception e) {
}
return result;
}

public static String httpGet(String url,String params){
String result="";
try{
HttpClient client=new DefaultHttpClient();
if(params!=""){
url=url+"?"+params;
}
HttpGet httpget=new HttpGet(url);
HttpResponse response=client.execute(httpget);
HttpEntity entity=response.getEntity();
if (entity != null) {
InputStream instreams = entity.getContent();
result = convertStreamToString(instreams);
System.out.println(result);
}
}catch(Exception e){}
return result;
}

public static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();

String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}

 

webservice請求

 

public static void main(String[] args) {
org.tempuri.MsgSend service = new org.tempuri.MsgSend();
org.tempuri.MsgSendSoap port = service.getMsgSendSoap();
String result= port.sendMes("使用者名稱","密碼","手機號","簡訊內容【簽名】","通道號");
System.out.println(result);
}

簡訊平台介面調用方法參考

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.