package com.jeequan.jeepay.thirdparty.channel.ybpay;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.model.params.ybpay.YbpayIsvParams;
import com.jeequan.jeepay.thirdparty.channel.ybpay.model.ReqHeader;
import com.jeequan.jeepay.thirdparty.channel.ybpay.model.ReqMethod;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;

import java.util.Map;

/**
 * TODO
 * 易宝kit
 * @author crystal
 * @date 2024/2/27 11:01
 */
@Slf4j
public class YbpayKit {

    /**
     * 发起请求 返回业务参数
     *
     * @param method
     * @param reqData
     * @return
     */
    public static JSONObject reqApi(ReqMethod.Method method, YbpayIsvParams isvParams, JSONObject reqData) {
        ReqHeader header = new ReqHeader(isvParams);
        Map<String, String> headers = header.toHeader(isvParams,method);
        HttpResponse response = HttpRequest.post(ReqMethod.getUrl(method)).headerMap(headers, false).body(reqData.toString()).execute();
        if(HttpStatus.OK.value() != response.getStatus()){
            throw new BizException("接口请求异常");
        }
        return null;
    }

}
