亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Springboot整合阿里巴巴SMS的實(shí)現(xiàn)示例

 更新時(shí)間:2023年12月14日 10:49:27   作者:墮落年代  
本文主要介紹了Springboot整合阿里巴巴SMS的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

前提條件

用戶權(quán)限

要確保用戶有這個(gè)權(quán)限

組權(quán)限

還要確保組要有這個(gè)權(quán)限

講反了要先保證組有這個(gè)權(quán)限然后保證用戶有這個(gè)權(quán)限,然后就可以使用這個(gè)用戶的權(quán)限的key來(lái)調(diào)取api了

申請(qǐng)資質(zhì)、簽名等

申請(qǐng)資質(zhì)

申請(qǐng)資質(zhì)

點(diǎn)擊這個(gè)進(jìn)入聲請(qǐng)就可以了然后等2個(gè)小時(shí)左右就可以通過(guò)了

申請(qǐng)簽名

在這里插入圖片描述

這個(gè)是為了之后自定義模板做準(zhǔn)備

添加模板

添加模板

當(dāng)然第一次是可以注冊(cè)釘釘認(rèn)證之后獲取免費(fèi)的一些額度

api引入

依賴引入

<!--sms的服務(wù)-->
 <dependency>
     <groupId>com.aliyun</groupId>
     <artifactId>alibabacloud-dysmsapi20170525</artifactId>
     <version>2.0.24</version>
 </dependency>

代碼部分

package com.example.lpms.tool;

import com.example.lpms.common.R;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.service.dysmsapi20170525.models.*;
import com.aliyun.sdk.service.dysmsapi20170525.*;
import com.google.gson.Gson;
import darabonba.core.client.ClientOverrideConfiguration;

import java.util.concurrent.CompletableFuture;

/**
 * @author:DUOLUONIANDAI
 * @DATA:2023/12/13
 * @Title:
 */

@Component
public class SMSTool {
    @Value("${spring.sms.id}")
    String id;

    @Value("${spring.sms.secret}")
    String secret;

    @Value("${spring.sms.sign-name}")
    String signName;

    @Value("${spring.sms.templateCode}")
    String templateCode;

    public R sendSMS(String phone, String captcha) {

        try {

            // Configure Credentials authentication information, including ak, secret, token
            StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                    .accessKeyId(id)
                    .accessKeySecret(secret)
                    //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
                    .build());

            // Configure the Client
            AsyncClient client = AsyncClient.builder()
                    .region("cn-shanghai") // Region ID
                    //.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
                    .credentialsProvider(provider)
                    //.serviceConfiguration(Configuration.create()) // Service-level configuration
                    // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
                    .overrideConfiguration(
                            ClientOverrideConfiguration.create()
                                    // Endpoint 請(qǐng)參考 https://api.aliyun.com/product/Dysmsapi
                                    .setEndpointOverride("dysmsapi.aliyuncs.com")
                            //.setConnectTimeout(Duration.ofSeconds(30))
                    )
                    .build();

            // Parameter settings for API request
            SendSmsRequest sendSmsRequest = SendSmsRequest.builder()
                    .signName(signName)
                    .templateCode(templateCode)
                    .phoneNumbers(phone)
                    .templateParam("{\"code\":\"" + captcha + "\"}")
                    // Request-level configuration rewrite, can set Http request parameters, etc.
                    // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                    .build();

            // Asynchronously get the return value of the API request
            CompletableFuture<SendSmsResponse> response = client.sendSms(sendSmsRequest);
            // Synchronously get the return value of the API request
            SendSmsResponse resp = response.get();
            System.out.println(new Gson().toJson(resp));


            // Finally, close the client
            client.close();
        } catch (Exception e) {
            e.printStackTrace();
            return R.fail();
        }


        return R.ok();
    }

}

注意

這下面和官網(wǎng)不一樣但是不這樣寫會(huì)報(bào)錯(cuò),好像是因?yàn)檫@個(gè)是直接注入到哪里的,而這里是不需要注入的

// Configure Credentials authentication information, including ak, secret, token
StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
        .accessKeyId(id)
        .accessKeySecret(secret)
        //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
        .build());

到此這篇關(guān)于Springboot整合阿里巴巴SMS的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)Springboot整合阿里巴巴SMS內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

  • Lucene源碼系列多值編碼壓縮算法實(shí)例詳解

    Lucene源碼系列多值編碼壓縮算法實(shí)例詳解

    這篇文章主要為大家介紹了Lucene源碼系列多值編碼壓縮算法實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • Spring Boot加密配置文件特殊內(nèi)容的示例代碼詳解

    Spring Boot加密配置文件特殊內(nèi)容的示例代碼詳解

    這篇文章主要介紹了Spring Boot加密配置文件特殊內(nèi)容的相關(guān)知識(shí),本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-05-05
  • 兼容Spring Boot 1.x和2.x配置類參數(shù)綁定的工具類SpringBootBindUtil

    兼容Spring Boot 1.x和2.x配置類參數(shù)綁定的工具類SpringBootBindUtil

    今天小編就為大家分享一篇關(guān)于兼容Spring Boot 1.x和2.x配置類參數(shù)綁定的工具類SpringBootBindUtil,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2018-12-12
  • maven 打包項(xiàng)目的幾種方式

    maven 打包項(xiàng)目的幾種方式

    maven目前在web上面的使用方式很普遍,而打包的方式也存在很多方式,本文就詳細(xì)的介紹了三種方式,具有一定的參考價(jià)值,感興趣的可以了解下
    2021-06-06
  • 淺談SpringBoot是如何實(shí)現(xiàn)日志的

    淺談SpringBoot是如何實(shí)現(xiàn)日志的

    這篇文章主要介紹了淺談SpringBoot是如何實(shí)現(xiàn)日志的,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • ThreadPoolExecutor核心線程數(shù)和RocketMQ消費(fèi)線程調(diào)整詳解

    ThreadPoolExecutor核心線程數(shù)和RocketMQ消費(fèi)線程調(diào)整詳解

    這篇文章主要介紹了ThreadPoolExecutor核心線程數(shù)和RocketMQ消費(fèi)線程調(diào)整詳解,Rocketmq 消費(fèi)者在高峰期希望手動(dòng)減少消費(fèi)線程數(shù),通過(guò)DefaultMQPushConsumer.updateCorePoolSize方法可以調(diào)用內(nèi)部的setCorePoolSize設(shè)置多線程核心線程數(shù),需要的朋友可以參考下
    2023-10-10
  • MybatisPlus實(shí)現(xiàn)insertBatchSomeColumn進(jìn)行批量增加

    MybatisPlus實(shí)現(xiàn)insertBatchSomeColumn進(jìn)行批量增加

    本文主要介紹了MybatisPlus實(shí)現(xiàn)insertBatchSomeColumn進(jìn)行批量增加,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • Java實(shí)現(xiàn)猜字小游戲

    Java實(shí)現(xiàn)猜字小游戲

    這篇文章給大家分享小編隨手寫的猜字小游戲,基于java代碼寫的,感興趣的朋友跟隨小編一起看看吧
    2019-11-11
  • @RequestBody的使用案例代碼

    @RequestBody的使用案例代碼

    @RequestBody主要用來(lái)接收前端傳遞給后端的json字符串中的數(shù)據(jù)的,這篇文章主要介紹了@RequestBody的使用,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-02-02
  • Java 對(duì)10個(gè)數(shù)進(jìn)行排序的實(shí)現(xiàn)代碼

    Java 對(duì)10個(gè)數(shù)進(jìn)行排序的實(shí)現(xiàn)代碼

    可以利用選擇法,即從后9個(gè)比較過(guò)程中,選擇一個(gè)最小的與第一個(gè)元素交換, 下次類推,即用第二個(gè)元素與后8個(gè)進(jìn)行比較,并進(jìn)行交換
    2017-02-02

最新評(píng)論