package com.gxwebsoft.shop.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.google.gson.Gson;
import com.gxwebsoft.shop.service.KuaiDi100;
import com.kuaidi100.sdk.api.BOrderOfficial;
import com.kuaidi100.sdk.contant.ApiInfoConstant;
import com.kuaidi100.sdk.core.BaseClient;
import com.kuaidi100.sdk.core.IBaseClient;
import com.kuaidi100.sdk.pojo.HttpResult;
import com.kuaidi100.sdk.request.BOrderReq;
import com.kuaidi100.sdk.request.BaseRequest;
import com.kuaidi100.sdk.request.PrintReq;
import com.kuaidi100.sdk.utils.SignUtils;
import org.springframework.stereotype.Service;

@Service
public class KuaiDi100Impl implements KuaiDi100 {
    private String key = "QIfOPROg5054";
    private String secret = "09401b3c56f54175bcacc74d0519e4ef";
    @Override
    public HttpResult border(BOrderReq bOrderReq) throws Exception {
        PrintReq printReq = new PrintReq();

        String t = String.valueOf(System.currentTimeMillis());
        String param = new Gson().toJson(bOrderReq);

        printReq.setKey(key);
        printReq.setSign(SignUtils.printSign(param,t,key,secret));
        printReq.setT(t);
        printReq.setParam(param);
        printReq.setMethod(ApiInfoConstant.B_ORDER_OFFICIAL_ORDER_METHOD);
        System.out.println(printReq);
//        IBaseClient bOrder = new BOrderOfficial();
        IBaseClient bOrder = new BaseClient() {
            @Override
            public String getApiUrl(BaseRequest baseRequest) {
                return "https://api.kuaidi100.com/apiMock/border";
            }
        };
        return bOrder.execute(printReq);
    }
}
