栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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;
    }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/732916.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号