java 向手机发送消息

HttpClient client = new HttpClient();
    PostMethod post = new PostMethod("http://gbk.sms.webchinese.cn");//http://utf8.sms.webchinese.cn/    http://gbk.sms.webchinese.cn
    post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");//在头文件中设置转码
    /*
     * Uid--该网站的用户名
     * key--短信秘钥
     * smsMob--手机号,多个手机号以‘,’分隔
     * smsText--短信发送的消息
     */
    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();

    }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的 Java 代码示例,可以用来发送消息到致信: ```java import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; public class SendMessageToZhiXin { public static void main(String[] args) { try { // 设置接口地址和参数 String url = "http://api.zx.ums86.com:8899/sms/Api/Send.do"; String account = "your_account"; // 替换成你的账号 String password = "your_password"; // 替换成你的密码 String phone = "your_phone_number"; // 替换成你要发送手机号 String content = URLEncoder.encode("测试短信", "UTF-8"); // 替换成你要发送的内容 // 发送 HTTP 请求 URL obj = new URL(url + "?SpCode=" + account + "&LoginName=" + account + "&Password=" + password + "&MessageContent=" + content + "&UserNumber=" + phone); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); // 读取响应结果 BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); // 输出响应结果 System.out.println(response.toString()); } catch (Exception e) { e.printStackTrace(); } } } ``` 注意:在发送短信之前,需要先注册致信账号并且获取账号和密码。此外,你还需要将代码中的 `your_account`、`your_password` 和 `your_phone_number` 替换成你自己的账号、密码和手机号。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值