Пример #1
0
        //发布广播消息,注意topic要以/broadcast开头
        private static void TestPubBroadcast()
        {
            IClientProfile clientProfile = DefaultProfile.GetProfile("<your-region-id>", "<your-access-key-id>", "<your-access-key-secret>");

            DefaultAcsClient client = new DefaultAcsClient(clientProfile);

            PubBroadcastRequest request = new PubBroadcastRequest();

            request.ProductKey    = "<productKey>";
            request.TopicFullName = "/broadcast/" + request.ProductKey + "/<XXXXXXX[deviceName]>";

            byte[] payload    = Encoding.Default.GetBytes("Hello World.");
            String payloadStr = Convert.ToBase64String(payload);

            request.MessageContent = payloadStr;


            try
            {
                PubBroadcastResponse response = client.GetAcsResponse(request);
                Console.WriteLine("publish broadcast message result: " + response.Success);
                Console.WriteLine(response.ErrorMessage);
            }
            catch (ServerException e)
            {
                Console.WriteLine(e.ErrorCode);
                Console.WriteLine(e.ErrorMessage);
            }
            catch (ClientException e)
            {
                Console.WriteLine(e.ErrorCode);
                Console.WriteLine(e.ErrorMessage);
            }
            Console.ReadKey();
        }
        public static PubBroadcastResponse Unmarshall(UnmarshallerContext context)
        {
            PubBroadcastResponse pubBroadcastResponse = new PubBroadcastResponse();

            pubBroadcastResponse.HttpResponse = context.HttpResponse;
            pubBroadcastResponse.RequestId    = context.StringValue("PubBroadcast.RequestId");
            pubBroadcastResponse.Success      = context.BooleanValue("PubBroadcast.Success");
            pubBroadcastResponse.ErrorMessage = context.StringValue("PubBroadcast.ErrorMessage");

            return(pubBroadcastResponse);
        }
Пример #3
0
        public static PubBroadcastResponse Unmarshall(UnmarshallerContext _ctx)
        {
            PubBroadcastResponse pubBroadcastResponse = new PubBroadcastResponse();

            pubBroadcastResponse.HttpResponse = _ctx.HttpResponse;
            pubBroadcastResponse.RequestId    = _ctx.StringValue("PubBroadcast.RequestId");
            pubBroadcastResponse.Success      = _ctx.BooleanValue("PubBroadcast.Success");
            pubBroadcastResponse.Code         = _ctx.StringValue("PubBroadcast.Code");
            pubBroadcastResponse.ErrorMessage = _ctx.StringValue("PubBroadcast.ErrorMessage");
            pubBroadcastResponse.MessageId    = _ctx.LongValue("PubBroadcast.MessageId");

            return(pubBroadcastResponse);
        }
Пример #4
0
        //发布广播消息,注意topic要以/broadcast开头
        public void TestPubBroadcast()
        {
            DefaultAcsClient client = Demo.IotClient.GetClient();

            PubBroadcastRequest request = new PubBroadcastRequest();

            request.ProductKey    = "<productKey>";
            request.TopicFullName = "/broadcast/" + request.ProductKey + "/<XXXXXXX[deviceName]>";

            byte[] payload    = Encoding.Default.GetBytes("Hello World.");
            String payloadStr = Convert.ToBase64String(payload);

            request.MessageContent = payloadStr;

            PubBroadcastResponse response = client.GetAcsResponse(request);

            Console.WriteLine("publish broadcast message result: " + response.Success);
            Console.WriteLine(response.ErrorMessage);
        }