开发者社区> 问答> 正文

发送短信验证码,偶尔会报错

com.aliyun.teautil.models.TeaUtilException: closed at com.aliyun.teautil.Common.readAsBytes(Common.java:175) at com.aliyun.teautil.Common.readAsString(Common.java:195) at com.aliyun.teautil.Common.readAsJSON(Common.java:208) at com.aliyun.teaopenapi.Client.doRPCRequest(Client.java:214) at com.aliyun.dysmsapi20170525.Client.sendSmsWithOptions(Client.java:199) at com.aliyun.dysmsapi20170525.Client.sendSms(Client.java:204) at com.with.assistant.service.impl.SmsServiceImpl.send(SmsServiceImpl.java:99) at com.with.assistant.service.impl.SmsServiceImpl.sendVerificationCode(SmsServiceImpl.java:54) at org.apache.dubbo.common.bytecode.Wrapper12.invokeMethod(Wrapper12.java) at org.apache.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:47) at org.apache.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:84) at org.apache.dubbo.config.invoker.DelegateProviderMetaDataInvoker.invoke(DelegateProviderMetaDataInvoker.java:56) at org.apache.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:56) at org.apache.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:52) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83) at org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:89) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83) at org.apache.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:46) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83) at org.apache.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:77) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83) at com.with.perfcounter.filter.DubboFilter.invoke(DubboFilter.java:55) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83) at org.apache.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:129) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83) at org.apache.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:152) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83) at org.apache.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83) at org.apache.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:41) at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:83) at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:145) at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:100) at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:175) at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:51) at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:57) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.io.IOException: closed at okio.RealBufferedSource$inputStream$1.read(RealBufferedSource.kt:154) at java.io.InputStream.read(InputStream.java:101) at com.aliyun.teautil.Common.readAsBytes(Common.java:167) ... 38 common frames omitted

    使用的 SDK
    <dependency>
        <groupId>com.aliyun</groupId>
        <artifactId>dysmsapi20170525</artifactId>
        <version>2.0.4</version>
    </dependency>
    
    SendSmsRequest request = new SendSmsRequest();
    request.setPhoneNumbers(mobile)
            .setTemplateCode(templateCode)
            .setSignName(aliyunConfig.getSmsSignName())
    ;
    if (params != null) {
        request.setTemplateParam(params.toString());
    }
    try {
        SendSmsResponse res = client.sendSms(request);
        if ("OK".equals(res.body.code)) {
            return true;
        }
        Gson gson = new Gson();
        log.error("短信验证码发送错误,templateCode={},signName={},mobile={},params={},retBody={}", templateCode, aliyunConfig.getSmsSignName(), mobile, (params == null ? "null" : params.toString()), gson.toJson(res.getBody()));
        return false;
    } catch (Exception e) {
        log.error("短信验证码发送错误,templateCode={},signName={},mobile={},params={}", templateCode, aliyunConfig.getSmsSignName(), mobile, (params == null ? "null" : params.toString()), e);
    }
    return false;

展开
收起
oxrphxuidnvom 2021-08-04 20:50:44 777 0
1 条回答
写回答
取消 提交回答
  • 2.0.10 也有这个问题,这么多年还没解决呢

    2024-10-13 13:43:32
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载