package com.huimv.video.dhicc.test.request;

import com.alibaba.fastjson.JSON;
import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo02;
import com.huimv.video.dhicc.test.constant.Constant;
import com.huimv.video.dhicc.test.response.GetPublicKeyResponse;
import com.huimv.video.dhicc.test.utils.HttpURLConnectionUtil;
import com.huimv.video.dhicc.test.utils.HttpsURLConnectionUtil;
import com.huimv.video.dhicc.test.utils.UrlUtil;


/**
 * 获取公钥
 */
public class GetPublicKeyRequest02 extends BaseRequest02<GetPublicKeyResponse> {

    public GetPublicKeyRequest02(OauthConfigBaseInfo02 oauthConfigBaseInfo){
        super(oauthConfigBaseInfo, Constant.HTTP_GET, oauthConfigBaseInfo.getHttpConfigInfo().getPrefixUrl() + Constant.GET_PUBLIC_KEY, false);
    }

    @Override
    public GetPublicKeyResponse doAction(){
        //重置url信息，替换版本号
        this.setUrl(UrlUtil.dealVersion(this.getUrl()));
        //发送请求
        String res = isEnableHttpTest() ? HttpURLConnectionUtil.doGet02(this) : HttpsURLConnectionUtil.doGet02(this);
        //获取响应
        GetPublicKeyResponse getPublicKeyResponse = JSON.parseObject(res, GetPublicKeyResponse.class);

        return getPublicKeyResponse;
    }

    public boolean isEnableHttpTest(){
        return super.getOauthConfigBaseInfo().getHttpConfigInfo().isEnableHttpTest();
    }
}
