PHP
·
发表于 5年以前
·
阅读量:8295
//http拼接方式
private Message sendNew(String method,String userName,String title,String content,String tel){
Message result = new Message();
try {
//判断是否是自定义手机号码
JSONObject obj=new JSONObject();
if(tel!= null ||!"".equals(tel) ){
obj.put("mobiles",tel);
}
obj.put("emsEnterpriseID","111");
obj.put("emsLoginName","111");
obj.put("emsPassword",MD5.toMD5("123456"));
DefaultHttpClient httpClient = new DefaultHttpClient();
String soapRequestData = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\""
+ " xmlns:ser=\"http://service.msgbuss.ceair.com/\">"
+"<soapenv:Header/>"
+"<soapenv:Body>"
+"<ser:send>"
+"<messageRequestVO>"
+"<bizProduct>"+method+"</bizProduct>"
+"<content>"+content+"</content>"
+"<extention>"+obj.toString()+"</extention>"
+"<requestId>"+UUID.randomUUID().toString()+"</requestId>"
+"<title>"+title+"</title>"
+"<toUserId>"+userName+"</toUserId>"
+"</messageRequestVO>"
+"</ser:send>"
+"</soapenv:Body>"
+"</soapenv:Envelope>";
HttpPost httppost = new HttpPost("http://xxx.xx.x.x:8080/msgbuss/soap/sendMessage?wsdl");
try {
HttpEntity re = new StringEntity(soapRequestData,HTTP.UTF_8);
httppost.setHeader("Content-Type","application/soap+xml; charset=utf-8");
httppost.setEntity(re);
HttpResponse response = httpClient.execute(httppost);
String str = EntityUtils.toString(response.getEntity());
result.setResultCode(str.substring(str.indexOf("<resultCode>")+12,str.indexOf("</resultCode>")));
result.setMsg(str.substring(str.indexOf("<desc>")+6,str.indexOf("</desc>")));
result.setSuccess(Boolean.parseBoolean(str.substring(str.indexOf("<success>")+9,str.indexOf("</success>"))));
return result;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
httpClient.getConnectionManager().shutdown();
}
return result;
} catch (Exception e) {
result.setSuccess(false);
result.setMsg("系统异常");
}
return result;
}