Javaは、Chuanglan 253 SMSサービスプラットフォームに基づいてSMSインターフェイスAPIを呼び出します
パッケージ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.htpclient.httpclient; org.apache.commons.httpclient.httpstatus; Import org.apache.commons.httpclient.namevaluepair; 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アカウントアカウント * @param pswdパスワード * @param携帯電話番号、複数の数字の使用 "、" @param msg content * @param needstatus @param needstatus execs execs、true、fals no fals http stingol */http stingol batchsend(string url、string account、string pswd、string mobile、string msg、boolean needstatus、string extno)スロー例外{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)) 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エラーステータス:" + method.getStatusCode() + ":" + method.getStatustext()); }}最後に{method.releaseconnection(); }}}要約します
上記は、Javaが編集者によって導入されたChuanglan 253 SMS検証コードを取得するための実装コードです。私はそれが誰にでも役立つことを願っています。ご質問がある場合は、メッセージを残してください。編集者は、すべての人に時間内に返信します。 wulin.comのウェブサイトへのご支援ありがとうございます!