Java, PHP, C #, ASP to achieve the method of mass message _java

Source: Internet
Author: User

This article describes the Java, PHP, C #, ASP to achieve the method of mass message. Share to everyone for your reference. Specifically as follows:

First go to http://www.smschinese.cn/download jar package and register user, then call API interface, get secret key

1. ASP Call Example

<%
' Common functions
' Enter URL destination page address, return value Gethttppage is the HTML code function of the target page
gethttppage (URL)
Dim Http
Set Http=server.createobject ("MSXML2.") XMLHTTP ")
Http.open" Get ", Url,false
http.send ()
if http.readystate<>4 then 
Exit function End
If
gethttppage=bytestobstr (http.responsebody, "GB2312")
set http=nothing
if Err.Number <>0 then err. Clear End 
function
function bytestobstr (body,cset)
Dim objstream
Set objstream = Server.CreateObject ("ADODB.stream")
objstream. Type = 1
objstream. Mode =3
objstream. Open
objstream. Write body
objstream. Position = 0
objstream. Type = 2
objstream. Charset = Cset
bytestobstr = objstream. ReadText 
objstream. The close
Set objstream = no end
Function

' combines the submitted URL to add your own account and password
sms_url= ' http:// Sms.webchinese.cn/web_api/? uid= account &key= interface key &smsmob= mobile phone number &smstext= SMS Content "
Response.Write gethttppage (Sms_url)

2.c# Call

The namespace using system.net that needs to be used
;
Using System.IO;
Using System.Text;
You only need to pass the spelled URL to the function when calling. The return value can be judged by 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" (compatible; MSIE 6.0; Windows NT 5.1) ";
hr. method = ' Get ';
hr. Timeout = * 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 Call

Import 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; public class Sendmsg_webchinese {public static void main (string[] args) throws Exception {httpclient client = new HTTPC
Lient (); 
Postmethod post = new Postmethod ("http://gbk.sms.webchinese.cn"); Post.addrequestheader ("Content-type", "APPLICATION/X-WWW-FORM-URLENCODED;CHARSET=GBK");//Set transcoding in header file NameValuePair [] Data ={new Namevaluepair ("Uid", "site username"), new Namevaluepair ("Key", "Interface Security password"), New Namevaluepair ("Smsmob", "mobile number"), new
Namevaluepair ("Smstext", "SMS Content")};

Post.setrequestbody (data);
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 (); }
}

4.PHP

$url = ' http://sms.webchinese.cn/web_api/?Uid= account &key= interface key &smsmob= mobile phone number &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);
return $file _contents;
}

5.vb.net

' Call to send SMS, nolist receive number. Multiple, separate, Memo content 70 Word public
Function 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= mobile phone number &smstext= SMS Content "
Dim webClient As New net.webclient ()
Try
' Dim ResponseData as Byte () = 
Dim srcstring as String = webclient.downloadstring (URL) return
srcstring
Catch return
" -444"
End Try-end
Function

I hope this article will help you with your Java programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.