package cn.ey.biz.module.external.api.smarthub.feign.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.ey.biz.module.external.utils.DateUtils;
import cn.ey.biz.module.external.utils.MD5Utils;
import cn.ey.biz.module.external.utils.SpringUtils;
import feign.RequestInterceptor;
import feign.RequestTemplate;
/**
 * feign请求拦截器
 * @author 86182
 *
 */
public class SmartHubFeignClientInterceptor implements RequestInterceptor {
	
	private final Logger log = LoggerFactory.getLogger(getClass());
	
    @Override
    public void apply(RequestTemplate requestTemplate) {
    	SmartHubConfig shConfig = SpringUtils.getObject(SmartHubConfig.class);
    	String timestamp = DateUtils.getTimestamp();
    	String signature = MD5Utils.encrypt(timestamp+Constant.AND_SYMBOL+shConfig.getSecret());
    	log.info("timestamp:"+timestamp);
    	log.info("X_SIGNATURE_PRE:"+timestamp+Constant.AND_SYMBOL+shConfig.getSecret());
    	requestTemplate.header(Constant.X_TIMESTAMP, timestamp);
    	requestTemplate.header(Constant.X_SIGNATURE, signature);
    

    }
    
//    public static void main(String[] args) {
//		String s = "20230412183646"+"&&"+"gX&7oZn@3Y!&";
//		String encrypt = MD5Utils.encrypt(s);
//		System.out.println(encrypt);
//	}
}
