|
@@ -0,0 +1,411 @@
|
|
|
|
|
+package com.muzhi.yinzhou.APITest;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.muzhi.yinzhou.service.AccessTokenService;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import okhttp3.*;
|
|
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
+
|
|
|
|
|
+import java.text.DateFormat;
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.util.Calendar;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+@SpringBootTest
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+public class Test1 {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private AccessTokenService accessTokenService;
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void panduan(){
|
|
|
|
|
+ //判断日期是否为周六周日
|
|
|
|
|
+ String date = "2022-10-08 00:00:00";
|
|
|
|
|
+ DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
+ Date date1 = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ date1 = format.parse(date);
|
|
|
|
|
+ System.out.println("date1:" + date1);
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
|
+ calendar.setTime(date1);
|
|
|
|
|
+
|
|
|
|
|
+ if (calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY||calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
|
|
|
|
|
+ System.out.println("当前日期为周六周日!");
|
|
|
|
|
+ }else {
|
|
|
|
|
+ System.out.println("当前日期为工作日");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void date(){
|
|
|
|
|
+ int dkcs = 5;
|
|
|
|
|
+ int ccts = 0;
|
|
|
|
|
+
|
|
|
|
|
+ dkcs = dkcs/2;
|
|
|
|
|
+ int dkcsLast = (int)dkcs;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (dkcs > 0){
|
|
|
|
|
+ //实际出差天数
|
|
|
|
|
+ ccts = ccts + dkcsLast;
|
|
|
|
|
+ System.out.println("实际出差天数:" + ccts);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ long startLong = new Long("1670342400000");
|
|
|
|
|
+ //将时间戳转换为时间
|
|
|
|
|
+ Date startDate = new Date(startLong);
|
|
|
|
|
+ System.out.println("出差开始时间(时间型):" + startDate);
|
|
|
|
|
+ //将时间调整为yyyy-MM-dd HH:mm:ss时间样式
|
|
|
|
|
+ String startString = simpleDateFormat.format(startDate);
|
|
|
|
|
+ System.out.println("出差开始时间(时间样式):" + startString);
|
|
|
|
|
+
|
|
|
|
|
+ long endLong = new Long("1670428800000");
|
|
|
|
|
+ //将时间戳转换为时间
|
|
|
|
|
+ Date endDate = new Date(endLong);
|
|
|
|
|
+ System.out.println("出差结束时间(时间型):" + endDate);
|
|
|
|
|
+ //将时间调整为yyyy-MM-dd HH:mm:ss时间样式
|
|
|
|
|
+ String endString = simpleDateFormat.format(endDate);
|
|
|
|
|
+ System.out.println("出差结束时间(时间样式):" + endString);
|
|
|
|
|
+
|
|
|
|
|
+ Calendar calendar1 = Calendar.getInstance();
|
|
|
|
|
+ calendar1.setTime(endDate);
|
|
|
|
|
+ //后面一天
|
|
|
|
|
+ calendar1.add(Calendar.DAY_OF_MONTH,1);
|
|
|
|
|
+ calendar1.set(Calendar.HOUR_OF_DAY,0);
|
|
|
|
|
+ calendar1.set(Calendar.MINUTE,0);
|
|
|
|
|
+ calendar1.set(Calendar.SECOND,0);
|
|
|
|
|
+ calendar1.set(Calendar.MILLISECOND,0);
|
|
|
|
|
+ String time1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar1.getTime());
|
|
|
|
|
+ System.out.println("出差结束时间后面一天零点:" + time1);
|
|
|
|
|
+
|
|
|
|
|
+ DateTime lastDateTime = DateUtil.parse(time1);
|
|
|
|
|
+ System.out.println("出差结束时间后面一天(时间型):" + lastDateTime);
|
|
|
|
|
+
|
|
|
|
|
+ //获取当天前一天的零点零分零秒
|
|
|
|
|
+ Date Date = new Date(System.currentTimeMillis());
|
|
|
|
|
+ System.out.println("当前时间:" + Date);
|
|
|
|
|
+ String dateNowString = simpleDateFormat.format(Date);
|
|
|
|
|
+ System.out.println("当前时间(时间样式):" + dateNowString);
|
|
|
|
|
+
|
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
|
+ calendar.setTime(Date);
|
|
|
|
|
+ //前一天
|
|
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH,-1);
|
|
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY,0);
|
|
|
|
|
+ calendar.set(Calendar.MINUTE,0);
|
|
|
|
|
+ calendar.set(Calendar.SECOND,0);
|
|
|
|
|
+ calendar.set(Calendar.MILLISECOND,0);
|
|
|
|
|
+ String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
|
|
|
|
|
+ System.out.println("前一天零点:" + time);
|
|
|
|
|
+
|
|
|
|
|
+ Calendar calendar111 = Calendar.getInstance();
|
|
|
|
|
+ calendar111.setTime(Date);
|
|
|
|
|
+ //前一个月第一天
|
|
|
|
|
+ calendar111.add(Calendar.MONTH,-1);
|
|
|
|
|
+ calendar111.set(Calendar.DAY_OF_MONTH,1);
|
|
|
|
|
+ calendar111.set(Calendar.HOUR_OF_DAY,0);
|
|
|
|
|
+ calendar111.set(Calendar.MINUTE,0);
|
|
|
|
|
+ calendar111.set(Calendar.SECOND,0);
|
|
|
|
|
+ calendar111.set(Calendar.MILLISECOND,0);
|
|
|
|
|
+ String FORMtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar111.getTime());
|
|
|
|
|
+ System.out.println("前一个月第一天零点:" + FORMtime);
|
|
|
|
|
+
|
|
|
|
|
+ Calendar calendar222 = Calendar.getInstance();
|
|
|
|
|
+ int month222 = calendar222.get(Calendar.MONTH);
|
|
|
|
|
+ //前一个月最后一天
|
|
|
|
|
+ calendar222.set(Calendar.MONTH,month222-1);
|
|
|
|
|
+ calendar222.set(Calendar.DAY_OF_MONTH,calendar222.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
|
|
+ calendar222.set(Calendar.HOUR_OF_DAY,0);
|
|
|
|
|
+ calendar222.set(Calendar.MINUTE,0);
|
|
|
|
|
+ calendar222.set(Calendar.SECOND,0);
|
|
|
|
|
+ calendar222.set(Calendar.MILLISECOND,0);
|
|
|
|
|
+ String TOtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar222.getTime());
|
|
|
|
|
+ System.out.println("前一个月最后一天零点:" + TOtime);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //MD5加密
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void MD5(){
|
|
|
|
|
+
|
|
|
|
|
+ /*明文
|
|
|
|
|
+ * timestamp毫秒级时间戳
|
|
|
|
|
+ * */
|
|
|
|
|
+ //当前时间的时间戳
|
|
|
|
|
+ long timeMillis = System.currentTimeMillis();
|
|
|
|
|
+ String timestamp = String.valueOf(timeMillis);
|
|
|
|
|
+ log.info("当前时间的时间戳(毫秒级):" + timestamp);
|
|
|
|
|
+
|
|
|
|
|
+ /*秘钥
|
|
|
|
|
+ * AppSecret应用秘钥
|
|
|
|
|
+ * */
|
|
|
|
|
+ String AppSecret = System.getenv("SHB_APP_SECRET");
|
|
|
|
|
+
|
|
|
|
|
+ //加密后的字符串
|
|
|
|
|
+ String encodeStr= DigestUtils.md5Hex(AppSecret + "_" + timestamp);
|
|
|
|
|
+
|
|
|
|
|
+ Map map = new HashMap();
|
|
|
|
|
+ map.put("appKey", System.getenv("SHB_APP_KEY"));
|
|
|
|
|
+ map.put("timestamp",timestamp);
|
|
|
|
|
+ map.put("verifyCode",encodeStr);
|
|
|
|
|
+ String parmsStr = JSON.toJSONString(map);
|
|
|
|
|
+
|
|
|
|
|
+ //售后宝【接口授权】
|
|
|
|
|
+ //授权码
|
|
|
|
|
+ String access_token = null;
|
|
|
|
|
+ //失效时间
|
|
|
|
|
+ String expire_time = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
+ .build();
|
|
|
|
|
+ MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
|
+ RequestBody body = RequestBody.create(mediaType, parmsStr);
|
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
|
+ .url("https://oapi.shb.ltd/service/auth/get_access_token")
|
|
|
|
|
+ .method("POST", body)
|
|
|
|
|
+ .addHeader("Content-Type", "application/json")
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+ String responseBody = response.body().string();
|
|
|
|
|
+ String substring1 = responseBody.substring(1, responseBody.length() - 1);
|
|
|
|
|
+ String substring2 = substring1.replaceAll("\\\\", "");
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(substring2);
|
|
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
|
|
+ //授权码
|
|
|
|
|
+ access_token = data.getString("access_token");
|
|
|
|
|
+ //失效时间
|
|
|
|
|
+ expire_time = data.getString("expire_time");
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ long endLong = new Long(expire_time);
|
|
|
|
|
+ //将时间戳转换为时间
|
|
|
|
|
+ Date endDate = new Date(endLong);
|
|
|
|
|
+ System.out.println("授权码失效时间(时间型):" + endDate);
|
|
|
|
|
+ //将时间调整为yyyy-MM-dd HH:mm:ss时间样式
|
|
|
|
|
+ String endString = simpleDateFormat.format(endDate);
|
|
|
|
|
+ System.out.println("授权码失效时间(时间样式):" + endString);
|
|
|
|
|
+ log.info("授权码失效时间:" + endString);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //【客户列表】
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void getKehuList(){
|
|
|
|
|
+ OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
+ .build();
|
|
|
|
|
+ MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
|
+ RequestBody body = RequestBody.create(mediaType, "{\r\n \"pageSize\":50,\r\n \"pageNum\":1\r\n}");
|
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
|
+ .url("https://oapi.shb.ltd/service/customer/get_customers?accessToken=" + System.getenv("SHB_ACCESS_TOKEN"))
|
|
|
|
|
+ .method("POST", body)
|
|
|
|
|
+ .addHeader("Content-Type", "application/json")
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //【工单类型】
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void getGongdanType(){
|
|
|
|
|
+ OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
+ .build();
|
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
|
+ .url("https://oapi.shb.ltd/service/task/get_task_types?accessToken=" + System.getenv("SHB_ACCESS_TOKEN"))
|
|
|
|
|
+ .method("GET", null)
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //【创建工单】
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void addGongdan(){
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ 【创建工单json参数】
|
|
|
|
|
+ {
|
|
|
|
|
+ "cusNo":"CUSEH00762",
|
|
|
|
|
+ "cusName":"上海市松江区城市管理行政执法局执法大队岳阳街道中队",
|
|
|
|
|
+ "address":"西林北路367号",
|
|
|
|
|
+ "lmName":"陆老师",
|
|
|
|
|
+ "lmPhone":"13371958895",
|
|
|
|
|
+ "templateId":"279bb347-913e-4627-bffc-605317774885",
|
|
|
|
|
+ "templateName":"安装工单",
|
|
|
|
|
+ "planTime":"2023-03-19"
|
|
|
|
|
+ }
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
+ .build();
|
|
|
|
|
+ MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
|
+ RequestBody body = RequestBody.create(mediaType, "{\r\n \"cusNo\":\"CUSEH00762\",\r\n \"cusName\":\"上海市松江区城市管理行政执法局执法大队岳阳街道中队\",\r\n \"address\":\"西林北路367号\",\r\n \"lmName\":\"陆老师\",\r\n \"lmPhone\":\"13371958895\",\r\n \"templateId\":\"279bb347-913e-4627-bffc-605317774885\",\r\n \"templateName\":\"安装工单\",\r\n \"planTime\":\"2023-03-19\"\r\n}");
|
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
|
+ .url("https://oapi.shb.ltd/service/task/create_task_v2?accessToken=" + System.getenv("SHB_ACCESS_TOKEN"))
|
|
|
|
|
+ .method("POST", body)
|
|
|
|
|
+ .addHeader("Content-Type", "application/json")
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+// public static String IP = "http://124.221.15.189:8002";
|
|
|
|
|
+ //调整第四版
|
|
|
|
|
+ public static String IP = "http://101.43.89.2:8002";
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void test(){
|
|
|
|
|
+ OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
+ .build();
|
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
|
+ .url(IP + "/GetKuquList")
|
|
|
|
|
+ .method("GET", null)
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ String s = null;
|
|
|
|
|
+ String s1 = null;
|
|
|
|
|
+ String s2 = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+ String result = response.body().string();
|
|
|
|
|
+ //获取接口返回的原始内容
|
|
|
|
|
+ s = JSON.toJSONString(result);
|
|
|
|
|
+ //去除返回字符串中的\转义字符
|
|
|
|
|
+ s1 = s.trim().replace("\\", "");
|
|
|
|
|
+ //去除返回字符串的首尾""双引号,去除两次
|
|
|
|
|
+ s2 = s1.replaceAll("^\"|\"$", "")
|
|
|
|
|
+ .replaceAll("^\"|\"$", "");
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ System.out.println("接口返回【库区列表】:" + s2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //查询商品库存
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void getChanpinList(){
|
|
|
|
|
+
|
|
|
|
|
+ //商品编码
|
|
|
|
|
+ String shangpinbianma = "202300026";
|
|
|
|
|
+ //商品名称
|
|
|
|
|
+ String shangpinmingcheng = "锉刀";
|
|
|
|
|
+ //仓库id
|
|
|
|
|
+ String cangkuid = "1115";
|
|
|
|
|
+
|
|
|
|
|
+ /*先查询当前商品的库存实际数量*/
|
|
|
|
|
+ log.info("开始执行库存查询接口,获取当前实际库存...");
|
|
|
|
|
+ OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
+ .build();
|
|
|
|
|
+ MediaType mediaType = MediaType.parse("text/plain");
|
|
|
|
|
+ RequestBody body = RequestBody.create(mediaType, "");
|
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
|
+ .url(IP + "/PostInventoryInquiry?commodity=" + shangpinbianma + "&commodityname=" + shangpinmingcheng
|
|
|
|
|
+ + "&kuqu_id=" + cangkuid)
|
|
|
|
|
+ .method("POST", body)
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ String s = null;
|
|
|
|
|
+ String s1 = null;
|
|
|
|
|
+ String s2 = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+ String result = response.body().string();
|
|
|
|
|
+ //获取接口返回的原始内容
|
|
|
|
|
+ s = JSON.toJSONString(result);
|
|
|
|
|
+ //去除返回字符串中的\转义字符
|
|
|
|
|
+ s1 = s.trim().replace("\\", "");
|
|
|
|
|
+ //去除返回字符串的首尾""双引号,去除两次
|
|
|
|
|
+ s2 = s1.replaceAll("^\"|\"$", "")
|
|
|
|
|
+ .replaceAll("^\"|\"$", "");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject jsonObjectKUCUN = JSON.parseObject(s2);
|
|
|
|
|
+ JSONObject list = jsonObjectKUCUN.getJSONArray("list").getJSONObject(0);
|
|
|
|
|
+ System.out.println("库存查询接口返回list:" + list);
|
|
|
|
|
+ //商品编码
|
|
|
|
|
+ String commodity = list.getString("commodity");
|
|
|
|
|
+ System.out.println("【库存】商品编码:" + commodity);
|
|
|
|
|
+ //商品名称
|
|
|
|
|
+ String name = list.getString("name");
|
|
|
|
|
+ System.out.println("【库存】商品名称:" + name);
|
|
|
|
|
+ //仓位
|
|
|
|
|
+ String position = list.getString("position");
|
|
|
|
|
+ System.out.println("【库存】仓位:" + position);
|
|
|
|
|
+ //容器(托盘)
|
|
|
|
|
+ String tuopan_code = list.getString("tuopan_code");
|
|
|
|
|
+ System.out.println("【库存】容器(托盘):" + tuopan_code);
|
|
|
|
|
+ //库存数量
|
|
|
|
|
+ int kucun_num = list.getInteger("kucun_num");
|
|
|
|
|
+ System.out.println("【库存】库存数量:" + kucun_num);
|
|
|
|
|
+ /*先查询当前商品的库存实际数量*/
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void getAll(){
|
|
|
|
|
+ String kuquid = "1115";
|
|
|
|
|
+
|
|
|
|
|
+ OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
+ .build();
|
|
|
|
|
+ MediaType mediaType = MediaType.parse("text/plain");
|
|
|
|
|
+ RequestBody body = RequestBody.create(mediaType, "");
|
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
|
+ .url(IP + "/PostInventoryInquiry?commodity=&commodityname=&kuqu_id=" + kuquid)
|
|
|
|
|
+ .method("POST", body)
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ String s = null;
|
|
|
|
|
+ String s1 = null;
|
|
|
|
|
+ String s2 = null;
|
|
|
|
|
+
|
|
|
|
|
+ JSONArray list = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
|
|
+ String result = response.body().string();
|
|
|
|
|
+ //获取接口返回的原始内容
|
|
|
|
|
+ s = JSON.toJSONString(result);
|
|
|
|
|
+ //去除返回字符串中的\转义字符
|
|
|
|
|
+ s1 = s.trim().replace("\\", "");
|
|
|
|
|
+ //去除返回字符串的首尾""双引号,去除两次
|
|
|
|
|
+ s2 = s1.replaceAll("^\"|\"$", "")
|
|
|
|
|
+ .replaceAll("^\"|\"$", "");
|
|
|
|
|
+
|
|
|
|
|
+ //System.out.println("接口返回【库存列表】:" + s2);
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(s2);
|
|
|
|
|
+ //System.out.println("接口返回【库存列表】jsonObject:" + jsonObject);
|
|
|
|
|
+
|
|
|
|
|
+ list = jsonObject.getJSONArray("list");
|
|
|
|
|
+ System.out.println("当前库区的库存信息:" + list);
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|