zoukankan      html  css  js  c++  java
  • 阿里短信集成

    1、准备工作

    阿里短信平台:

    https://www.aliyun.com/product/sms?utm_content=se_1006519387

     阿里云的账号我已经有了,也通过了实名认证,接下来的开通短信服务、申请签名、申请短信模板也都不难,关键是得等后台审核,挺耽误时间的

    我的模板内容:

    告警区域:${area},告警时间:${time},告警信息:${msg}。

     快速学习界面:

    https://dysms.console.aliyun.com/dysms.htm?spm=a2c4g.11186623.2.12.67466d880lhyXx#/quickStart

    还提供了sdk和demo的下载

     2、集成到项目

    导入两个需要依赖的jar

    工程依赖了2个jar包(存放在工程的libs目录下)
    * 1:aliyun-java-sdk-core.jar
    * 2:aliyun-java-sdk-dysmsapi.jar

    实现的代码可以从demo中拷贝,稍作修改即可

    3、异常处理

     集成后,在main方法中运行一切正常,但是当项目跑起来以后,触发短信发送时,却发生了异常,内容如下:

    16:06:15,491 ERROR [org.jboss.seam.async.AsynchronousExceptionHandler] (DefaultQuartzScheduler_Worker-8) Exception thrown whilst executing asynchronous call: java.lang.RuntimeException: exception invoking: doSendSmsEventInfo
        at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:154) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.Component.callComponentMethod(Component.java:2317) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.core.Events.raiseEvent(Events.java:85) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.async.AsynchronousEvent$1.process(AsynchronousEvent.java:33) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.run(Asynchronous.java:80) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.async.AsynchronousEvent.execute(AsynchronousEvent.java:27) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.async.QuartzDispatcher$QuartzJob.execute(QuartzDispatcher.java:243) [jboss-seam.jar:2.3.1.Final]
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [quartz.jar:1.6.5]
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525) [quartz.jar:1.6.5]
    Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_60]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_60]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_60]
        at java.lang.reflect.Method.invoke(Method.java:497) [rt.jar:1.8.0_60]
        at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:79) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.util.Work.workInTransaction(Work.java:61) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:196) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:114) [jboss-seam.jar:2.3.1.Final]
        at com.Tip3000.sms.ali.AliSmsUtilAction_$$_javassist_seam_23.doSendSmsEventInfo(AliSmsUtilAction_$$_javassist_seam_23.java)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_60]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_60]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_60]
        at java.lang.reflect.Method.invoke(Method.java:497) [rt.jar:1.8.0_60]
        at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) [jboss-seam.jar:2.3.1.Final]
        at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144) [jboss-seam.jar:2.3.1.Final]
        ... 8 more
    Caused by: java.lang.AbstractMethodError: gnu.xml.dom.DomElement.getTextContent()Ljava/lang/String;
        at com.aliyuncs.regions.InternalEndpointsParser.parseEndpoints(InternalEndpointsParser.java:56) [aliyun-java-sdk-core-3.3.1.jar:]
        at com.aliyuncs.regions.InternalEndpointsParser.getEndpoint(InternalEndpointsParser.java:90) [aliyun-java-sdk-core-3.3.1.jar:]
        at com.aliyuncs.profile.DefaultProfile.getEndpoints(DefaultProfile.java:148) [aliyun-java-sdk-core-3.3.1.jar:]
        at com.aliyuncs.profile.DefaultProfile.addEndpoint(DefaultProfile.java:269) [aliyun-java-sdk-core-3.3.1.jar:]
        at com.aliyuncs.profile.DefaultProfile.addEndpoint(DefaultProfile.java:263) [aliyun-java-sdk-core-3.3.1.jar:]
        at com.Tip3000.sms.ali.AliSmsUtil.sendSms(AliSmsUtil.java:93)
        at com.Tip3000.sms.ali.AliSmsUtilAction.doSendSmsEventInfo(AliSmsUtilAction.java:154)
        ... 35 more

     可见caused by gnu.xml.dom.DomElement,问题出在这个类,而这个类在 gnujaxp.jar 中,于是我删除了这个jar包,重新编译项目后,运行一切正常。

  • 相关阅读:
    剑指Offer——构建乘积数组
    剑指Offer——把二叉树打印成多行
    剑指Offer——二叉树的下一个结点
    剑指Offer——二叉搜索树与双向链表
    剑指Offer——二叉搜索树的后序遍历序列
    LeetCode——Construct Binary Tree from Inorder and Postorder Traversal
    LeetCode——Construct Binary Tree from Preorder and Inorder Traversal
    剑指Offer——重建二叉树2
    C++ STL基本容器的使用
    mysql中模糊查询的四种用法介绍
  • 原文地址:https://www.cnblogs.com/LcxSummer/p/14069509.html
Copyright © 2011-2022 走看看