服务器之家

服务器之家 > 正文

Java调取创蓝253短信验证码的实现代码

时间:2021-04-19 14:27     来源/作者:创蓝253

基于创蓝253短信服务平台的java调用短信接口api

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.bcloud.msg.http;
import java.io.bytearrayoutputstream;
import java.io.inputstream;
import java.net.urldecoder;
import org.apache.commons.httpclient.httpclient;
import org.apache.commons.httpclient.httpstatus;
import org.apache.commons.httpclient.namevaluepair;
import org.apache.commons.httpclient.uri;
import org.apache.commons.httpclient.methods.getmethod;
     /**
     *
     * @param url 应用地址,类似于http://ip:port/msg/
     * @param account 账号
     * @param pswd 密码
     * @param mobile 手机号码,多个号码使用","分割
     * @param msg 短信内容
     * @param needstatus 是否需要状态报告,需要true,不需要false
     * @return 返回值定义参见http协议文档
     * @throws exception
     */
     public static string batchsend(string url, string account, string pswd, string mobile, string msg,
              boolean needstatus, string extno) throws exception {
          httpclient client = new httpclient();
          getmethod method = new getmethod();
          try {
              uri base = new uri(url, false);
              method.seturi(new uri(base, "httpbatchsendsm", false));
              method.setquerystring(new namevaluepair[] {
                        new namevaluepair("account", account),
                        new namevaluepair("pswd", pswd),
                        new namevaluepair("mobile", mobile),
                        new namevaluepair("needstatus", string.valueof(needstatus)),
                        new namevaluepair("msg", msg),
                        new namevaluepair("extno", extno),
                   });
              int result = client.executemethod(method);
              if (result == httpstatus.sc_ok) {
                   inputstream in = method.getresponsebodyasstream();
                   bytearrayoutputstream baos = new bytearrayoutputstream();
                   byte[] buffer = new byte[1024];
                   int len = 0;
                   while ((len = in.read(buffer)) != -1) {
                        baos.write(buffer, 0, len);
                   }
                   return urldecoder.decode(baos.tostring(), "utf-8");
              } else {
                   throw new exception("http error status: " + method.getstatuscode() + ":" + method.getstatustext());
              }
          } finally {
              method.releaseconnection();
          }
     }
}

总结

以上所述是小编给大家介绍的java调取创蓝253短信验证码的实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:https://www.cnblogs.com/chuanglan253/archive/2018/04/03/8706305.html

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部