java、php、C#、asp实现短信群发功能的方法
程序员文章站
2024-03-01 18:02:52
本文实例讲述了java、php、c#、asp实现短信群发功能的方法。分享给大家供大家参考。具体如下:
首先去http://www.smschinese.cn/上下载jar...
本文实例讲述了java、php、c#、asp实现短信群发功能的方法。分享给大家供大家参考。具体如下:
首先去http://www.smschinese.cn/上下载jar包以及注册用户,然后调用api接口,取得秘钥
1. asp 调用例子
<% '常用函数 '输入url目标网页地址,返回值gethttppage是目标网页的html代码 function 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.close set objstream = nothing end function '自已组合一下提交的url加入自己的账号和密码 sms_url="http://sms.webchinese.cn/web_api/?uid=账号&key=接口密钥&smsmob=手机号码&smstext=短信内容" response.write gethttppage(sms_url) %>
2.c# 调用
//需要用到的命名空间 using system.net; using system.io; using system.text; //调用时只需要把拼成的url传给该函数即可。判断返回值即可 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 = 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调用
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 httpclient(); postmethod post = new postmethod("http://gbk.sms.webchinese.cn"); post.addrequestheader("content-type","application/x-www-form-urlencoded;charset=gbk");//在头文件中设置转码 namevaluepair[] data ={ new namevaluepair("uid", "本站用户名"),new namevaluepair("key", "接口安全密码"),new namevaluepair("smsmob","手机号码"),new namevaluepair("smstext","短信内容")}; 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=账号&key=接口密钥&smsmob=手机号码&smstext=短信内容'; 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
'调用发送短信,nolist接收号码.多个之间用,分开,memo内容70字 public function sendsms(byval nolist as string, byval memo as string) as string dim url as string = "http://sms.webchinese.cn/web_api/?uid=账号&key=接口密钥&smsmob=手机号码&smstext=短信内容" 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
希望本文所述对大家的java程序设计有所帮助。
上一篇: java String的深入理解
下一篇: MyBatis插入数据返回主键的介绍