athrunwang

纪元
数据加载中……
http短信接口

[代码] [Java]代码

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

posted on 2011-12-26 22:22 AthrunWang 阅读(211) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: