全部产品
Search
文档中心

JAVA

更新时间: 2019-11-26

入参列表

参数名称 参数类型 必填与否 样例取值 参数说明
MessageType String 必填 SmsReport 有一种消息类型:SmsReport。
QueueName String 必填 Alicom-Queue-xxxxxx-SmsReport 阿里巴巴提供的消息队列名称,在短信控制台—系统设置可以查看到。

出参列表

出参名称 出参类型 样例取值 参数说明
MessageId String 10080303003003 短信的发送ID
To String 452220121 短信的发送号码
Status Number 1 短信的发送状态: 1 (Success), 0 (Fail).
ErrorCode String success 短信发送返回的错误码
ErrorDescription String success 短信发送返回的错误码详细描述
SendDate String Mon, 24 Dec 2018 16:58:22 +0800 短信转发给运营商的时间
ReceiveDate String Mon, 24 Dec 2018 16:58:22 +0800 短信收到运营商回执的时间
NumberDetail String 号码的详细属性
└Country String Hongkong, China 号码所属国家
└Region String HongKong Number Region
└Carrier String CMI 号码所属的运营商网络

技术对接步骤

1.SDK下载:点击查看下载链接

2.编写样例程序

调用接口时,请注意:

  1. package com.alicom.mns.sample;
  2. import java.text.ParseException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. import org.apache.commons.logging.Log;
  8. import org.apache.commons.logging.LogFactory;
  9. import com.alicom.mns.tools.DefaultAlicomMessagePuller;
  10. import com.alicom.mns.tools.MessageListener;
  11. import com.aliyun.mns.model.Message;
  12. import com.google.gson.Gson;
  13. /**
  14. * This is the DEMO for SMS Delivery Report API
  15. */
  16. public class ReceiveDemo {
  17. private static Log logger=LogFactory.getLog(ReceiveDemo.class);
  18. static class MyMessageListener implements MessageListener{
  19. private Gson gson=new Gson();
  20. @Override
  21. public boolean dealMessage(Message message) {
  22. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  23. System.out.println("message receiver time from mns:" + format.format(new Date()));
  24. System.out.println("message handle: " + message.getReceiptHandle());
  25. System.out.println("message body: " + message.getMessageBodyAsString());
  26. System.out.println("message id: " + message.getMessageId());
  27. System.out.println("message dequeue count:" + message.getDequeueCount());
  28. System.out.println("Thread:" + Thread.currentThread().getName());
  29. try{
  30. Map<String,Object> contentMap=gson.fromJson(message.getMessageBodyAsString(), HashMap.class);
  31. String arg = (String) contentMap.get("arg");
  32. //Please start your own code here
  33. }catch(com.google.gson.JsonSyntaxException e){
  34. logger.error("error_json_format:"+message.getMessageBodyAsString(),e);
  35. // Message will be deleted for the format error
  36. return true;
  37. } catch (Throwable e) {
  38. // The exception caused by your own code. Message will not be deleted and be pushed again
  39. return false;
  40. }
  41. // Message will be deleted for the format error
  42. return true;
  43. }
  44. }
  45. public static void main(String[] args) throws Exception, ParseException {
  46. DefaultAlicomMessagePuller puller=new DefaultAlicomMessagePuller();
  47. //Set the size of asynchronous thread
  48. puller.setConsumeMinThreadSize(6);
  49. puller.setConsumeMaxThreadSize(16);
  50. puller.setThreadQueueSize(200);
  51. puller.setPullMsgThreadSize(1);
  52. //Only enabled when debugging, should be disabled at working status
  53. puller.openDebugLog(false);
  54. String regionIdForPop = "ap-southeast-1";
  55. String endpointNameForPop = "ap-southeast-1";
  56. String domainForPop = "dybaseapi.ap-southeast-1.aliyuncs.com";
  57. String mnsAccountEndpoint = "http://1493622401794734.mns.ap-southeast-1.aliyuncs.com";
  58. //AccessKey, you can get if from Alicloud Console
  59. String accessKeyId="yourAccessKeyId";
  60. String accessKeySecret="yourAccessKeySecret";
  61. //Message Type: SmsReport
  62. String messageType="SmsReport";
  63. //Message Quenue Name, you can get it from SMS console, like:Alicom-Queue-xxxxxx-SmsReport
  64. String queueName="Alicom-Queue-********-SmsReport";
  65. puller.startReceiveMsgForVPC(accessKeyId, accessKeySecret, messageType, queueName, regionIdForPop,
  66. endpointNameForPop, domainForPop, mnsAccountEndpoint,new MyMessageListener());
  67. }
  68. }