wanghc
2023-07-04 a042e0e63f86a0880d20e57c14ec4a60b65801fb
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
package com.jttech.pfcs.services.impl;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
 
import com.jttech.pfcs.services.ITradeService;
import com.jttech.pfcs.util.OkHttpUtil;
 
import okhttp3.*;
 
/**
 * @author wanghc
 * @version 1.0.0
 * @date 2023-03-07
 */
@Service
public class TradeServiceImpl implements ITradeService {
 
    private Logger mLogger = LoggerFactory.getLogger(getClass());
 
    /**
     * excute
     *
     * @param content
     * @return
     */
    @Override
    public String excute(String url, String content) {
        mLogger.info("TradeServiceImpl.excute req={}", content);
        String result = "";
        try {
            OkHttpClient.Builder builder = new OkHttpClient.Builder()
                    .sslSocketFactory(OkHttpUtil.getIgnoreInitedSslContext().getSocketFactory(), OkHttpUtil.IGNORE_SSL_TRUST_MANAGER_X509)
                    .hostnameVerifier(OkHttpUtil.getIgnoreSslHostnameVerifier());
            RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), content);
            Request request = new Request.Builder().url(url).post(requestBody).build();
            Response response = builder.build().newCall(request).execute();
            result = response.body().string();
        } catch (Exception e) {
            mLogger.error("TradeServiceImpl.excute error={}", e);
            throw new RuntimeException(e.getMessage());
        }
        mLogger.info("TradeServiceImpl.excute resp={}", result);
        return result;
    }
}