บทความนี้อธิบายวิธีการใช้ฟังก์ชั่นการส่งมวลของ SMS โดย Java, PHP, C#และ ASP แบ่งปันสำหรับการอ้างอิงของคุณ รายละเอียดมีดังนี้:
ก่อนอื่นไปที่ http://www.smschinese.cn/ เพื่อดาวน์โหลดแพ็คเกจ JAR และลงทะเบียนผู้ใช้จากนั้นโทรไปที่อินเตอร์เฟส API เพื่อรับรหัสลับ
1. ตัวอย่างการโทร ASP
<%'ฟังก์ชั่นทั่วไป' ป้อน URL ของเว็บเพจปลายทางและค่าที่ส่งคืน gethttppage เป็นรหัส HTML ของฟังก์ชันหน้าเว็บปลายทาง gethttppage (URL) Dim httpset http = server.createObject ("msxml2.xmlhttp") http เปิด "get", url, falsehttp .send () ถ้า http.readystate <> 4 จากนั้นออก functionend ifgethttppage = bytestobstr (http.responsebody, "gb2312") bytestobstr (body, cset) dim objstreamset objstream = server.createObject ("adodb.stream") objstream.type = 1objstream.mode = 3objstream.openoBjstream.write BodyObjstream.position.position objstream.closeset objstream = ไม่มีฟังก์ชัน 'รวม URL ที่ส่งและเพิ่มบัญชีและรหัสผ่านของคุณเอง sms_url = "http://sms.webchinese.cn/web_api/?uid=act&key=interface กุญแจ เขียน gethttppage (sms_url)%>2.C# โทร
// namespace ที่จำเป็นคือการใช้ System.net; การใช้ System.io; การใช้ System.Text; // เมื่อโทรคุณจะต้องผ่าน URL ที่สะกดไปยังฟังก์ชัน เพียงตัดสินค่าคืนค่าสตริงสาธารณะ gethtmlfromurl (rl url) {string strret = null; if (url == null || url.trim (). toString () == "") {return strret;} สตริง targetUrl = url trim (). toString (); ลอง {httpwebrequest hr = (httpwebrequest) webrequest.create (targetUrl); hr.useragent = "mozilla/4.0 (เข้ากันได้; msie 6.0; windows nt 5.1) ; hr.timeout = 30 * 60 * 1000; webresponse hs = hr.getResponse (); stream sr = hs.getResponSestream (); StreamReader ser = streamReader ใหม่ (sr, encoding.default); strret = ser.readtoend (); } catch (exception ex) {strret = null;} return strret;}3.JAVA CALL
นำเข้า java.io.unsupportencodingexception; นำเข้า org.apache.commons.httpclient.header; นำเข้า org.apache.commons.httpClient.httpClient; นำเข้า org.apache.Commons.httpClient.namevaluepair; .PostMethod; คลาสสาธารณะ SENDMSG_WEBCHINESE {โมฆะคงที่สาธารณะหลัก (สตริง [] args) โยนข้อยกเว้น {httpClient client = ใหม่ httpClient (); postmethod post = postmethod ใหม่ ("http://gbk.sms. .Addrequestheader ("เนื้อหาประเภท", "แอปพลิเคชัน/x-ww-form-urlencoded; charset = gbk"); // ตั้งค่า transcoding namevaluepair [] data = {namevaluepair ใหม่ ("uid" NAMEVALUEPAIR ("คีย์", "รหัสผ่านความปลอดภัยอินเตอร์เฟส"), ใหม่ NAMEVALUEPAIR ("SMSMOB", "หมายเลขโทรศัพท์มือถือ"), NAMEVALUEPAIR ใหม่ ("SMSTEXT", "SMS Content")}; ExecuteMethod (โพสต์); ส่วนหัว [] ส่วนหัว = post.getResponseHeaders (); int statusCode = post.getStatusCode (); system.out.println ("statusCode:"+stationsCode); สำหรับ (ส่วนหัว H: ส่วนหัว) .println (H.ToString ());} สตริงผลลัพธ์ = สตริงใหม่ (post.getResponseBodyString (). getBytes ("GBK"));4.php
$ url = 'http: //sms.webchinese.cn/web_api/? uid = account & key = interface key & smsmob = หมายเลขมือถือ & smstext = เนื้อหา sms'; echo get ($ url); ฟังก์ชั่นรับ ($ url) {ถ้า (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 curl_setopt ($ ch, curlopt_connecttimeout, $ timeout); $ file_contents = curl_exec ($ ch); curl_close ($ ch);} return $ file_contents;}5.vb.net
'เรียก SMS, nolist เพื่อรับหมายเลข .cn/web_api/? uid = บัญชี & key = อินเทอร์เฟซคีย์ & smsmob = หมายเลขมือถือ & smstext = เนื้อหา sms "dim webclient เป็น net.webclient () try'dim responsedata เป็น byte () = dim srcstring เป็นสตริง = webclient.downloadstring (url) "-444" ฟังก์ชั่นการลอง
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม Java ของทุกคน