JavaはSMS SMSプラットフォームを介してSMSメッセージ機能を実装します
プロジェクトでテキストメッセージを送信する機能を使用しましたが、内部制限のために、今日のオンラインで簡単なオンラインを見つけて、何もすることがないときに次のように記録しました。
このプログラムは、中国の純建設が提供するSMS SMSプラットフォームを使用して実装されています(プラットフォームは現在、登録ユーザーに5つの無料SMSと3つの無料MMSを提供します。これは、使用する前に登録する必要があり、登録アドレスはhttp://sms.webchinese.cn/reg.shtmlです)。以下はプログラムソースコードです。
/ ** * @author dengsilinming * @date 2012-9-18 * */ package com.dengsilinming.mail; java.io.ioexceptionをインポートします。 org.apache.commons.httpclient.headerをインポートします。 Import org.apache.commons.httpclient.httpclient; Import org.apache.commons.httpclient.httpclient; Import org.apache.commons.httpclient.httpexception; org.apache.commons.httpclient.namevaluepairをインポートします。 org.apache.commons.httpclient.methods.postmethodをインポートします。パブリッククラスsendmsg_webchinese { / ** * @author dengsilinming * @date Sep 18、2012 * @time 9:38:25 am * @param args * @throws ioexception * @throws httpexception * @description * / public static bain(] throws htpexception httpclient(); PostMethod post = new postmethod( "http://gbk.sms.webchinese.cn"); // postmethod post = new postmethod( "http://sms.webchinese.cn/web_api/"); post.addrequestheader( "content-type"、 "application/x-www-form-urlencoded; charset = gbk"); // transcoding namevaluepair [] data = {new namevaluepair( "uid"、 "dengsilinming")、// 「72DA78DA5FF54F450505」)、//正常に登録した後、Webサイトにログインした後に取得されたキーは新しいNameValuePair( "smsmob"、 "12345678900")、//携帯電話番号new namevaluepair( "smstext")、 " post.setRequestBody(データ); client.executemethod(post); header [] headers = post.getResponseHeaders(); int statuscode = post.getStatusCode(); system.out.println( "statusCode:" + statusCode); for(header h:headers){system.out.println( "---" + h.toString()); } string result = new String(post.getResponseBodyAsstring()。getBytes( "gbk")); system.out.println(result); }}使用する3つのJARパッケージがあります。
commons-logging-1.1.1.jar
commons-httpclient-3.1.jar
Commons-Codec-1.4.jar
次のコンテンツは、中国Jianshe SMS SMS APIから抜粋されています。
インターフェイスアドレスの送信のGBKエンコード:
http://gbk.sms.webchinese.cn/?uid=userこのサイトの名前&key = interfaceセキュリティパスワード&smsmob =携帯番号&smstext = smsコンテンツ
UTF-8インターフェイスの送信アドレスのエンコード:
http://utf8.sms.webchinese.cn/?uid=userこのサイトの名前&key = interfaceセキュリティパスワード&smsmob =携帯番号&smstext = smsコンテンツsmsインターフェイスアドレスの数(utf8)を取得する
http://sms.webchinese.cn/web_api/sms/?action=sms_num&uid=usernameこのサイトのuid = username = key =インターフェイスセキュリティとセキュリティSMS番号インターフェイスアドレス(GBK)
http://sms.webchinese.cn/web_api/sms/gbk/?action=sms_num&uid = usernameこのサイト&key = interfaceセキュリティパスワード
ヒント: HTTPがURLインターフェイスを呼び出す場合、呼び出す前にパラメーター値をURLエンコードする必要があります
ハーフコーナーを使用して、138888888886、13888888887、13888888888888888などの複数の携帯電話番号を分離してください。
以下は、異なる言語でSMSインターフェイスを呼び出す簡単なデモです。
1。ASPコール
<% 'Common Function' URL宛先Webページアドレスを入力すると、gethttppageの返品値は宛先Webページ関数gethttppage(url)dim http = server.createobject( "msxml22.xmlhttp")http.open "get"、url、false http.send( http.ReadyState <> 4次に、gethttppage = bytestobstr(http.responsebody、 "gb2312")の場合、機能終了を終了します。 objstream.type = 1 objstream.mode = 3 objstream.open objstream.write body objstream.position = 0 objstream.type = 2 objstream.charset = cset bytestobstr = objstream. objstream.readtext objstream.close set objstream sms_url = "http://sms.webchinese.cn/web_api/?uid=account&key= interface key&smsmob =携帯番号&smstext = smsコンテンツ" response.write gethttpage(sms_url)%>
2.C#呼び出し
// system.netを使用して必要な名前空間; System.ioを使用しています。 System.textを使用しています。 //呼び出すとき、スペルのURLを関数に渡すだけです。 return Value Public String gethtmlfromurl(string url){string strret = null; if(url == null || url.trim()。toString()== ""){return strret; } string targeturl = url.trim()。toString(); try {httpwebrequest hr =(httpwebrequest)webrequest.create(targeturl); hr.useragent = "mozilla/4.0(互換; msie 6.0; windows nt 5.1)"; hr.method = "get"; hr.timeout = 30 * 60 * 1000; webresponse hs = hr.getResponse(); stream sr = hs.getResponsestream(); StreamReader Ser = new StreamReader(SR、Encoding.Default); strret = ser.readtoend(); } catch(Exception ex){strret = null; } return strret; } 3.Javaコール
java.io.unsupportedencodingexceptionをインポートします。 org.apache.commons.httpclient.headerをインポートします。 Import org.apache.commons.httpclient.httpclient; org.apache.commons.httpclient.namevaluepairをインポートします。 org.apache.commons.httpclient.methods.postmethodをインポートします。 public class sendmsg_webchinese {public static void main(string [] args)throws exception {httpclient client = new httpclient(); PostMethod post = new postmethod( "http://gbk.sms.webchinese.cn"); post.addrequestheader( "content-type"、 "application/x-www-form-urlencoded; charset = gbk"); // transcoding namevaluepair [] data = {new namevaluepair( "uid"、 "このサイトのユーザー名")、new namebaluepair( "key")、 ")、") number ")、new NameValuePair(" smstext "、" sms content ")}; post.setRequestBody(データ); client.executemethod(post); header [] headers = post.getResponseHeaders(); int statuscode = post.getStatusCode(); system.out.println( "statusCode:"+statusCode); for(Header H:Headers){System.out.Println(h.toString()); } string result = new String(post.getResponseBodyAsstring()。getBytes( "gbk")); system.out.println(result); post.releaseconnection(); }} JARパッケージのダウンロード
commons-logging-1.1.1.jar
commons-httpclient-3.1.jar
Commons-Codec-1.4.jar
4。PHPコール
$ url = 'http://sms.webchinese.cn/web_api/?uid = account&key = interface key&smsmob =携帯番号&smstext = sms content'; echo get($ url); function get($ url){if(function_exists( 'file_get_contents')){$ file_contents = file_get_contents($ url); } else {$ ch = curl_init(); $ Timeout = 5; curl_setopt($ ch、curlopt_url、$ url); curl_setopt($ ch、curlopt_returntransfer、1); curl_setopt($ ch、curlopt_connecttimeout、$ timeout); $ file_contents = curl_exec($ ch); curl_close($ ch); } $ file_contentsを返します。 } 5.VB.NETコール
'Nolistを送信するために電話を送信して、番号を受け取ります。メモコンテンツの複数回、個別、70語を使用する
パブリック関数sendsms(byval nolist as string、byval memo as string)as string dim url as string = "http://sms.webchinese.cn/web_api/?uid = account&key = interface key&smsmob =モバイル番号&smstext = smstext = sms content" dim webcliant as dim s.webclient sing = webclient.downloadstring(url)return srcstringキャッチリターン "-444"エンドエンド機能を試してください
テスト後、上記のJavaソースコードを正常に送信できますが、他の言語にはテストがありません。
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。