日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

阿里云实现发送短信(Java实例教程)

發(fā)布時(shí)間:2023/12/20 java 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 阿里云实现发送短信(Java实例教程) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

目錄

    • 🍋發(fā)送驗(yàn)證碼
      • 🧣短信服務(wù)(推薦)
        • 🐳注冊(cè)購(gòu)買
        • 🏓代碼測(cè)試
      • 🖐Java組件封裝
        • 🥝發(fā)送實(shí)例
        • 🥝pom依賴
        • 🌈Spring.factories(略)
    • 🍎麻煩給博主點(diǎn)個(gè)關(guān)注+收藏+點(diǎn)贊!

🍋發(fā)送驗(yàn)證碼

短信發(fā)送是電信運(yùn)營(yíng)商提供的服務(wù),需要訪問(wèn)對(duì)應(yīng)的接口,不同運(yùn)營(yíng)商提供的接口地址肯定不一樣,如果直接訪問(wèn)這些接口就需要判斷收信息的手機(jī)號(hào)屬于哪個(gè)運(yùn)營(yíng)商,關(guān)鍵在于這些接口不對(duì)個(gè)人開(kāi)放,還要考慮調(diào)用短信服務(wù)的費(fèi)用問(wèn)題

因此目前調(diào)用短信業(yè)務(wù)都是使用第三方企業(yè)的短信服務(wù),他們與運(yùn)營(yíng)商合作,封裝了短信接口,調(diào)用方法,而且費(fèi)用相對(duì)便宜

第三方的短信服務(wù)有很多,其中阿里云也提供了短信服務(wù)

🧣短信服務(wù)(推薦)

🐳注冊(cè)購(gòu)買

第一步:阿里云首頁(yè)搜索短信服務(wù)

地址:添加鏈接描述

第二步:選擇購(gòu)買的短信服務(wù)

第三步:點(diǎn)擊購(gòu)買,有5條免費(fèi)使用,測(cè)試也會(huì)消耗使用次數(shù),用完了在付費(fèi)購(gòu)買即可

第四步:找到自己購(gòu)買的云服務(wù)

  • 可以看到已購(gòu)買的服務(wù)剩余數(shù)量

🏓代碼測(cè)試

第一步:參考API,在【API接口】中已經(jīng)給出了Java代碼怎么調(diào)用該服務(wù)的接口

第二步:參考API,編寫(xiě)發(fā)送短信工具類

import com.aliyun.tea.TeaModel;/**** @Title:* @ClassName: com.hssmart.common.utils.AliyunSms.java* @Description:** @Copyright suihao- Powered By 研發(fā)中心* @author: suihao* @date: 2022-11-01 15:51* @version V1.0*/ public class AliyunSms {/*** 使用AK&SK初始化賬號(hào)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);// 訪問(wèn)的域名config.endpoint = "dysmsapi.aliyuncs.com";return new com.aliyun.dysmsapi20170525.Client(config);}}

accessKeyId 以及accessKeySecret查找的方式“:
第一步點(diǎn)擊頭像打開(kāi)accessKey管理

第二部進(jìn)行查看所需要的accessKeyId 以及accessKeySecret

🖐Java組件封裝

🥝發(fā)送實(shí)例

package com.suihao.autoconfig.properties;public static void main(String[] args) {com.aliyun.dysmsapi20170525.Client client = AliyunSms.createClient("accessKeyId", "accessKeySecret");com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest().setSignName("簽名名稱").setTemplateCode("模板號(hào)碼").setPhoneNumbers("測(cè)試手機(jī)號(hào)").setTemplateParam("{\"code\":\"6666\"}");com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();com.aliyun.dysmsapi20170525.models.SendSmsResponse resp = client.sendSmsWithOptions(sendSmsRequest, runtime);com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(resp)));}

1.SignName代表的簽名名稱

2.TemplateCode代表的模板code

🥝pom依賴

<!--阿里云--><developers><developer><id>aliyundeveloper</id><name>Aliyun SDK</name><email>aliyunsdk@aliyun.com</email></developer></developers><distributionManagement><snapshotRepository><id>sonatype-nexus-snapshots</id><url>https://s01.oss.sonatype.org/content/repositories/snapshots</url></snapshotRepository><repository><id>sonatype-nexus-staging</id><url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url></repository></distributionManagement><scm><connection></connection><developerConnection></developerConnection><url></url></scm><dependencies><!--阿里云--><dependency><groupId>com.aliyun</groupId><artifactId>dysmsapi20170525</artifactId><version>2.0.22</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>tea-openapi</artifactId><version>0.2.6</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>tea-console</artifactId><version>0.0.1</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>tea-util</artifactId><version>0.2.14</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>tea</artifactId><version>1.1.14</version></dependency><!----></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><plugin><groupId>org.sonatype.plugins</groupId><artifactId>nexus-staging-maven-plugin</artifactId><version>1.6.3</version><extensions>true</extensions><configuration><serverId>sonatype-nexus-staging</serverId><nexusUrl>https://s01.oss.sonatype.org/</nexusUrl><autoReleaseAfterClose>true</autoReleaseAfterClose></configuration></plugin></plugins></build>

🌈Spring.factories(略)

🍎麻煩給博主點(diǎn)個(gè)關(guān)注+收藏+點(diǎn)贊!

總結(jié)

以上是生活随笔為你收集整理的阿里云实现发送短信(Java实例教程)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。