注意事项--接入必读 1.post数据msg字段的内容要为utf-8格式,尽量不要get方式提交,post提交兼容性好 2.短信内容需要为正规的业务内容,不能乱发内容,不能乱测.否则发送失败,可以发送通知、验证码和祝福等短信,具体的发送内容咨询商务 3.短信尾端需要加上签名,签名一般为客户公司简称比如 "【浪勤科技】"、"【阿里云】"、"【网易】" 4.短信发送有防轰炸过滤,一个号码一分钟不要超过2条,一天内不要超过8条,多次测试请换号码测试,狂发将被拉黑名单 5.收不到短信的号码最为常见的是被运营商加入“黑名单”,联系我们客服解除即可,未解除之前请换号码测试 6.测试短信内容例子:“您好,你的验证码:168458,请注意保管【浪勤科技】” 7.真实ip和帐号密码请联系商务经理索要 8.最近有比较多的不法分子利用客户的接入短信验证简单作短信轰炸业务,严重影响客户正常的短信发送业务和短信浪费,为了防止此类情况发生,客户在短信发送页面上需要添加60S保护、图文验证(干扰码不能太简单)、代码程序保 护(强行限制每个ip、每个号码每小时内每天内发送)、改用post提交。60s限制、ip限制、cookie或session限制能简单绕过,60秒、代码保护二者需要同时结合。 9.控制验证手机的有效性:如果该手机多次触发验证码,收到验证码后多次(比如3次)都没有输入验证码验证,可判断该手机号码为恶意号码,从而停止给这个号码给发送短信(或规定时间内不允许向此手机发送短信)。 1. ASP 调用例子 Dim sendinfo 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,"utf-8") set http=nothing if err.number<>0 then err.Clear end if 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 Function GBtoUTF8(szInput) Dim wch, uch, szRet Dim x Dim nAsc, nAsc2, nAsc3 '如果输入参数为空,则退出函数 If szInput = "" Then GBtoUTF8= szInput Exit Function End If '开始转换 For x = 1 To Len(szInput) wch = Mid(szInput, x, 1) nAsc = AscW(wch) If nAsc < 0 Then nAsc = nAsc + 65536 If (nAsc And &HFF80) = 0 Then szRet = szRet & wch Else If (nAsc And &HF000) = 0 Then uch = "%" & Hex(((nAsc \ 2 ^ 6)) Or &HC0) & Hex(nAsc And &H3F Or &H80) szRet = szRet & uch Else uch = "%" & Hex((nAsc \ 2 ^ 12) Or &HE0) & "%" & _ Hex((nAsc \ 2 ^ 6) And &H3F Or &H80) & "%" & _ Hex(nAsc And &H3F Or &H80) szRet = szRet & uch End If End If Next GBtoUTF8= szRet End Function 'sendinfo = server.urlEncode(GBtoUTF8("【票务中心】您好!您的验证码是:5460.")) sendinfo = GBtoUTF8("【浪勤科技】您好!您的验证码是:5460.请注意保管.") sms_url ="http://ip:7003/http.aspx?act=sendmsg&username=账号&passwd=密码&msg=内容&phone=手机1,手机2&port=&sendtime=2008-01-01 12:00:00" response.write getHTTPPage(sms_url) '真实ip请参照开发文档 2.C# 调用 //需要用到的命名空间 using System.Net; using System.IO; using System.Text; //调用时只需要把拼成的URL传给该函数即可。判断返回值即可 string url = "http://ip:7003/http.aspx?act=sendmsg&username=账号&passwd=密码&msg=您好,你的验证码:8888【浪勤科技】&phone=手机1,手机2&port=&sendtime=2008-01-01 12:00:00";////真实ip请参照开发文档 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.UTF8); strRet = ser.ReadToEnd(); }catch (Exception ex){ strRet = null; } return strRet; } //------------参考代码2 string data = "act=sendmsg&username=username&passwd=password&phone=" + phonenumber + "&msg=您好,你的验证码:" + code + "【浪勤科技】&port=&sendtime="; HttpWebRequest hr = (HttpWebRequest)WebRequest.Create("http://ip/msg/HttpSendSM"); hr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; hr.ContentType = "application/x-www-form-urlencoded"; hr.Method = "POST"; hr.Timeout = 30 * 60 * 1000; byte[] datas = Encoding.UTF8.GetBytes(data); hr.ContentLength = datas.Length; Stream requestStream = hr.GetRequestStream(); requestStream.Write(datas, 0, datas.Length); requestStream.Close(); WebResponse hs = hr.GetResponse(); Stream sr = hs.GetResponseStream(); StreamReader ser = new StreamReader(sr, Encoding.UTF8); string strRet = ser.ReadToEnd(); 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://ip:7003/http.aspx?act=sendmsg"); //真实ip请参照开发文档 post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");//在头文件中设置转码 NameValuePair[] data ={ new NameValuePair("username", "账号"),new NameValuePair("passwd", "接口密钥"),new NameValuePair("phone","手机号码"),new NameValuePair("msg","您好,你的验证码:8888【浪勤科技】"),new NameValuePair("port",""),new NameValuePair("sendtime","")}; 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()); System.out.println(result); //打印返回消息状态 post.releaseConnection(); } } 说明:如果返回值是200,应该是整段程序代码没有执行完整,只获取到client.executeMethod(post)HTTP状态码的消息;接口是提交成功,没有执行下半部的返回消息代码。 client.executeMethod(post);HTTP状态码参考:http://baike.baidu.com/view/1790469.htm jar包下载 commons-logging-1.1.1.jar commons-httpclient-3.0.jar commons-codec-1.9.jar 4.PHP /** * 注意事项 * 1.post数据不需要urldecode,msg字段的内容要为utf-8格式,尽量不要get方式提交 * 2.短信内容需要为正规的业务内容,不能乱发内容,不能乱测.否则发送失败,可以发送通知、验证码和祝福等短信,具体的发送内容咨询商务 * 3.短信尾端需要加上签名,签名一般为客户公司简称比如 "【浪勤科技】"、"【阿里云】"、"【网易】" * 4.短信发送有防轰炸过滤,一个号码一分钟不要超过2条,一天内不要超过8条,多次测试请换号码测试,狂发将被拉黑名单 * 5.收不到短信的号码最为常见的是被运营商加入“黑名单”,联系我们客服解除即可,未解除之前请换号码测试 * 6.测试短信内容例子:“您好,你的验证码:168458,请注意保管【浪勤科技】” * **/ $url='http://ip:7003/http.aspx?act=sendmsg'; //真实ip请参照开发文档或咨询商务 echo Get($url); function Get($url){ $ch = curl_init(); $timeout = 20; /** 有些curl版本的post这样的数据格式 **/ $post_data = "username=账号&passwd=密码&phone=手机号码1,号码2,号码3,后面以此类推&msg=您好,你的验证码:8888【浪勤科技】&port=&sendtime="; /** 有些curl版本的curl数据格式为数组 你们接入时要注意 $post_data = array( "username"=>"账号", "passwd"=>"密码", "phone"=>"手机号码1,号码2,号码3", "msg"=>"您好,你的验证码:8888【浪勤科技】", "port"=>"", "sendtime"=>'' ); **/ curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //post数据 curl_setopt($ch, CURLOPT_POST, 1); //post的变量 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $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://ip:7003/http.aspx?act=sendmsg&username=账号&passwd=密码&msg=您好,你的验证码:8888【浪勤科技】&phone=手机1,手机2&port=&sendtime=2008-01-01 12:00:00";" //真实ip请参照开发文档 Dim webClient As New Net.WebClient() Try Dim srcString As String = webClient.DownloadString(Url) Return srcString Catch Return "网络错误." End Try End Function 注意 短信平台使用utf-8的编码,如果你的项目使用gbk编码, 短信内容需要转为utf-8编码提交.