package com.om.utils;


import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.om.entity.dto.AppInfo;
import com.om.entity.dto.PushInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class PushUtil {
    @Value("${umeng.appkey}")
	private String appkey;

    @Value("${umeng.appMasterSecret}")
	private String appMasterSecret;
	private String timestamp = Long.toString(System.currentTimeMillis());
	private PushClient client = new PushClient();



    public void sendAndroidListcastJSON(String[] tokens, PushInfo pushInfo) throws Exception {
        AndroidListcast listcast = new AndroidListcast(appkey,appMasterSecret);

        listcast.setDeviceToken(tokens);

        listcast.setCustomField(JSON.toJSONString(pushInfo));
        System.out.println("pushinfo:"+JSON.toJSONString(pushInfo));

        listcast.goAppAfterOpen();
        listcast.setDisplayType(AndroidNotification.DisplayType.MESSAGE);
        // For how to register a test device, please see the developer doc.
        listcast.setProductionMode();

        listcast.setExtraField("test", "helloworld");
        listcast.setChannelActivity("your channel activity");
        listcast.setChannelProperties("abc");
        client.send(listcast);
    }

    public static void main(String[] args) {
        String[] tokens = {"Al2VBWU3U80w842QkW4Y-SUW7pIFNRDq0MqWUi4taYV9"};
       // AppInfo appInfo = new AppInfo("app.apk",15741,"www.baidu.com","V1.0");
        PushInfo pushInfo = new PushInfo();
        pushInfo.setPushInfoType(1);
        //pushInfo.setJson(JSONUtil.parseObj(appInfo));
        PushUtil demo = new PushUtil();
        try {
            demo.sendAndroidListcastJSON(tokens,pushInfo);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
