package cn.palmte.work.utils.Umengpush;


import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UmengPushUtils {

    private static final Logger logger = LoggerFactory.getLogger(UmengPushUtils.class);

    //android
    private static final String  ANDROID_APP_KEY="5f335966b4b08b653e93a5ff";
    private static final String ANDROID_APP_SECRET="eh64abp9cwazcqnf2mhndep8srv64xmi";

    //iOS
    private static final String  IOS_APP_KEY="5f338a376de5a925ac88057d";
    private static final String IOS_APP_SECRET="wotwakmh7xmntlvzozq43xihxhowi9sj";

    /**
     *  customizedcast 自定义播：通过alias进行推送
     * @param alias
     * @param title
     * @param text
     * @param fieldObject
     * @return
     */
    public String sendCustomizedCast(String alias, String aliasType, String title, String text, JSONObject fieldObject){
        try {
            AndroidPushUtils androidPushUtils =new AndroidPushUtils(ANDROID_APP_KEY,ANDROID_APP_SECRET);
            String androidPushResult= androidPushUtils.sendAndroidCustomizedcast(alias,aliasType,title,text,fieldObject);
            logger.info("sendCustomizedCast,androidPushResult,{}",androidPushResult);

            IOSPushUtils demo = new IOSPushUtils(IOS_APP_KEY, IOS_APP_SECRET);
            String iosPushResult= demo.sendIOSCustomizedcast(alias,aliasType, title,text,fieldObject);
            logger.info("sendCustomizedCast,iosPushResult,{}",iosPushResult);
        } catch (Exception e) {
             e.printStackTrace();
        }
        return "";
    }

    /**
     * 广播：全用户推送
     * @param title
     * @param text
     * @param fieldObject
     * @return
     */
    public String sendBroadcast(String title, String text, JSONObject fieldObject){
        try {
            AndroidPushUtils androidPushUtils =new AndroidPushUtils(ANDROID_APP_KEY,ANDROID_APP_SECRET);
            String androidPushResult= androidPushUtils.sendAndroidBroadcast(title,text,fieldObject);
            logger.info("sendBroadcast,androidPushResult,{}",androidPushResult);

            IOSPushUtils demo = new IOSPushUtils(IOS_APP_KEY, IOS_APP_SECRET);
            String iosPushResult= demo.sendIOSBroadcast(title,text,fieldObject);
            logger.info("sendBroadcast,iosPushResult,{}",iosPushResult);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }


    public String sendGroupcast(String tag, String title, String text, JSONObject fieldObject){
        try {
            AndroidPushUtils androidPushUtils =new AndroidPushUtils(ANDROID_APP_KEY,ANDROID_APP_SECRET);
            String androidPushResult= androidPushUtils.sendAndroidGroupcast(tag,title,text,fieldObject);
            logger.info("sendGroupcast,androidPushResult,{}",androidPushResult);

            IOSPushUtils demo = new IOSPushUtils(IOS_APP_KEY, IOS_APP_SECRET);
            String iosPushResult= demo.sendIOSGroupcast(tag,title,text,fieldObject);
            logger.info("sendCustomizedCast,iosPushResult,{}",iosPushResult);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    public static void main(String[] args) {
        UmengPushUtils umengPushUtils=new UmengPushUtils();
        JSONObject object = new JSONObject();
        object.put("url", "https://dzg.palmte.cn/upload/file/html5/notice/285.html?appstr=15ae9890dadee17434f4223714cc3528dd467f09d4db6b2fcdff2bbf2f457ce6695cc63d6a6db9653d7b738b505176b958b44fe03f52f44f97f39555fb7570f2d35bcb103c0071567e44cbb6b478fe9c958431c16edb6ba50dc669756c6c593d3ce7283f4f023dbb44053bb993378ff373caee10425e7a92aa76907c867c47191a844591154ed71a491a66c08ac9f03397f2e39eecb376ad3bf3cb7269f81ad6c28874d09940f0e8fdb1842c009d578fa219949acf4ce831c515c716b063aba94b85a092d3b44ab295c3cc5a7ada3954955b403447d73e51aa945ad1e6483c1bf95118a0ca7f8a787ebcf5cd75d2222d70c496dbc152f65c6f081eb5fe82c519c4513633da5f85be64ea915890c1b03706eb556415d251e53c90c99264eb27793120d44df6664bb91899ae27bbfd38876f9a4bed4247c659eaf9d8550e010d95b8b45cd782bcffa8e149b226d45f6f1a&group_id=2");
        object.put("ALERT_TYPE", "5");
        String alias="18280108248";
        String tag="OAO_BROAD1444307";
        String title="这里是标题";
        String text="这里是内容";
//        umengPushUtils.sendCustomizedCast(alias,title,text,object);
        umengPushUtils.sendGroupcast(tag,title,text,object);
//        umengPushUtils.sendBroadcast(title,text,object);
    }


}
