puzhibing
2023-05-22 8d5196a9663570735148c023367672cc1d86615c
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
package com.agentdriving.driver.modular.system.util.MallBook.util;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.exceptions.ValidateException;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.agentdriving.driver.modular.system.util.MallBook.config.ChannelConfig;
import com.agentdriving.driver.modular.system.util.MallBook.model.InterfaceRequest;
import com.agentdriving.driver.modular.system.util.MallBook.model.InterfaceResponse;
 
/**
 * @Author xiaogc
 * @Date 2022/1/24 13:45
 */
public class TrhRequest<T> {
 
    public InterfaceResponse execute(T t, String serverCode) {
        InterfaceRequest<T> request = new InterfaceRequest(t, serverCode);
        System.out.println("mallbook请求参数:" + JSONUtil.toJsonStr(request));
        String result = HttpUtil.post(ChannelConfig.payUrl, BeanUtil.beanToMap(request));
        System.out.println("mallbook响应参数:" + result);
        InterfaceResponse response = JSONUtil.toBean(result, InterfaceResponse.class);
        boolean verify = RSASignature.validate(response.content(), response.getSign());
        if (!verify) {
            throw new ValidateException("签名验证失败");
        } else {
            System.out.printf("签名验证通过");
        }
        return response;
    }
}