package com.hfkj.channel.saas.utils;

import com.alibaba.fastjson.JSONObject;
import com.hfkj.channel.lakala.config.RSAUtils;
import com.hfkj.channel.saas.config.SaasConfig;
import com.hfkj.common.Base64Util;
import com.hfkj.common.utils.HttpsUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @className: SaasMerRequest
 * @author: HuRui
 * @date: 2023/4/5
 **/
@Component
public class SaasMerRequest {

    private static final Logger log = LoggerFactory.getLogger(SaasMerRequest.class);

    @Resource
    private SaasCommon saasCommon;

    /**
     * 增加进件
     * @param body 参数
     * @return
     */
    public Object addMerchant(Map<String, Object> body) {
        try {
            Map<String,Object> header = new HashMap<>();
            header.put("Authorization", "bearer " + saasCommon.getToken());

            log.info("==============start 商户进件 start ==============");
            log.info("请求header:" + JSONObject.toJSONString(header));
            log.info("请求参数:" + JSONObject.toJSONString(body));

            JSONObject jsonObject = HttpsUtils.doPost(SaasConfig.requestMerRegistrationUrl, body, header);
            log.info("响应参数:" + jsonObject);
            return jsonObject;
        } catch (Exception e) {
            log.info("出现异常:", e);
            return null;
        } finally {
            log.info("==============end 商户进件 end ==============");
        }
    }

}
