当前位置: 首页 > 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>

相关文章:

  • AIGC 3D即将爆发,混合显示成为产业数字化的生产力平台
  • Docker 的基本概念和优势,以及在应用程序开发中的实际应用
  • C++ Qt QFile用法介绍与代码演示
  • 静态web服务器开发之HTTP协议
  • java通过年月获取当前月所有周(跨月),获取每周开始日期和结束日期
  • css 固定按钮到页面顶部或者底部的实现方式
  • 百度云加速免费版下线,推荐几款目前仍旧免费的CDN
  • 国家开放大学平时作业 练习题
  • C#,《小白学程序》第七课:列表(List)其一,编制《高铁车次信息表》
  • Git工作流和Commit规范
  • 【电子通识】为什么说做产品不是简单的将不同的技术进行搭积木?
  • 排序算法-----快速排序(非递归实现)
  • 安卓开发之HTTP API服务接口设计(基于okhttp3请求)
  • uni-app小程序 swiper 分页器样式修改
  • cocos2dx ​​Animate3D(二)
  • JavaScript 奇技淫巧
  • JavaScript创建对象的四种方式
  • JDK9: 集成 Jshell 和 Maven 项目.
  • learning koa2.x
  • nginx(二):进阶配置介绍--rewrite用法,压缩,https虚拟主机等
  • php ci框架整合银盛支付
  • Python socket服务器端、客户端传送信息
  • Python打包系统简单入门
  • socket.io+express实现聊天室的思考(三)
  • 阿里云购买磁盘后挂载
  • 关于Android中设置闹钟的相对比较完善的解决方案
  • 跨域
  • 前端每日实战 2018 年 7 月份项目汇总(共 29 个项目)
  • 如何用vue打造一个移动端音乐播放器
  • 入门级的git使用指北
  • 写代码的正确姿势
  • 用Python写一份独特的元宵节祝福
  • 责任链模式的两种实现
  • 1.Ext JS 建立web开发工程
  • postgresql行列转换函数
  • SAP CRM里Lead通过工作流自动创建Opportunity的原理讲解 ...
  • 阿里云ACE认证之理解CDN技术
  • 阿里云移动端播放器高级功能介绍
  • 国内开源镜像站点
  • 继 XDL 之后,阿里妈妈开源大规模分布式图表征学习框架 Euler ...
  • $.each()与$(selector).each()
  • (C11) 泛型表达式
  • (C语言)逆序输出字符串
  • (delphi11最新学习资料) Object Pascal 学习笔记---第2章第五节(日期和时间)
  • (八)Flask之app.route装饰器函数的参数
  • (不用互三)AI绘画工具应该如何选择
  • (二)hibernate配置管理
  • (附源码)ssm教材管理系统 毕业设计 011229
  • (企业 / 公司项目)前端使用pingyin-pro将汉字转成拼音
  • (十五)、把自己的镜像推送到 DockerHub
  • (四)鸿鹄云架构一服务注册中心
  • (原創) 物件導向與老子思想 (OO)
  • (自用)网络编程
  • ***测试-HTTP方法
  • 、写入Shellcode到注册表上线