用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

webservice中http拼接方式

2019-09-10 作者:云代码会员举报

[java]代码库

//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;
	}


分享到:
更多

网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。