package com.ym.im.service.impl;

import com.ym.im.push.umeng.PushClient;
import com.ym.im.push.umeng.ios.IOSNotification;
import com.ym.im.service.PushService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author: JJww
 * @Date:2020/11/5
 */
@Component
public class UmengIosPushServiceImpl extends IOSNotification implements PushService {

    @Autowired
    private PushClient pushClient;

    private static final String APP_KEY = "5f963f3ea1491772a2aef713";

    private static final String APP_MASTER_SECRET = "ti5gomxtvmkgehmwgtbq9rtsfhy0khsi";

    @PostConstruct
    public void init() throws Exception {
        setAppMasterSecret(APP_MASTER_SECRET);
        setPredefinedKeyValue("appkey", APP_KEY);
    }

    @Override
    @SneakyThrows
    public void unicast(String deviceToken) {
        this.setAlert("您有一条新信息");
        this.setBadge(0);
        this.setSound("default");
        this.setProductionMode();
        this.setPredefinedKeyValue("device_tokens", deviceToken);
        this.setCustomizedField("pushType", "1");//自定义字段 推送类型:客服消息
        this.setPredefinedKeyValue("type", "unicast");
        pushClient.send(this);
    }


}
