請求參數
| 名稱 | 類型 | 是否必選 | 示例值 | 描述 |
|---|---|---|---|---|
| Action | String | 是 | SendMessage | 系統規定參數。取值:SendMessage。 |
| InstanceId | String | 是 | post-cn-0pp12gl**** | 微消息隊列 MQTT 版實例的 ID,一定要和客戶端實際使用的實例 ID 匹配。您可以在控制台實例詳情頁面獲取該 ID。 |
| MqttTopic | String | 是 | TopicA | 將消息發往的微消息隊列 MQTT 版的 Topic。Topic 的詳細說明請參見名詞解釋。 |
| Payload | String | 是 | test | 消息內容,即消息負載。建議自行做 Base64 編碼,避免傳輸不可見字符。 |
| RegionId | String | 是 | cn-hangzhou | 微消息隊列 MQTT 版實例所在地域(Region)。 |
返回數據
| 名稱 | 類型 | 示例值 | 描述 |
|---|---|---|---|
| MsgId | String | 0B736D997B7F45FF54E61C1C1B58**** | 消息的唯一標識,消息發送成功后服務端會返回消息 ID。 |
| RequestId | String | 020F6A43-19E6-4B6E-B846-44EB31DF44D3 | 公共參數,每個請求的 ID 都是唯一的。 |
IClientProfile profile = DefaultProfile.GetProfile(“RegionId", "此處填寫阿里雲帳號 AccessKey", "此處填寫阿里雲帳號 SecretKey"); DefaultAcsClient client = new DefaultAcsClient(profile); var request = new SendMessageRequest(); request.InstanceId = "InstanceId"; request.Payload = "Payload"; request.MqttTopic = "MqttTopic"; resop resop = new resop(); try { var response = client.GetAcsResponse(request); var s = System.Text.Encoding.Default.GetString(response.HttpResponse.Content); cunt cunt = JsonConvert.DeserializeObject<cunt>(s); if (cunt.MsgId!=null&&cunt.MsgId!="") { resop.code = 200; resop.msg = "發送成功"; } return resop; } catch (ServerException e) { resop.code = 202; resop.msg = "服務端異常"; return resop; } catch (ClientException e) { resop.code = 202; resop.msg = "客戶端異常"; return resop; }
