您好,登錄后才能下訂單哦!
基于創藍253短信服務平臺的Java調用短信接口API
package com.bcloud.msg.http; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.URLDecoder; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.URI; import org.apache.commons.httpclient.methods.GetMethod; /** * * @param url 應用地址,類似于http://ip:port/msg/ * @param account 賬號 * @param pswd 密碼 * @param mobile 手機號碼,多個號碼使用","分割 * @param msg 短信內容 * @param needstatus 是否需要狀態報告,需要true,不需要false * @return 返回值定義參見HTTP協議文檔 * @throws Exception */ public static String batchSend(String url, String account, String pswd, String mobile, String msg, boolean needstatus, String extno) throws Exception { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(); try { URI base = new URI(url, false); method.setURI(new URI(base, "HttpBatchSendSM", false)); method.setQueryString(new NameValuePair[] { new NameValuePair("account", account), new NameValuePair("pswd", pswd), new NameValuePair("mobile", mobile), new NameValuePair("needstatus", String.valueOf(needstatus)), new NameValuePair("msg", msg), new NameValuePair("extno", extno), }); int result = client.executeMethod(method); if (result == HttpStatus.SC_OK) { InputStream in = method.getResponseBodyAsStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = in.read(buffer)) != -1) { baos.write(buffer, 0, len); } return URLDecoder.decode(baos.toString(), "UTF-8"); } else { throw new Exception("HTTP ERROR Status: " + method.getStatusCode() + ":" + method.getStatusText()); } } finally { method.releaseConnection(); } } }
總結
以上所述是小編給大家介紹的Java調取創藍253短信驗證碼的實現代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。