当前位置: 首页 > news >正文

阿里云发送短信

官方代码如下:

// This file is auto-generated, don't edit it. Thanks.
package com.aliyun.sample;import com.aliyun.tea.*;public class Sample {/*** 使用AK&SK初始化账号Client* @param accessKeyId* @param accessKeySecret* @return Client* @throws Exception*/public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()// 必填,您的 AccessKey ID.setAccessKeyId(accessKeyId)// 必填,您的 AccessKey Secret.setAccessKeySecret(accessKeySecret);// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapiconfig.endpoint = "dysmsapi.aliyuncs.com";return new com.aliyun.dysmsapi20170525.Client(config);}public static void main(String[] args_) throws Exception {java.util.List<String> args = java.util.Arrays.asList(args_);// 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例使用环境变量获取 AccessKey 的方式进行调用,仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.htmlcom.aliyun.dysmsapi20170525.Client client = Sample.createClient(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest().setSignName("阿里云短信测试").setTemplateCode("SMS_154950909").setPhoneNumbers("15138098888").setTemplateParam("{\"code\":\"1234\"}");com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();try {// 复制代码运行请自行打印 API 的返回值client.sendSmsWithOptions(sendSmsRequest, runtime);} catch (TeaException error) {// 如有需要,请打印 errorcom.aliyun.teautil.Common.assertAsString(error.message);} catch (Exception _error) {TeaException error = new TeaException(_error.getMessage(), _error);// 如有需要,请打印 errorcom.aliyun.teautil.Common.assertAsString(error.message);}        }
}

上述代码在使用的时候只需要更改这几个地方即可。
在这里插入图片描述
对应的pom依赖

<dependency><groupId>com.aliyun</groupId><artifactId>dysmsapi20170525</artifactId><version>2.0.1</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>tea-openapi</artifactId><version>0.0.13</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>tea-console</artifactId><version>0.0.1</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>darabonba-env</artifactId><version>0.1.1</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>tea-util</artifactId><version>0.2.11</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>darabonba-time</artifactId><version>0.0.1</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>darabonba-string</artifactId><version>0.0.3</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>tea</artifactId><version>[1.0.3, 2.0.0)</version></dependency><dependency><groupId>org.locationtech.jts</groupId><artifactId>jts-core</artifactId><version>1.17.1</version> </dependency>
http://www.lryc.cn/news/239735.html

相关文章:

  • 关于用css设置input输入框hover的时候的样式以及当input为disabled的时候,不要让hover样式生效
  • hadoop在本地创建文件,然后将文件拷贝/上传到HDFS
  • NFC:应用场景广泛的短距离通信技术
  • CentOS使用docker安装OpenGauss数据库
  • 原理Redis-QuickList
  • js双击修改元素内容并提交到后端封装实现
  • Kubernetes+Gitlab+Jenkins+ArgoCD多集群部署
  • 在中国企业出海的大浪潮下,亚马逊云科技提供遍及全球的基础设施和技术支持
  • 前端如何判空
  • 基于SSM的焦作旅游协会管理系统设计与实现
  • 庖丁解牛:NIO核心概念与机制详解 07 _ 字符集
  • ansible的基本安装
  • 开发仿抖音APP遇到的问题和解决方案
  • 手机上玩.NET的两种方式
  • DedeBIZ 管理系统 DedeV6 v6.2.6 社区版 免费授权版
  • 编译 CUDA加速的 OpenCV-4.8.0 版本
  • 设计模式篇---外观模式
  • leetcode:520. 检测大写字母
  • 5-6求1-20的阶乘和
  • web需求记录
  • [网鼎杯 2018]Fakebook
  • 微信小程序蓝牙连接 uniApp蓝牙连接设备
  • 启动Dubbo项目注册Zookeeper时提示zookeeper not connected异常原理解析
  • 我在Vscode学OpenCV 几何变换(缩放、翻转、仿射变换、透视、重映射)
  • MATLAB算法实战应用案例精讲-【图像处理】图像缩放
  • Doris的PROPERTIES与ENGINE(九)
  • 华为云数据库 RDS 下载全量备份文件 wget
  • C#使用whisper.net实现语音识别(语音转文本)
  • 从零开始学习typescript——运算符(算术运算符、赋值运算符、比较运算符)
  • likeshop单商户商城系统 任意文件上传漏洞复现