当前位置:   article > 正文

对接阿里大于短信平台报错_dependency 鈥檃liyun-java-sdk-dysmsapi' not found

dependency 鈥檃liyun-java-sdk-dysmsapi' not found
  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>aliyun-java-sdk-core</artifactId>
  4. <version>3.7.1</version>注:如提示报错,先升级基础包版,无法解决可联系技术支持
  5. </dependency>
  6. <dependency>
  7. <groupId>com.aliyun</groupId>
  8. <artifactId>aliyun-java-sdk-dysmsapi</artifactId>
  9. <version>1.1.0</version>
  10. </dependency>
  • 报错:Exception in thread "main" java.lang.NoSuchMethodError: org.json.JSONArray.iterator()Ljava/util/Iterator;
  • 错误原因:未升级基础包版本,引起JSON的版本和引入的冲突。
  • 解决方案(2种):
  1. 升级原来引用的JSON基础包
  2. 将引入的aliyun-java-sdk-core的version修改为3.3.1 即:
  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>aliyun-java-sdk-core</artifactId>
  4. <version>3.3.1</version>注:如提示报错,==先升级基础包版==,无法解决可联系技术支持
  5. </dependency>
  • 调用过程实例:
    1. package com.alicom.dysms.api;
    2. import com.aliyuncs.DefaultAcsClient;
    3. import com.aliyuncs.IAcsClient;
    4. import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest;
    5. import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse;
    6. import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
    7. import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
    8. import com.aliyuncs.exceptions.ClientException;
    9. import com.aliyuncs.profile.DefaultProfile;
    10. import com.aliyuncs.profile.IClientProfile;
    11. import java.text.SimpleDateFormat;
    12. import java.util.Date;
    13. /**
    14. * Created on 17/6/7.
    15. * 短信API产品的DEMO程序,工程中包含了一个SmsDemo类,直接通过
    16. * 执行main函数即可体验短信产品API功能(只需要将AK替换成开通了云通信-短信产品功能的AK即可)
    17. * 工程依赖了2个jar包(存放在工程的libs目录下)
    18. * 1:aliyun-java-sdk-core.jar
    19. * 2:aliyun-java-sdk-dysmsapi.jar
    20. * 备注:Demo工程编码采用UTF-8
    21. * 国际短信发送请勿参照此DEMO
    22. */
    23. public class scratch {
    24. //产品名称:云通信短信API产品,开发者无需替换
    25. static final String product = "Dysmsapi";
    26. //产品域名,开发者无需替换
    27. static final String domain = "dysmsapi.aliyuncs.com";
    28. // TODO 此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
    29. static final String accessKeyId = "LTAIJtIqA8nc5kkV";
    30. static final String accessKeySecret = "9QifiCxzQo4dWKAoXUZiCtwq6mYKKG";
    31. public static SendSmsResponse sendSms() throws ClientException {
    32. //可自助调整超时时间
    33. System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
    34. System.setProperty("sun.net.client.defaultReadTimeout", "10000");
    35. //初始化acsClient,暂不支持region化
    36. IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
    37. DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
    38. IAcsClient acsClient = new DefaultAcsClient(profile);
    39. //组装请求对象-具体描述见控制台-文档部分内容
    40. SendSmsRequest request = new SendSmsRequest();
    41. //必填:待发送手机号
    42. request.setPhoneNumbers("1856267xxxx");
    43. //必填:短信签名-可在短信控制台中找到
    44. request.setSignName("xxxx");
    45. //必填:短信模板-可在短信控制台中找到
    46. request.setTemplateCode("SMS_1386xxxxx");
    47. //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
    48. request.setTemplateParam("{\"name\":\"Tom\", \"code\":\"123\"}");
    49. request.setTemplateParam("{\"code\":\"123456\"}");
    50. //选填-上行短信扩展码(无特殊需求用户请忽略此字段)
    51. //request.setSmsUpExtendCode("90997");
    52. //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
    53. request.setOutId("yourOutId");
    54. //hint 此处可能会抛出异常,注意catch
    55. SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
    56. return sendSmsResponse;
    57. }
    58. public static QuerySendDetailsResponse querySendDetails(String bizId) throws ClientException {
    59. //可自助调整超时时间
    60. System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
    61. System.setProperty("sun.net.client.defaultReadTimeout", "10000");
    62. //初始化acsClient,暂不支持region化
    63. IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
    64. DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
    65. IAcsClient acsClient = new DefaultAcsClient(profile);
    66. //组装请求对象
    67. QuerySendDetailsRequest request = new QuerySendDetailsRequest();
    68. //必填-号码
    69. request.setPhoneNumber("185xxxxxxxx");
    70. //可选-流水号
    71. request.setBizId(bizId);
    72. //必填-发送日期 支持30天内记录查询,格式yyyyMMdd
    73. SimpleDateFormat ft = new SimpleDateFormat("yyyyMMdd");
    74. request.setSendDate(ft.format(new Date()));
    75. //必填-页大小
    76. request.setPageSize(10L);
    77. //必填-当前页码从1开始计数
    78. request.setCurrentPage(1L);
    79. //hint 此处可能会抛出异常,注意catch
    80. QuerySendDetailsResponse querySendDetailsResponse = acsClient.getAcsResponse(request);
    81. return querySendDetailsResponse;
    82. }
    83. public static void main(String[] args) throws ClientException, InterruptedException {
    84. //发短信
    85. SendSmsResponse response = sendSms();
    86. System.out.println("短信接口返回的数据----------------");
    87. System.out.println("Code=" + response.getCode());
    88. System.out.println("Message=" + response.getMessage());
    89. System.out.println("RequestId=" + response.getRequestId());
    90. System.out.println("BizId=" + response.getBizId());
    91. Thread.sleep(3000L);
    92. //查明细
    93. if(response.getCode() != null && response.getCode().equals("OK")) {
    94. QuerySendDetailsResponse querySendDetailsResponse = querySendDetails(response.getBizId());
    95. System.out.println("短信明细查询接口返回数据----------------");
    96. System.out.println("Code=" + querySendDetailsResponse.getCode());
    97. System.out.println("Message=" + querySendDetailsResponse.getMessage());
    98. int i = 0;
    99. for(QuerySendDetailsResponse.SmsSendDetailDTO smsSendDetailDTO : querySendDetailsResponse.getSmsSendDetailDTOs())
    100. {
    101. System.out.println("SmsSendDetailDTO["+i+"]:");
    102. System.out.println("Content=" + smsSendDetailDTO.getContent());
    103. System.out.println("ErrCode=" + smsSendDetailDTO.getErrCode());
    104. System.out.println("OutId=" + smsSendDetailDTO.getOutId());
    105. System.out.println("PhoneNum=" + smsSendDetailDTO.getPhoneNum());
    106. System.out.println("ReceiveDate=" + smsSendDetailDTO.getReceiveDate());
    107. System.out.println("SendDate=" + smsSendDetailDTO.getSendDate());
    108. System.out.println("SendStatus=" + smsSendDetailDTO.getSendStatus());
    109. System.out.println("Template=" + smsSendDetailDTO.getTemplateCode());
    110. }
    111. System.out.println("TotalCount=" + querySendDetailsResponse.getTotalCount());
    112. System.out.println("RequestId=" + querySendDetailsResponse.getRequestId());
    113. }
    114. }
    115. }

     

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/70282
推荐阅读
相关标签
  

闽ICP备14008679号