【Java】如何擷取創藍253簡訊驗證碼?

來源:互聯網
上載者:User

標籤:Java   簡訊驗證碼   創藍253   

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簡訊驗證碼?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.