您的位置:首页 > 其它

未来无线发送短信接口文档

2017-08-28 17:44 169 查看
public Map sendMessage(SmsForm smsForm) throws IOException{
String phone = smsForm.getPhone();
String content = smsForm.getContent();
// 数字签名,签名内容根据 “短信内容+客户密码”进行MD5编码后获得
String sign = content + password;
sign = Md5.getMd5(sign.getBytes("UTF-8"));
//长号码,选填
String sp_code = "";
// 是否需要状态报告
String need_report = "yes";
// 业务标识,选填,由客户自行填写不超过20位的数字
String uid = "";
String json_send_sms = "{\"cust_code\":\"" + account + "\",\"sp_code\":\"" + sp_code + "\",\"content\":\"" + content +
"\",\"destMobiles\":\"" + phone + "\",\"uid\":\"" + uid + "\",\"need_report\":\"" + need_report + "\",\"sign\":\"" + sign + "\"}";
URL urls = new URL(url);
HttpURLConnection httpURLConnection = (HttpURLConnection) urls.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
OutputStream out = httpURLConnection.getOutputStream();
out.write(json_send_sms.getBytes("UTF-8"));
LOG.info("send msg:\t"+json_send_sms);
InputStream inputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader reader = null;
StringBuffer resultBuffer = new StringBuffer();
String tempLine = null;
try {
inputStream = httpURLConnection.getInputStream();
inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
reader = new BufferedReader(inputStreamReader);
while ((tempLine = reader.readLine()) != null) {
resultBuffer.append(tempLine);
}
LOG.info("recv msg:\t"+resultBuffer.toString());
} catch (Exception e) {
throw e;
} finally {
if (reader != null) {
reader.close();
}
if (inputStreamReader != null) {
inputStreamReader.close();
}
if (inputStream != null) {
inputStream.close();
}
httpURLConnection.disconnect();
}
JSONObject jasonObject = JSONObject.parseObject(resultBuffer.toString());
Map map = jasonObject;

Map<String,Object> message = new HashMap<>();
if(map.get("respCode")!=null && "0".equals(map.get("respCode"))){
JSONArray jasonArray = (JSONArray) map.get("result");
JSONObject jasonObject2 = (JSONObject) jasonArray.get(0);
Map result2 = jasonObject2;
if(result2.get("code")!=null && !"0".equals(result2.get("code"))){
message.put("errors",map);
}else {
message.put("datas",map);
}
}else {
message.put("outcome",map);
}
return message;
}


接口文档参考链接:

http://43.243.130.33:8099/support/http-3.0.jsp
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: