Exemple #1
0
        private void pushMessageToAppIOS(string title)
        {
            IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);

            AppMessage message = new AppMessage();

            //通知模版:支持TransmissionTemplate、LinkTemplate、NotificationTemplate,此处以LinkTemplate为例
            TransmissionTemplate template = TransmissionTemplateIOS(title);

            message.IsOffline = true;                         // 用户当前不在线时,是否离线存储,可选
            message.OfflineExpireTime = 1000 * 3600 * 12;            // 离线有效时间,单位为毫秒,可选
            message.Data = template;

            List<String> appIdList = new List<string>();
            appIdList.Add(APPID);

            List<String> phoneTypeList = new List<string>();    //通知接收者的手机操作系统类型
            phoneTypeList.Add("ANDROID");
            phoneTypeList.Add("IOS");

            List<String> provinceList = new List<string>();     //通知接收者所在省份
            //provinceList.Add("浙江");
            //provinceList.Add("上海");
            //provinceList.Add("北京");

            message.AppIdList = appIdList;
            message.PhoneTypeList = phoneTypeList;
            message.ProvinceList = provinceList;

            String pushResult = push.pushMessageToApp(message);
        }
        private string PushMessageToAppAndroid(RequestPushMessageToApp req)
        {
            IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);

            AppMessage message = new AppMessage();

            NotificationTemplate template = NotificationTemplateAndroid(req.Title);

            message.IsOffline = true;                         // 用户当前不在线时,是否离线存储,可选
            message.OfflineExpireTime = 1000 * 3600 * 12;            // 离线有效时间,单位为毫秒,可选
            message.Data = template;

            List<String> appIdList = new List<string>();
            appIdList.Add(APPID);

            List<String> phoneTypeList = new List<string>();    //通知接收者的手机操作系统类型
            phoneTypeList.Add("ANDROID");
            //phoneTypeList.Add("IOS");

            List<String> provinceList = new List<string>();     //通知接收者所在省份

            message.AppIdList = appIdList;
            message.PhoneTypeList = phoneTypeList;
            message.ProvinceList = provinceList;

            String pushResult = push.pushMessageToApp(message);
            return pushResult;
        }
        //pushMessageToApp接口测试代码
        private static void pushMessageToApp()
        {
            IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);

            AppMessage message = new AppMessage();

            //通知模版:支持TransmissionTemplate、LinkTemplate、NotificationTemplate,此处以LinkTemplate为例
            LinkTemplate template = new LinkTemplate();
            template.AppId = APPID;                     //应用APPID
            template.AppKey = APPKEY;                   // 应用APPKEY
            template.Title = "toAPP消息";        // 通知标题
            template.Text = "toAPP消息";         // 通知内容
            template.Logo = "icon.png";                 // 通知Logo
            template.LogoURL = "http://www.photophoto.cn/m23/086/010/0860100017.jpg"; //通知栏网络图片展示
            template.Url = "http://www.baidu.com";            // 跳转地址
            //template.IsRing = true;					// 收到通知是否响铃,可选,默认响铃
            //template.IsVibrate = true;					// 收到通知是否震动,可选,默认振动
            //template.IsClearable = true;				// 通知是否可清除,可选,默认可清除

            message.IsOffline = true;                         // 用户当前不在线时,是否离线存储,可选
            message.OfflineExpireTime = 1000 * 3600 * 12;            // 离线有效时间,单位为毫秒,可选
            message.Data = template;

            List<String> appIdList = new List<string>();
            appIdList.Add(APPID);

            List<String> phoneTypeList = new List<string>();    //通知接收者的手机操作系统类型
            phoneTypeList.Add("ANDROID");
            //phoneTypeList.Add("IOS");

            List<String> provinceList = new List<string>();     //通知接收者所在省份
            //provinceList.Add("浙江");
            //provinceList.Add("上海");
            //provinceList.Add("北京");

            message.AppIdList = appIdList;
            message.PhoneTypeList = phoneTypeList;
            message.ProvinceList = provinceList;

            String pushResult = push.pushMessageToApp(message);
            System.Console.WriteLine("-----------pushMessageToApp--------------" + pushResult);
        }
        private string PushMessageToListIOS(RequestPushMessageToList req)
        {
            try
            {
                IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);

                ListMessage message = new ListMessage();

                TransmissionTemplate template = TransmissionTemplateIOS(req.Title);

                message.IsOffline = true;                         // 用户当前不在线时,是否离线存储,可选
                message.OfflineExpireTime = 1000 * 3600 * 12;            // 离线有效时间,单位为毫秒,可选
                message.Data = template;

                //设置接收者
                var targetList = new List<com.igetui.api.openservice.igetui.Target>();
                string[] cds = req.Clientids.Split(",".ToCharArray());

                foreach (string s in cds)
                {
                    var target1 = new com.igetui.api.openservice.igetui.Target();
                    target1.appId = APPID;
                    target1.clientId = s;
                    targetList.Add(target1);
                }

                String contentId = push.getContentId(message);
                String pushResult = push.pushMessageToList(contentId, targetList);

                return pushResult;
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
Exemple #5
0
 public BatchImpl(string appKey, IGtPush push)
 {
     batchId   = Guid.NewGuid().ToString();
     APPKEY    = appKey;
     this.push = push;
 }
        //PushMessageToSingle接口测试代码
        private static void PushMessageToSingle()
        {
            // 推送主类
            IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);

            //通知模版:支持TransmissionTemplate、LinkTemplate、NotificationTemplate,此处以TransmissionTemplate为例
            TransmissionTemplate template = new TransmissionTemplate();
            template.AppId = APPID;                             // 应用APPID
            template.AppKey = APPKEY;                           // 应用APPKEY
            template.TransmissionType = "1";                    // 收到消息是否立即启动应用,1为立即启动,2则广播等待客户端自启动
            template.TransmissionContent = "您需要透传的内容";  // 需要透传的内容

            //iOS推送需要的pushInfo字段
            //template.setPushInfo(actionLocKey, badge, message, sound, payload, locKey, locArgs, launchImage);

            // 单推消息模型
            SingleMessage message = new SingleMessage();
            message.IsOffline = true;                         // 用户当前不在线时,是否离线存储,可选
            message.OfflineExpireTime = 1000 * 3600 * 12;            // 离线有效时间,单位为毫秒,可选
            message.Data = template;

            com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target();
            target.appId = APPID;
            target.clientId = CLIENTID;

            String pushResult = push.pushMessageToSingle(message, target);
            System.Console.WriteLine("-----------PushMessageToSingle--------------" + pushResult);
        }
        //PushMessageToList接口测试代码
        private static void PushMessageToList()
        {
            IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);

            ListMessage message = new ListMessage();

            NotificationTemplate template = new NotificationTemplate();
            template.AppId = APPID;                             // 应用APPID
            template.AppKey = APPKEY;                           // 应用APPKEY
            template.Title = "此处填写通知标题";                // 通知标题
            template.Text = "此处填写通知内容";                 // 通知内容
            template.Logo = "icon.png";                         // 应用Logo
            template.LogoURL = "http://www.photophoto.cn/m23/086/010/0860100017.jpg"; //通知栏网络图片展示
            template.TransmissionType = "2";                    // 收到消息是否立即启动应用,1为立即启动,2则广播等待客户端自启动
            template.TransmissionContent = "你需要透传的内容";  // 需要透传的内容
            //template.IsRing = true;					// 收到通知是否响铃,可选,默认响铃
            //template.IsVibrate = true;					// 收到通知是否震动,可选,默认振动
            //template.IsClearable = true;				// 通知是否可清除,可选,默认可清除

            message.IsOffline = true;                         // 用户当前不在线时,是否离线存储,可选
            message.OfflineExpireTime = 1000 * 3600 * 12;            // 离线有效时间,单位为毫秒,可选
            message.Data = template;

            //设置接收者
            List<com.igetui.api.openservice.igetui.Target> targetList = new List<com.igetui.api.openservice.igetui.Target>();
            com.igetui.api.openservice.igetui.Target target1 = new com.igetui.api.openservice.igetui.Target();
            target1.appId = APPID;
            target1.clientId = CLIENTID;

            // 如需要,可以设置多个接收者
            //com.igetui.api.openservice.igetui.Target target2 = new com.igetui.api.openservice.igetui.Target();
            //target2.AppId = APPID;
            //target2.ClientId = "ddf730f6cabfa02ebabf06e0c7fc8da0";

            targetList.Add(target1);
            //targetList.Add(target2);

            String contentId = push.getContentId(message);
            String pushResult = push.pushMessageToList(contentId, targetList);
            System.Console.WriteLine("-----------PushMessageToList--------------" + pushResult);
        }