使用阿里云全球物流快递查询(单号识别)的时候,在本地测试好好的,但是部署到服务器后遇到了中文符号乱码问题,如 】会乱码
官方接口文档地址
给他修改一下
public static JSONObject getExpInfo(String no, String appcode) { if (LInc.isBlank(no)) { throw new RuntimeException("快递单号不能为空"); } if (LInc.isBlank(appcode)) { throw new RuntimeException("参数尚未配置"); } JSONObject result = null; try { HttpClient htClient = HttpClientBuilder.create().build(); HttpGet method = new HttpGet("https://goexpress.market.alicloudapi.com/goexpress?no=" + no + "&type="); method.setHeader("Authorization", "APPCODE " + appcode); HttpResponse response = htClient.execute(method); String resData = EntityUtils.toString(response.getEntity()); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != 200) { Header[] headers = response.getHeaders("X-Ca-Error-Message"); if(headers.length>0){ String error = headers[0].getValue(); if (statusCode == 400 && "Invalid AppCode `not exists`".equals(error)) { throw new RuntimeException("AppCode错误"); } else if (statusCode == 400 && "Invalid Url".equals(error)) { throw new RuntimeException("请求的 Method、Path 或者环境错误"); } else if (statusCode == 400 && "Invalid Param Location".equals(error)) { throw new RuntimeException("参数错误"); } else if (statusCode == 403 && "Unauthorized".equals(error)) { throw new RuntimeException("服务未被授权(或URL和Path不正确)"); } else if (statusCode == 403 && "Quota Exhausted".equals(error)) { throw new RuntimeException("套餐包次数用完"); } else { throw new RuntimeException("参数名错误 或 其他错误" + error); } } throw new RuntimeException("响应参数有误"); } result = JSON.parseObject(resData); } catch (Exception e) { throw new RuntimeException("获取失败:" + e.getMessage()); } return result; }