xin
4 days ago 044a57d2133b2363a6f0d3d167b3eaa587c70b91
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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.RiderSourceInfo;
import com.oying.modules.rider.domain.RiderSourceInfoHttp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
 
/**
 * TODO
 * 骑手信息查询
 *
 * @author pxb
 * @version 1.0
 */
public class RiderSourceHttpUtils {
 
    private static final Logger log = LoggerFactory.getLogger(RiderSourceHttpUtils.class);
    private static final String URL = "https://1.95.3.255:443/lyhd/api/contract/syncRiderContract";
    // 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);
            return JSON.toJSONString(riderSourceInfoHttp);
        } finally {
            IoUtil.close(response);
        }
    }
 
    /**
     * 功能描述: <获取第三方骑手数据信息>
     *
     * @param: [phone, sourcePlatform] 手机号,来源平台
     * @return: riderSourceInfoHttp
     * @author: pxb
     */
    public static RiderSourceInfoHttp getRiderSourceInfoHttp(List<String> phones, String sourcePlatform) {
        HashMap<String, Object> param = new HashMap<>(2);
        param.put("phones", phones);
        param.put("sourcePlatform", sourcePlatform);
        String url = URL;
        // 转化成对象
        RiderSourceInfoHttp riderSourceInfoHttp = new RiderSourceInfoHttp();
        try {
            String result = httpPostRequest(param, url);
            log.info("第三方骑手数据信息:{}", result);
            // 转换数据
            riderSourceInfoHttp = riderConvertUtils(result);
        } catch (Exception e) {
            riderSourceInfoHttp.setCode("500");
            riderSourceInfoHttp.setMessage("获取数据失败");
            riderSourceInfoHttp.setData(null);
            return riderSourceInfoHttp;
        }
        // riderSourceInfoHttp.setCode(Constants.HTTP_CODE_SUCCESS);
        // riderSourceInfoHttp.setMessage("请求成功");
        // RiderSourceInfo riderSourceInfo = new RiderSourceInfo();
        // riderSourceInfo.setSourcePlatform("LY");
        // riderSourceInfo.setCardNum("123456789012345678");
        // riderSourceInfo.setPhone("18706999997");
        // riderSourceInfo.setCardName("张三");
        // riderSourceInfo.setEnabled(Constants.SOURCE_ENABLED_ON);
        // riderSourceInfoHttp.getData().add(riderSourceInfo);
        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("转化数据失败");
            return riderSourceInfoHttp;
        }
    }
 
    public static void main(String[] args) {
        List<String> phones = new ArrayList<>();
        phones.add("13954532585");
        RiderSourceHttpUtils.getRiderSourceInfoHttp(phones, "LY");
    }
}