顺丰快递下单接口
                            
                            
                            /*下單測試接口*/
@PostMapping(value = "/test")
@ApiOperation(value = "順風--下單")
public R test() throws IOException {//收貨人信息Map<String,Object> receive=new HashMap<>();receive.put("user_name", URLEncoder.encode("小明"));receive.put("user_phone","13855552125");receive.put("user_address",URLEncoder.encode("七里河區125號"));receive.put("user_lng","116.382342");receive.put("user_lat","39.923099");//將收貨人信息轉成json對象JSONObject json = new JSONObject(receive);//快遞要發的商品詳情List<JSONObject> product_detai=new ArrayList<>();Map<String,Object> pd=new HashMap<>();pd.put("product_name",URLEncoder.encode("食品"));pd.put("product_num",1);JSONObject pdjons=new JSONObject(pd);product_detai.add(pdjons);//訂單詳情(必須傳)Map<String,Object> order_detail=new HashMap<>();order_detail.put("total_price",100);order_detail.put("product_type",1);order_detail.put("weight_gram",10);order_detail.put("product_num",1);order_detail.put("product_type_num",1);// order_detail.put("product_detail",product_detai);//順風接口需要的其他參數Date date = new Date();long push_time=date.getTime()/1000;Map<String,Object> map=new HashMap<>();map.put("dev_id",APP_ID);map.put("shop_id",shop_id);map.put("shop_order_id", OrderNumUtil.getOrderIdByTime());map.put("order_source","1");map.put("pay_type",0);map.put("order_time",push_time);map.put("is_appoint",0);map.put("is_insured",0);map.put("push_time",push_time);map.put("version",17);map.put("receive",json);//收貨人信息jsonmap.put("order_detail",order_detail);///訂單信息jsonJSONObject jsonObj=new JSONObject(map);String jsonParam=jsonObj.toString();//順風下單接口String url="https://commit-openic.sf-express.com/open/api/external/createorder?sign="+sign(jsonParam);CloseableHttpClient closeableHttpClient = HttpClients.createDefault();CloseableHttpResponse closeableHttpResponse;//發送post請求HttpPost httpPost = new HttpPost(url);httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");StringEntity entity = new StringEntity(jsonParam, ContentType.create("text/json", "UTF-8"));httpPost.setEntity(entity);RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(2000).setConnectTimeout(2000).build();httpPost.setConfig(requestConfig);closeableHttpResponse = closeableHttpClient.execute(httpPost);int statusCode = closeableHttpResponse.getStatusLine().getStatusCode();if (statusCode == HttpStatus.SC_OK) {//下單成功,處理自己的代碼}//接口返回結果HttpEntity httpEntity = closeableHttpResponse.getEntity();String asset_synchronization = EntityUtils.toString(httpEntity, "UTF-8");JSONObject data =JSON.parseObject(asset_synchronization);return R.ok(data);
}
                            
                        
                        
                        總結
 
                            
                        - 上一篇: linux修改ip配置文件路径,Linu
- 下一篇: 辅助软件
