package com.zhgd.xmgl.push.config;

import com.getui.push.v2.sdk.ApiHelper;
import com.getui.push.v2.sdk.GtApiConfiguration;
import com.getui.push.v2.sdk.api.PushApi;
import com.getui.push.v2.sdk.api.UserApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: wisdomSite
 * @description: 个推配置
 * @author: Mr.Peng
 * @create: 2022-04-20 09:40
 **/
@Slf4j
@Configuration
public class GeTuiConfig {

    @Value("${getui.baseUrl}")
    private String baseUrl;

    @Value("${getui.appId}")
    private String appId;

    @Value("${getui.appKey}")
    private String appKey;

    @Value("${getui.appSecret}")
    private String appSecret;

    @Value("${getui.masterSecret}")
    private String masterSecret;

    @Bean
    public PushApiHelper pushApiHelper() {
        GtApiConfiguration apiConfiguration = new GtApiConfiguration();
        //填写应用配置
        apiConfiguration.setAppId(appId);
        apiConfiguration.setAppKey(appKey);
        apiConfiguration.setMasterSecret(masterSecret);
        // 接口调用前缀，请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
        apiConfiguration.setDomain(baseUrl);
        ApiHelper apiHelper=null;
        PushApiHelper pushApiHelper=new PushApiHelper();
        try {
            apiHelper = ApiHelper.build(apiConfiguration);
            // 创建对象，建议复用。目前有PushApi、StatisticApi、UserApi
            PushApi pushApi = apiHelper.creatApi(PushApi.class);
            UserApi userApi = apiHelper.creatApi(UserApi.class);
            // 实例化ApiHelper对象，用于创建接口对象
            pushApiHelper.setPushApi(pushApi);
            pushApiHelper.setUserApi(userApi);
        }catch (Exception e){
            log.error("初始话个推失败"+e.getMessage());
        }
        return pushApiHelper;
    }


}
