Example #1
0
        static void Main()
        {
            IClientProfile              clientProfile = DefaultProfile.GetProfile("cn-hangzhou", "<your access key id>", "<your access key secret>");
            DefaultAcsClient            client        = new DefaultAcsClient(clientProfile);
            PushMessageToAndroidRequest request       = new PushMessageToAndroidRequest();

            request.AppKey      = < your Appkey >;
            request.Target      = "all";
            request.TargetValue = "all";
            request.Message     = ".net Mesage";
            try
            {
                PushMessageToAndroidResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId:" + response.RequestId);
                Console.WriteLine("ResponseId:" + response.ResponseId);
                Console.WriteLine("message:" + response.Message);
                Console.ReadLine();
            }
            catch (ServerException e)
            {
                Console.WriteLine(e.ErrorCode);
                Console.WriteLine(e.ErrorMessage);
            }
            catch (ClientException e)
            {
                Console.WriteLine(e.ErrorCode);
                Console.WriteLine(e.ErrorMessage);
            }
        }
Example #2
0
        public void PushMessageToAndroid(string deviceId, string title, string body)
        {
            var clientProfile =
                DefaultProfile.GetProfile("cn-hangzhou", _pushSetting.AccessKey,
                                          _pushSetting.AccessSecret);
            var client = new DefaultAcsClient(clientProfile);

            var request = new PushMessageToAndroidRequest
            {
                AppKey      = _pushSetting.AppKey,
                Target      = "DEVICE",
                TargetValue = deviceId,
                Title       = title,
                Body        = body
            };

            //推送目标: DEVICE:按设备推送 ALIAS : 按别名推送 ACCOUNT:按帐号推送  TAG:按标签推送; ALL: 广播推送
            ////根据Target来设定,如Target=DEVICE, 则对应的值为 设备id1,设备id2. 多个值使用逗号分隔.(帐号与设备一次最多100)
            try
            {
                var respone = client.GetAcsResponse(request);
            }
            catch (ServerException e)
            {
                throw e;
            }
            catch (ClientException e)
            {
                throw e;
            }
        }
        static void Main()
        {
            IClientProfile              clientProfile = DefaultProfile.GetProfile("cn-hangzhou", "<your access key id>", "<your access key secret>");
            DefaultAcsClient            client        = new DefaultAcsClient(clientProfile);
            PushMessageToAndroidRequest request       = new PushMessageToAndroidRequest();

            request.AppKey      = < your Appkey >;
            request.Target      = "ALL"; //推送目标: DEVICE:按设备推送 ALIAS : 按别名推送 ACCOUNT:按帐号推送  TAG:按标签推送; ALL: 广播推送
            request.TargetValue = "all"; ////根据Target来设定,如Target=DEVICE, 则对应的值为 设备id1,设备id2. 多个值使用逗号分隔.(帐号与设备一次最多100)
            request.Title       = "android title";
            request.Body        = "android body";
            try
            {
                PushMessageToAndroidResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId:" + response.RequestId);
                Console.WriteLine("ResponseId:" + response.MessageId);
                Console.ReadLine();
            }
            catch (ServerException e)
            {
                Console.WriteLine(e.ErrorCode);
                Console.WriteLine(e.ErrorMessage);
                Console.ReadLine();
            }
            catch (ClientException e)
            {
                Console.WriteLine(e.ErrorCode);
                Console.WriteLine(e.ErrorMessage);
                Console.ReadLine();
            }
        }