Java使用阿里云全球物流快递查询(单号识别)乱码问题

Java使用阿里云全球物流快递查询(单号识别)乱码问题

使用阿里云全球物流快递查询(单号识别)的时候,在本地测试好好的,但是部署到服务器后遇到了中文符号乱码问题,如 】会乱码
官方接口文档地址

给他修改一下

    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;
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值