java 程序实现短信发送(可调⽤免费短信接⼝)附:
1. ASP 调⽤例⼦
<%
'常⽤函数
'输⼊url ⽬标⽹页地址,返回值getHTTPPage 是⽬标⽹页的html 代码function getHTTPPage(url)
01. package 02. 03. import 04. import 05. import 06. import 07. 08. public class 09. 10. public static void throws 11. 12. new 13. new "sms.webchinese/web_api/"14. "Content-Type"15. "application/x-www-form-urlencoded;charset=gbk"// 在头⽂件中设置转码16. new "Uid""cshxxxxxxxx"// 注册的⽤户名17. new "Key""53295058d1c46710666a"// 注册成功后,登录⽹站使⽤的密钥18. new "smsMob""187xxxxxxx"// ⼿机号码19. new "smsText""以后给我⽼实点哈。。。。听话。。。"//设置短信内容
20. 21.
运⾏条件:引⼊jar 包. commons-codec-1.4
commons-httpclient-3.1
commons-logging-1.1.1
23.
GBK 编码发送接⼝地址:
gbk.sms.webchinese/?Uid=本站⽤户名&Key=接⼝安全密码&smsMob=⼿机号码&smsText=短信内容 UTF-8编码发送接⼝地址:
utf8.sms.webchinese/?Uid=本站⽤户名&Key=接⼝安全密码&smsMob=⼿机号码&smsText=短信内容获取短信数量接⼝地址(UTF8):
sms.webchinese/web_api/SMS/?Action=SMS_Num&Uid=本站⽤户名&Key=接⼝安全密码
获取短信数量接⼝地址(GBK):
=本站⽤户名&Key=接⼝安全密码01. 02. 03. 04. 05. int 06. "statusCode:"07. for 08. 09. 10. new 11. "gbk"
12. 13. 14.
function getHTTPPage(url)
dim Http
set ateobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
adystate<>4 then
exit function
java在哪里可以免费自学end if
getHTTPPage=sponseBody,"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="sms.webchinese/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.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.apachemons.httpclient.Header;
import org.apachemons.httpclient.HttpClient;
import org.apachemons.httpclient.NameValuePair;
import org.hods.PostMethod;
public class SendMsg_webchinese {
public static void main(String[] args)throws Exception
{
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("gbk.sms.webchinese");
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);
Header[] headers = ResponseHeaders();
int statusCode = StatusCode();
int statusCode = StatusCode();
System.out.println("statusCode:"+statusCode);
for(Header h : headers)
{System.out.String());
}
String result = new ResponseBodyAsString().getBytes("gbk"));
System.out.println(result);
}
}
jar 包下载
4.PHP
$url='sms.webchinese/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 = "sms.webchinese/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

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。