开发者社区> 问答> 正文

流量回执消息如何查看?



简介


当您使用流量的API接口充值完流量后,可以通过使用MNS的Queue模型来接收充值的回执消息,假如服务出现异常情况时(如网络问题),导致消息回执未成功获取,还可以通过充值状态查询API接口进行一定的补偿(目前支持30天内发送记录的查询)。

消息的订阅


云通信的所有业务消息都用过MNS消息服务向外发送。用户每订阅一个类别的消息(比如流量充值回执报告消息FlowReport),系统都会为用户分配一个独立的消息队列。用户可以通过阿里云账号拿到一个临时的token用于获取队列中的消息。用户可以下载demo,编写简单的消息处理类即可完成消息处理的任务。在页面上订阅消息,订阅完消息后,能拿到消息队列名称(queueName)。比如:Alicom-Queue-xxxxxx-FlowReport 。队列名字每个用户都不同。

消息类型


流量提供一种消息类型,流量充值回执消息FlowReport

流量充值回执消息FlowReport消息体格式

名称类型描述示例是否必须
phoneString充值的手机号13000000000必须
out_idString外部扩展ID,在充值接口调用时指定123必须
resultString充值结果3-充值成功,4-充值失败必须
err_codeString错误码UNKNOW可选
err_msgString错误信息描述未知错误可选


技术对接步骤



下载消息SDK


下载对应语音的消息DEMO工程,工程所需要的所有依赖jar包都放在DEMO工程的lib目录下,将对于的jar包引入到您的工程当中既可按照DEMO样例编写接收消息的程序。
SDK&DEMO[ 下载地址]
  1. [backcolor=transparent]/**
  2. [backcolor=transparent] * 只能用于接收云通信的消息,不能用于接收其他业务的消息
  3. [backcolor=transparent] */
  4. [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]class[backcolor=transparent] [backcolor=transparent]ReceiveAlicomMsgDemo[backcolor=transparent] [backcolor=transparent]{
  5. [backcolor=transparent]    [backcolor=transparent]private[backcolor=transparent] [backcolor=transparent]static[backcolor=transparent] [backcolor=transparent]Log[backcolor=transparent] logger[backcolor=transparent]=[backcolor=transparent]LogFactory[backcolor=transparent].[backcolor=transparent]getLog[backcolor=transparent]([backcolor=transparent]ReceiveAlicomMsgDemo[backcolor=transparent].[backcolor=transparent]class[backcolor=transparent]);
  6. [backcolor=transparent]    [backcolor=transparent]static[backcolor=transparent] [backcolor=transparent]class[backcolor=transparent] [backcolor=transparent]MyMessageListener[backcolor=transparent] [backcolor=transparent]implements[backcolor=transparent] [backcolor=transparent]MessageListener[backcolor=transparent]{
  7. [backcolor=transparent]        [backcolor=transparent]private[backcolor=transparent] [backcolor=transparent]Gson[backcolor=transparent] gson[backcolor=transparent]=[backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]Gson[backcolor=transparent]();
  8. [backcolor=transparent]        [backcolor=transparent]@Override
  9. [backcolor=transparent]        [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]boolean[backcolor=transparent] dealMessage[backcolor=transparent]([backcolor=transparent]Message[backcolor=transparent] message[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
  10. [backcolor=transparent]            [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]"message handle: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] message[backcolor=transparent].[backcolor=transparent]getReceiptHandle[backcolor=transparent]());
  11. [backcolor=transparent]            [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]"message body: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] message[backcolor=transparent].[backcolor=transparent]getMessageBodyAsString[backcolor=transparent]());
  12. [backcolor=transparent]            [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]"message id: "[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] message[backcolor=transparent].[backcolor=transparent]getMessageId[backcolor=transparent]());
  13. [backcolor=transparent]            [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]"message dequeue count:"[backcolor=transparent] [backcolor=transparent]+[backcolor=transparent] message[backcolor=transparent].[backcolor=transparent]getDequeueCount[backcolor=transparent]());
  14. [backcolor=transparent]            [backcolor=transparent]try[backcolor=transparent]{
  15. [backcolor=transparent]                [backcolor=transparent]Map[backcolor=transparent]<[backcolor=transparent]String[backcolor=transparent],[backcolor=transparent]Object[backcolor=transparent]>[backcolor=transparent] contentMap[backcolor=transparent]=[backcolor=transparent]gson[backcolor=transparent].[backcolor=transparent]fromJson[backcolor=transparent]([backcolor=transparent]message[backcolor=transparent].[backcolor=transparent]getMessageBodyAsString[backcolor=transparent](),[backcolor=transparent] [backcolor=transparent]HashMap[backcolor=transparent].[backcolor=transparent]class[backcolor=transparent]);
  16. [backcolor=transparent]                [backcolor=transparent]String[backcolor=transparent] phone[backcolor=transparent]=([backcolor=transparent]String[backcolor=transparent])[backcolor=transparent]contentMap[backcolor=transparent].[backcolor=transparent]get[backcolor=transparent]([backcolor=transparent]"phone"[backcolor=transparent]);
  17. [backcolor=transparent]                [backcolor=transparent]Boolean[backcolor=transparent] outId[backcolor=transparent]=([backcolor=transparent]Boolean[backcolor=transparent])[backcolor=transparent]contentMap[backcolor=transparent].[backcolor=transparent]get[backcolor=transparent]([backcolor=transparent]"out_id"[backcolor=transparent]);
  18. [backcolor=transparent]                [backcolor=transparent]String[backcolor=transparent] result[backcolor=transparent]=([backcolor=transparent]String[backcolor=transparent])[backcolor=transparent]contentMap[backcolor=transparent].[backcolor=transparent]get[backcolor=transparent]([backcolor=transparent]"result"[backcolor=transparent]);
  19. [backcolor=transparent]                [backcolor=transparent]String[backcolor=transparent] errCode[backcolor=transparent]=([backcolor=transparent]String[backcolor=transparent])[backcolor=transparent]contentMap[backcolor=transparent].[backcolor=transparent]get[backcolor=transparent]([backcolor=transparent]"err_code"[backcolor=transparent]);
  20. [backcolor=transparent]                [backcolor=transparent]String[backcolor=transparent] errMsg[backcolor=transparent]=([backcolor=transparent]String[backcolor=transparent])[backcolor=transparent]contentMap[backcolor=transparent].[backcolor=transparent]get[backcolor=transparent]([backcolor=transparent]"err_msg"[backcolor=transparent]);
  21. [backcolor=transparent]                [backcolor=transparent]//TODO 这里开始写业务代码
  22. [backcolor=transparent]            [backcolor=transparent]}[backcolor=transparent]catch[backcolor=transparent]([backcolor=transparent]com[backcolor=transparent].[backcolor=transparent]google[backcolor=transparent].[backcolor=transparent]gson[backcolor=transparent].[backcolor=transparent]JsonSyntaxException[backcolor=transparent] e[backcolor=transparent]){
  23. [backcolor=transparent]                logger[backcolor=transparent].[backcolor=transparent]error[backcolor=transparent]([backcolor=transparent]"error_json_format:"[backcolor=transparent]+[backcolor=transparent]message[backcolor=transparent].[backcolor=transparent]getMessageBodyAsString[backcolor=transparent](),[backcolor=transparent]e[backcolor=transparent]);
  24. [backcolor=transparent]            [backcolor=transparent]}
  25. [backcolor=transparent]            [backcolor=transparent]Boolean[backcolor=transparent] dealResult[backcolor=transparent]=[backcolor=transparent]true[backcolor=transparent];
  26. [backcolor=transparent]            [backcolor=transparent]return[backcolor=transparent] dealResult[backcolor=transparent];[backcolor=transparent]//返回true,则工具类自动删除已拉取的消息。
  27. [backcolor=transparent]        [backcolor=transparent]}
  28. [backcolor=transparent]    [backcolor=transparent]}
  29. [backcolor=transparent]    [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]static[backcolor=transparent] [backcolor=transparent]void[backcolor=transparent] main[backcolor=transparent]([backcolor=transparent]String[backcolor=transparent][][backcolor=transparent] args[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]throws[backcolor=transparent] com[backcolor=transparent].[backcolor=transparent]aliyuncs[backcolor=transparent].[backcolor=transparent]exceptions[backcolor=transparent].[backcolor=transparent]ClientException[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]ParseException[backcolor=transparent] [backcolor=transparent]{
  30. [backcolor=transparent]        [backcolor=transparent]DefaultAlicomMessagePuller[backcolor=transparent] puller[backcolor=transparent]=[backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]DefaultAlicomMessagePuller[backcolor=transparent]();
  31. [backcolor=transparent]        [backcolor=transparent]String[backcolor=transparent] accessKeyId[backcolor=transparent]=[backcolor=transparent]"yourAccessKeyId"[backcolor=transparent];
  32. [backcolor=transparent]        [backcolor=transparent]String[backcolor=transparent] accessKeySecret[backcolor=transparent]=[backcolor=transparent]"yourAccessKeySecret"[backcolor=transparent];
  33. [backcolor=transparent]        [backcolor=transparent]String[backcolor=transparent] messageType[backcolor=transparent]=[backcolor=transparent]"FlowReport"[backcolor=transparent];
  34. [backcolor=transparent]        [backcolor=transparent]String[backcolor=transparent] queueName[backcolor=transparent]=[backcolor=transparent]"yourQueueName"[backcolor=transparent];[backcolor=transparent]//在云通信页面开通相应业务消息后,就能在页面上获得对应的queueName
  35. [backcolor=transparent]        puller[backcolor=transparent].[backcolor=transparent]startReceiveMsg[backcolor=transparent]([backcolor=transparent]accessKeyId[backcolor=transparent],[backcolor=transparent]accessKeySecret [backcolor=transparent],[backcolor=transparent]messageType[backcolor=transparent],[backcolor=transparent]queueName [backcolor=transparent],[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]MyMessageListener[backcolor=transparent]());
  36. [backcolor=transparent]    [backcolor=transparent]}
  37. [backcolor=transparent]}

展开
收起
猫饭先生 2017-10-25 13:55:11 1651 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
探索连接的最后十秒”落时”的网关 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载