SpringCloud(11)—— 项目经验之(RestTemplate请求)

http://www.cnblogs.com/BensonHe/p/4602746.html



/**
* 对接国寿i购系统 * * @param query */ @Override public ResponseInfo<Map<String, String>> dockIGou(ExclusiveDockIGouInputDTO query) { try { //请求格式(定位具体方法) Map map2 = new HashMap(); map2.put("state", "new"); map2.put("action", "ShopAction"); map2.put("method", "mall"); //请求格式(具体参数) Map map3 = new HashMap(); map3.put("Usercode", query.getUsercode()); map3.put("ExtraParams", query.getExtraparams()); map3.put("Mobile", query.getMobile()); map3.put("Source", configProperties.getIgousouce()); //秘钥 Map mp4 = new HashMap(); mp4.put("id", ""); mp4.put("Resolution", ""); mp4.put("model", "iPhone"); mp4.put("enterprise", "N"); mp4.put("appversion", "2.0"); mp4.put("session", ""); mp4.put("buildversion", "Ver:1.5_CUS_PROD_131212"); mp4.put("Memory", ""); mp4.put("password", ""); mp4.put("sysversion", "9.2"); mp4.put("manufacturer", "Apple"); mp4.put("devicemodel", "iPhone"); mp4.put("name", ""); mp4.put("udid", "DA3A075D-CE35-47B7-89DB-8ECB9013D969"); //请求格式 Map map1 = new HashMap(); map1.put("head", map2); map1.put("info", map3); map1.put("security", mp4); LOGGER.debug("获取i购地址接口参数:" + JSONObject.toJSONString(map1)); String html = sendToService(configProperties.getIgouurl(), JSONObject.toJSONString(map1)); LOGGER.debug("获取掌上国寿对接i购地址:" + JSONObject.parseObject(html)); return new ResponseInfo(true, "success", JSONObject.parseObject(html)); } catch (Exception e) { LOGGER.error("对接国寿i购异常,原因:" + CommonUtil.getExceptionStackTrace(e)); return new ResponseInfo<>(false, "系统异常...", 400); } } /** * 发生post请求 * * @param serverUrl * @param jsonObj * @return */ public static String sendToService(String serverUrl, String jsonObj) { String result = ""; try { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8"); headers.setContentType(type); headers.add("Accept", MediaType.APPLICATION_JSON.toString()); HttpEntity<String> formEntity = new HttpEntity<String>(jsonObj, headers); result = restTemplate.postForObject(serverUrl, formEntity, String.class); LOGGER.debug("连接服务器:" + serverUrl + ",返回结果" + result); return result; } catch (Exception e) { LOGGER.error("连接服务器:" + serverUrl + "失败,原因" + e.getMessage()); return result; } }

 

转载于:https://www.cnblogs.com/xushuyi/articles/7131751.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值