package com.fdkankan.ucenter.httpClient;

import com.alibaba.fastjson.JSONObject;
import com.dtflys.forest.http.ForestRequest;
import com.dtflys.forest.http.ForestResponse;
import com.dtflys.forest.interceptor.Interceptor;
import com.dtflys.forest.reflection.ForestMethod;
import com.fdkankan.sign.RsaUtils;
import com.fdkankan.ucenter.entity.AppSecret;
import com.fdkankan.ucenter.service.IAppSecretService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.util.Date;

/**
 * @author Xiewj
 * @date 2025/7/8
 */
@Component
@Slf4j
public class SignInterceptor implements Interceptor<JSONObject> {

    @Value("${ucenter.sign.appid}")
    public String appId;
    @Value("${ucenter.sign.publickey}")
    public String publicKey;
    @Override
    public void onInvokeMethod(ForestRequest request, ForestMethod method, Object[] args) {
        JSONObject playload = new JSONObject();
        playload.put("appId", appId);
        playload.put("timestamp", new Date().getTime());
        request.addHeader("appId",appId);
        request.addHeader("sign", RsaUtils.encipher(playload.toJSONString(), publicKey));

    }
}
