01
package
com.sun.duanxin;
02
import
java.io.BufferedReader;
03
java.io.IOException;
04
java.io.InputStreamReader;
05
java.io.UnsupportedEncodingException;
06
java.net.HttpURLConnection;
07
java.net.MalformedURLException;
08
java.net.URL;
09
java.net.URLEncoder;
10
11
/**
12
*
13
* 首先到:http://www.woxp.cn/ 申请你的http短信接口的账号 ,有了账号你才能发信息
14
15
*/
16
17
public
class
TT {
18
private
Integer x_eid =
0
;
19
String x_uid =
"XXXX"
// // 您申请的账号
20
String x_pwd_md5 =
// /http://tool.cnzz.cn/tool/md5.asp
21
Integer x_gate_id =
300
22
String SendSms(String mobile, String content)
23
throws
UnsupportedEncodingException {
24
Integer x_ac =
// 发送信息
25
String result =
"-20"
26
String memo = content.length() <
70
? content.trim() : content.trim()
27
.substring(
,
);
28
StringBuilder sb =
new
StringBuilder();
29
sb.append(
"http://gateway.woxp.cn:6630/utf8/web_api/?x_eid="
30
sb.append(x_eid);
31
"&x_uid="
).append(x_uid);
32
"&x_pwd_md5="
).append(x_pwd_md5);
33
"&x_ac="
).append(x_ac);
34
"&x_gate_id="
).append(x_gate_id);
35
"&x_target_no="
).append(mobile);
36
"&x_memo="
).append(URLEncoder.encode(memo,
"utf-8"
));
37
try
{
38
URL url =
URL(sb.toString());
39
httpconn = (HttpURLConnection) url.openConnection();
40
BufferedReader rd =
BufferedReader(
InputStreamReader(
41
httpconn.getInputStream()));
42
result = rd.readLine();
43
if
(result.equals(
"0"
))
44
45
System.out.println(
"短信发送成功!"
46
}
47
else
"-11"
48
49
"账号或者密码不存在请重试!"
50
51
"-13"
52
53
"您的余额不足请充值!"
54
55
56
"短信发送失败"
57
58
rd.close();
59
60
catch
(MalformedURLException e) {
61
e.printStackTrace();
62
63
(IOException e) {
64
// TODO Auto-generated catch block
65
66
finally
67
(httpconn !=
null
) {
68
httpconn.disconnect();
69
httpconn =
71
72
return
result;
73
74
static
void
main(String[] args)
75
TT t =
TT();
76
String res = t.SendSms(
"151XXXXX060"
"我在测试发短信"
77
78
posted on 2011-12-26 22:22 AthrunWang 阅读(212) 评论(0) 编辑 收藏