Cet article décrit les méthodes de mise en œuvre de la fonction d'envoi de masse des SMS par Java, PHP, C # et ASP. Partagez-le pour votre référence. Les détails sont les suivants:
Tout d'abord, allez sur http://www.smschinese.cn/ pour télécharger le package JAR et enregistrer l'utilisateur, puis appelez l'interface API pour obtenir la clé secrète
1. Exemple d'appel ASP
<% 'Fonction commune' Entrez l'URL de la page Web de destination, et la valeur de retour GetHTTPPAGE est le code html de la fonction Web de destination Gethttppage (URL) dim httpset http = server.createObject ("msxml2.xmlhttp") http. Ouvrir "get", url, falsehttp .send () if http.readystate <> 4 puis exiter functionend ifGettppage = byTestObstr (http.Responsebody, "gb2312") set http = rien err.number <> 0 alors. ByTestobstr (body, cset) dim objstreamset objstream = server.createObject ("adodb.stream") objstream.type = 1OBJStream.Mode = 3OBjstream.openobjstream.write bodyobjStream.position = 0oBjstream.type = 2OBJstream.Charset = CsetBytestob objstream.closeset objstream = Nothing Function 'Combinez l'URL soumise et ajoutez votre propre compte et mot de passe sms_url = "http://sms.webchinese.cn/web_api/?uid=Account&key=Interface Key & smsmob = Mobile Number & SMSTEXT = SMS Response". Écrivez GethTTPPAGE (SMS_URL)%>2.C # Appel
// L'espace de noms requis est d'utiliser System.net; en utilisant System.io; en utilisant System.Text; // lorsque l'appel, vous n'avez qu'à passer l'URL orthographiée à la fonction. Jugez simplement la valeur de retour publique String gethtmlfromurl (Url de chaîne) {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 (compatible; msie 6.0; windows nt 5.1)"; hr.method = "get" ; hr.timeout = 30 * 60 * 1000; weBResponse hs = hr.getResponse (); stream sr = hs.getResponseRam (); streamReader ser = new StreamReader (sr, coding.default); strret = ser.readtoend (); } catch (exception ex) {strret = null;} return strret;}3. Call Java
Importer java.io.unsupportedEncodingException; import org.apache.commons.httpclient.header; import org.apache.commons.httpclient.httpclient; import org.apache.commons.httpclient.namevaluepair; import org.apache.Commons.httpclient.Methods .PostMethod; classe publique sendmsg_webchinese {public static void main (string [] args) lève une exception {httpclient client = new httpclient (); postMethod post = new postMethod ("http://gbk.sms.webchinese.cn"); .AdDrequestHeader ("Content-Type", "Application / X-Www-Form-Urlencoded; charSet = GBK"); // Set transcoding nameValuepair [] data = {new nameValuepair ("uid", "ce site username", new NameValuePair ("Key", "Interface Security Motway"), nouveau NameValuePair ("SMSMOB", "Numéro de téléphone mobile"), nouveau NameValuepair ("SMSTEXT", "SMS Content")}; ExecuteThod (POST); En-tête d'en-tête [] en-têtes = post.getResponseHeashes (); int statuscode = post.getStaturScode (); system.out.println ("statuscode:" + statuscode); for (en-tête h: en-têtes) {System.out .println (h.toString ());} string result = new String (post.getResponseBodyAsstring (). GetBytes ("gbk");4.Php
$ url = 'http: //sms.webchinese.cn/web_api/? uid = compte & key = interface key & smsmob = mobile numéro & smstext = sms contenu'; 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);} return $ file_contents;}5.vb.net
«Appelez pour envoyer des SMS, Nolist pour recevoir le numéro. .cn / web_api /? uid = compte & key = interface key & smsmob = numéro mobile & smstext = contenu sms "dim webclient as newt net.webclient () try'dim répondata as byte () = dim srcstring as string = webclient.downloadString (url) return srcStringCrand Fonction de fin d'essai "-444"
J'espère que cet article sera utile à la programmation Java de tous.