码迷,mamicode.com
首页 > 其他好文 > 详细

消息推送

时间:2017-06-05 17:58:30      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:ons   key   res   amp   内容   name   androi   ati   form   

// 推送到IOS平台
        /// <param name="registeration_id">注册的设备ID</param>
        /// <param name="content">推送的内容</param>
        private bool SendPushToIos(string registeration_id, string content)
        {
            if (string.IsNullOrEmpty(registeration_id))
                return false;

            if (string.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(masterSecret))
                return false;

            JPushClient client = new JPushClient(appKey, masterSecret);
            PushPayload pushPayload = new PushPayload();
            pushPayload.options.apns_production = apns_production;
            pushPayload.platform = Platform.ios();
            pushPayload.audience = Audience.s_registrationId(registeration_id);
            pushPayload.notification = Notification.ios(content);
            //发送请求
            var result = client.SendPush(pushPayload);
            if (result != null && result.msg_id > 0)
                return true;
            else
                return false;
        }

// 推送到Android平台
        /// <param name="registeration_id">注册的设备ID</param>
        /// <param name="content">推送的内容</param>
        private bool SendPushToAndroid(string registeration_id, string content)
        {
            if (string.IsNullOrEmpty(registeration_id))
                return false;

            if (string.IsNullOrEmpty(appKey) || string.IsNullOrEmpty(masterSecret))
                return false;

            JPushClient client = new JPushClient(appKey, masterSecret);
            PushPayload pushPayload = new PushPayload();
            pushPayload.options.apns_production = apns_production;
            pushPayload.platform = Platform.android();
            pushPayload.audience = Audience.s_registrationId(registeration_id);
            pushPayload.notification = Notification.android(content,"易钱宝");
            //发送请求
            var result = client.SendPush(pushPayload);
            if (result != null && result.msg_id > 0)
                return true;
            else
                return false;
        }

//推送消息

public bool SendPush(PlatformEnum platform, string registeration_id, string content)
        {
            int platform_val = (int)platform;

            if (platform_val == 10)
                return SendPushToIos(registeration_id, content);
            else if (platform_val == 20)
                return SendPushToAndroid(registeration_id, content);
            else
                return false;
        }

// 推送平台枚举
    public enum PlatformEnum
    {
        /// <summary>
        /// IOS
        /// </summary>
        ios = 10,
        /// <summary>
        /// Android
        /// </summary>
        android = 20
    }

消息推送

标签:ons   key   res   amp   内容   name   androi   ati   form   

原文地址:http://www.cnblogs.com/Alwayswantmore/p/Push_1.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!