(已解决)阿里云部署项目 阿里大于短信功能失效

  这两天在阿里云部署项目,项目主体是springboot2.2 + vue2.6.10,本地使用阿里大于短信功能正常,打成jar包,docker镜像,使用阿里云容器服务部署后,短信功能失效。

  我们使用的阿里云服务区域是上海。(很重要,短信设置跟区域有关)

  本地配置:

// 依赖部分
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>4.1.0</version>
</dependency>
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-dysmsapi</artifactId>
    <version>1.1.0</version>
</dependency>

// 代码部分(关键的部分)
CommonRequest request = new CommonRequest();
request.setDomain(“dysmsapi.aliyuncs.com”);
request.putQueryParameter("RegionId", "cn-hangzhou");

  本地运行发送短信功能正常,一旦部署到阿里云,就出现如下错误:(请求超时)

  com.aliyuncs.exceptions.ClientException: SDK.ServerUnreachable : Server unreachable: java.net.ConnectException: Connection timed out (Connection timed out) 

  经多次尝试,该问题得以解决:

  1、需要根据你的阿里云服务区域选择阿里大于短信服务内网IP

  https://help.aliyun.com/document_detail/68360.html?spm=a2c4g.11186623.6.699.1c0137edsk3wUh

  如我的服务区域是上海,我就选择上海的内网IP:dysmsapi-vpc.cn-shanghai.aliyuncs.com

  

   2、修改代码如下:

CommonRequest request = new CommonRequest();
// 设置区域为对应的内网地址
request.setDomain(“dysmsapi-vpc.cn-shanghai.aliyuncs.com”);
// 改为上海
request.putQueryParameter("RegionId", "cn-shanghai");

  按照上述方式修改后,短息发送成功。

  在问题处理过程中,网上资料并不多,有可能是个例,忘参考使用。

猜你喜欢

转载自www.cnblogs.com/SamNicole1809/p/12096497.html