xin
2025-07-02 2116b5b5802c0de0f126f85cf2ac56a732639e82
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.oying.modules.rider.utils;
 
import cn.hutool.core.io.IoUtil;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.oying.modules.rider.domain.RiderSourceInfoHttp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.util.HashMap;
 
 
/**
 * TODO
 * 骑手信息查询
 *
 * @author pxb
 * @version 1.0
 */
public class RiderSourceHttpUtils {
 
    private static final Logger log = LoggerFactory.getLogger(RiderSourceHttpUtils.class);
    // private static final String URL = "http://1.14.71.182:5000/";
    // private static final String URL = "http://192.168.18.111:5000/";
 
 
    /**
     * 功能描述: <HTTp请求>
     *
     * @param: paramMap 请求参数
     * @return: java.lang.Object
     * @author: pxb
     */
    public static String httpPostRequest(HashMap<String, Object> paramMap, String url) {
        String jsonParam = JSON.toJSONString(paramMap);
        HttpResponse response = null;
        try {
            response = HttpRequest.post(url)
                    // 头信息,多个头信息多次调用此方法即可
                    .header(Header.USER_AGENT, "*")
                    .header(Header.CONTENT_TYPE, "application/json;charset=utf-8")
                    // .form(paramMap)//表单内容
                    // 超时,毫秒
                    .timeout(30000)
                    .body(jsonParam)
                    .execute();
            return response.body();
        } catch (Exception e) {
            RiderSourceInfoHttp riderSourceInfoHttp = new RiderSourceInfoHttp();
            riderSourceInfoHttp.setCode("500");
            riderSourceInfoHttp.setMessage(paramMap.get("phone") + "手机号请求异常:" + url);
            riderSourceInfoHttp.setSuccess("false");
            return JSON.toJSONString(riderSourceInfoHttp);
        } finally {
            IoUtil.close(response);
        }
    }
 
    /**
     * 功能描述: <获取第三方骑手数据信息>
     *
     * @param: [phone, sourcePlatform] 手机号,来源平台
     * @return: riderSourceInfoHttp
     * @author: pxb
     */
    public static RiderSourceInfoHttp getRiderSourceInfoHttp(String phone, String sourcePlatform) {
        HashMap<String, Object> paramMap = new HashMap<>(2);
        paramMap.put("phone", phone);
        paramMap.put("produceType", sourcePlatform);
        String url = "";
        // 转化成对象
        RiderSourceInfoHttp riderSourceInfoHttp = new RiderSourceInfoHttp();
        try {
            String result = httpPostRequest(paramMap, url);
            // 转换数据
            riderSourceInfoHttp = riderConvertUtils(result);
        } catch (Exception e) {
            riderSourceInfoHttp.setCode("500");
            riderSourceInfoHttp.setMessage("获取数据失败");
            riderSourceInfoHttp.setSuccess("false");
            return riderSourceInfoHttp;
        }
        return riderSourceInfoHttp;
    }
 
    /**
     * 功能描述: <转换第三方骑手数据信息>
     *
     * @param: []
     * @return: java.lang.Object
     * @author: pxb
     */
    public static RiderSourceInfoHttp riderConvertUtils(String result) {
        RiderSourceInfoHttp riderSourceInfoHttp = new RiderSourceInfoHttp();
        try {
            riderSourceInfoHttp = JSONObject.parseObject(result, RiderSourceInfoHttp.class);
            return riderSourceInfoHttp;
        } catch (Exception e) {
            riderSourceInfoHttp.setCode("500");
            riderSourceInfoHttp.setMessage("转化数据失败");
            riderSourceInfoHttp.setSuccess("false");
            return riderSourceInfoHttp;
        }
    }
}