@RequestMapping(value="/update") @ResponseBody public String update(@Context HttpServletRequest request,@Context HttpServletResponse response) { System.err.println("进来了"); // TODO Auto-generated method stub try { StringBuilder sb = new StringBuilder(); InputStream is = null; try { is = request.getInputStream(); BufferedReader reader = new BufferedReader( new InputStreamReader(is)); String line = null; while ((line = reader.readLine()) != null) { sb.append(line ); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } String result = sb.toString(); System.err.println(result+"快递开放平台传的参数"); JSONObject obj = JSON.parseObject(result); System.err.println(obj); String params2= obj.getString("params"); System.err.println(params2); JSONArray obj2=JSON.parseArray(params2); System.out.println(obj2); String arr=obj2.getString(0); System.out.println(arr); JSONObject obj3 = JSON.parseObject(arr); String orderNo=obj3.getString("orderNo"); System.out.println(orderNo); String state=obj3.getString("status"); System.err.println(state); String ewbNo=obj3.getString("ewbNo"); System.err.println(ewbNo); if(orderNo==null||state==null){ JSONObject json =new JSONObject(); json.put("result", false); json.put("resultCode", -1); json.put("resultInfo", "失败"); json.put("reason", "传参数据不正确"); return json.toJSONString(); }else{ Map<String, Object>map=new HashMap<String, Object>(); map.put("order_no", orderNo); map.put("waybill_status", state); map.put("waybill_no", ewbNo); int i= orderService.updateState(map); System.err.println(i+"是否跟新了"); if(i==1){ JSONObject json=new JSONObject(); json.put("result", true); json.put("resultCode", 200); json.put("resultInfo","成功" ); json.put("reason", "传参格式正确"); return json.toJSONString(); }else{ JSONObject json=new JSONObject(); json.put("result", false); json.put("resultCode", -1); json.put("resultInfo","失败" ); json.put("reason", "参数格式不对"); return json.toJSONString(); } } } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } return null; } |