Java调取创蓝253短信验证码的实现代码
程序员文章站
2023-10-20 12:14:38
基于创蓝253短信服务平台的java调用短信接口api
package com.bcloud.msg.http;
import java.io.bytearra...
基于创蓝253短信服务平台的java调用短信接口api
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短信验证码的实现代码,希望对大家有所帮助