package cn.com.ctop.track.utils;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.request.AlipayUserInviteRtaConsultRequest;
import com.alipay.api.response.AlipayUserInviteRtaConsultResponse;
import com.alipay.api.domain.AlipayUserInviteRtaConsultModel;
import com.alipay.api.FileItem;
import java.util.Base64;

public class AlipayUserInviteRtaConsult {


    public static void main(String[] args) throws AlipayApiException {
        // 初始化SDK
        AlipayClient alipayClient = new DefaultAlipayClient(getAlipayConfig());
        // 构造请求参数以调用接口
        AlipayUserInviteRtaConsultRequest request = new AlipayUserInviteRtaConsultRequest();
        AlipayUserInviteRtaConsultModel model = new AlipayUserInviteRtaConsultModel();
        // 设置设备标识信息
        model.setPrincipal("d5c631598a54d8bbfd1ac03e4b6b7806");
        // 设置OpenId映射
        model.setOpenId("暂无");
        // 设置查询的设备类型（IMEI、IDFA、OAID、USERID、OPENID）
        model.setPrincipalType("OAID");
        // 设置加密类型
        model.setEncryptType("MD5或者不填");
        // 设置咨询策略组
        model.setTargetCrowdPackageKey("M0004");
        request.setBizModel(model);
        // 第三方代调用模式下请设置app_auth_token
        // request.putOtherTextParam("app_auth_token", "<-- 请填写应用授权令牌 -->");
        AlipayUserInviteRtaConsultResponse response = alipayClient.execute(request);
        System.out.println(response.getBody());
        if (response.isSuccess()) {
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
            // sdk版本是"4.38.0.ALL"及以上,可以参考下面的示例获取诊断链接
            // String diagnosisUrl = DiagnosisUtils.getDiagnosisUrl(response);
            // System.out.println(diagnosisUrl);
        }
    }
    private static AlipayConfig getAlipayConfig() {
        String privateKey = "<-- 请填写您的应用私钥，例如：MIIEvQIBADANB ... ... -->";
        String alipayPublicKey = "<-- 请填写您的支付宝公钥，例如：MIIBIjANBg... -->";
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
        alipayConfig.setAppId("<-- 请填写您的AppId，例如：2019091767145019 -->");
        alipayConfig.setPrivateKey(privateKey);
        alipayConfig.setFormat("json");
        alipayConfig.setAlipayPublicKey(alipayPublicKey);
        alipayConfig.setCharset("UTF-8");
        alipayConfig.setSignType("RSA2");
        return alipayConfig;
    }

}
