国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【快速上手系列】使用阿里云發(fā)送測試短信超簡單教程

這篇具有很好參考價值的文章主要介紹了【快速上手系列】使用阿里云發(fā)送測試短信超簡單教程。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

【快速上手系列】使用阿里云發(fā)送測試短信超簡單教程

步驟

一、阿里云配置

1、進(jìn)入阿里云首頁點擊短信服務(wù)

阿里云短信測試,# 快速上手系列,# 各種接口,阿里云,java,云計算,intellij-idea

2、短信服務(wù)界面

阿里云短信測試,# 快速上手系列,# 各種接口,阿里云,java,云計算,intellij-idea

3、點擊快速學(xué)習(xí),然后綁定測試手機(jī)號,綁定好后點擊調(diào)用API發(fā)送短信

阿里云短信測試,# 快速上手系列,# 各種接口,阿里云,java,云計算,intellij-idea

4、左側(cè)可以看到一些參數(shù)設(shè)置,右面是可以選擇的demo代碼

阿里云短信測試,# 快速上手系列,# 各種接口,阿里云,java,云計算,intellij-idea

5、測試代碼中需要改的是你自己的accessKeyIdaccessKeySecret

在短信服務(wù)頁面或主頁的右上角點擊自己的賬號,然后點擊AccessKeyId管理

阿里云短信測試,# 快速上手系列,# 各種接口,阿里云,java,云計算,intellij-idea

點擊創(chuàng)建AccessKey,然后點擊查看Secret

阿里云短信測試,# 快速上手系列,# 各種接口,阿里云,java,云計算,intellij-idea

可以看到上面有AccessKey IDAccessKey Secret,這兩個參數(shù)內(nèi)容都要復(fù)制下來,都是一會要用到的(查看已有的需要手機(jī)號再次驗證)

至此網(wǎng)站的配置完成

二、代碼

1、配置maven依賴:pom.xml

<!-- 阿里云短信服務(wù) -->
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>dysmsapi20170525</artifactId>
    <version>2.0.22</version>
</dependency>
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>darabonba-java-core</artifactId>
    <version>0.1.5-beta</version>
</dependency>
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>alibabacloud-dysmsapi20170525</artifactId>
    <version>1.0.1</version>
</dependency>
<!-- 運行時可能會發(fā)生缺少slf4j的錯誤,雖然不一定,但是盡量導(dǎo)一下比較好 -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-nop</artifactId>
    <version>1.7.2</version>
</dependency>

2、這里用的是升級版的SDK版本,雖然官網(wǎng)都有代碼了,還是在這里粘一下

在這兩個demo里面都只需要改兩個參數(shù):就是我們上面保存的那個AccessKey IDAccessKey Secret

tips:這兩個demo里面只改這兩個參數(shù)和手機(jī)號即可(就是格式為----------XXXX----------的這種)

Java(異步)demo
// This file is auto-generated, don't edit it. Thanks.
package com.r.demo;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpClient;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.core.http.ProxyOptions;
import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
import com.aliyun.sdk.service.dysmsapi20170525.models.*;
import com.aliyun.sdk.service.dysmsapi20170525.*;
import com.google.gson.Gson;
import darabonba.core.RequestConfiguration;
import darabonba.core.client.ClientOverrideConfiguration;
import darabonba.core.utils.CommonUtil;
import darabonba.core.TeaPair;

//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;

public class SendSms {
    public static void main(String[] args) throws Exception {

        // HttpClient Configuration
        /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                .connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout time, the default is 10 seconds
                .responseTimeout(Duration.ofSeconds(10)) // Set the response timeout time, the default is 20 seconds
                .maxConnections(128) // Set the connection pool size
                .maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout, the default is 30 seconds
                // Configure the proxy
                .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<your-proxy-hostname>", 9001))
                        .setCredentials("<your-proxy-username>", "<your-proxy-password>"))
                // If it is an https connection, you need to configure the certificate, or ignore the certificate(.ignoreSSL(true))
                .x509TrustManagers(new X509TrustManager[]{})
                .keyManagers(new KeyManager[]{})
                .ignoreSSL(false)
                .build();*/

        // Configure Credentials authentication information, including ak, secret, token
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                .accessKeyId("----------在這里寫上自己的accessKeyId即可----------")
                .accessKeySecret("----------在這里寫上自己的accessKeySecret即可----------")
                //.securityToken("<your-token>") // use STS token
                .build());

        // Configure the Client
        AsyncClient client = AsyncClient.builder()
                .region("cn-hangzhou") // 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()
                                .setEndpointOverride("dysmsapi.aliyuncs.com")
                        //.setConnectTimeout(Duration.ofSeconds(30))
                )
                .build();

        // Parameter settings for API request
        SendSmsRequest sendSmsRequest = SendSmsRequest.builder()
                .signName("阿里云短信測試")
                .templateCode("SMS_154950909")
                .phoneNumbers("----------這里是你自己的手機(jī)號----------")
                .templateParam("{\"code\":\"1234\"}")
                // 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));
        // Asynchronous processing of return values
        /*response.thenAccept(resp -> {
            System.out.println(new Gson().toJson(resp));
        }).exceptionally(throwable -> { // Handling exceptions
            System.out.println(throwable.getMessage());
            return null;
        });*/

        // Finally, close the client
        client.close();
    }

}
運行結(jié)果

阿里云短信測試,# 快速上手系列,# 各種接口,阿里云,java,云計算,intellij-idea

太長了就不截了

直接結(jié)果

{“headers”:{“Access-Control-Allow-Origin”:“*”,“x-acs-request-id”:“50F579AA-A36C-547C-9887-C9B597DBC519”,“Connection”:“keep-alive”,“Content-Length”:“110”,“Date”:“Sat, 29 Oct 2022 15:05:40 GMT”,“Content-Type”:“application/json;charset\u003dutf-8”,“x-acs-trace-id”:“2ca803d78068d3d55a936b22b44c5c68”},“body”:{“bizId”:“755622367055939907^0”,“code”:“OK”,“message”:“OK”,“requestId”:“50F579AA-A36C-547C-9887-C9B597DBC519”}}

Java demo
// This file is auto-generated, don't edit it. Thanks.
package com.r.demo;

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);
        // 訪問的域名
        config.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_);
        com.aliyun.dysmsapi20170525.Client client = Sample.createClient("----------在這里寫上自己的accessKeyId即可----------", "----------在這里寫上自己的accessKeySecret即可----------");
        com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
                .setSignName("阿里云短信測試")
                .setTemplateCode("SMS_154950909")
                .setPhoneNumbers("----------這里是你自己的手機(jī)號----------")
                .setTemplateParam("{\"code\":\"1234\"}");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // 復(fù)制代碼運行請自行打印 API 的返回值
            client.sendSmsWithOptions(sendSmsRequest, runtime);
            
            //這里我自己寫了一個打印,要不然默認(rèn)給的demo是不輸出任何東西的,要不是收到短信了我還以為運行沒反應(yīng)呢。。。
            System.out.println("------------短信發(fā)送成功-------------");
            System.out.println("發(fā)送的手機(jī)號:" + sendSmsRequest.getPhoneNumbers() + "\n" +
                    "信息內(nèi)容:" + sendSmsRequest.getTemplateParam());
            
        } catch (TeaException error) {
            // 如有需要,請打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 如有需要,請打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}
運行結(jié)果

阿里云短信測試,# 快速上手系列,# 各種接口,阿里云,java,云計算,intellij-idea

手機(jī)收到的短信

阿里云短信測試,# 快速上手系列,# 各種接口,阿里云,java,云計算,intellij-idea文章來源地址http://www.zghlxwxcb.cn/news/detail-787507.html

到了這里,關(guān)于【快速上手系列】使用阿里云發(fā)送測試短信超簡單教程的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 阿里云短信發(fā)送接口實現(xiàn)

    阿里云短信發(fā)送接口實現(xiàn)

    使用阿里云短信接口發(fā)送驗證碼 springboot 工程引入web 引入 lombok 關(guān)鍵代碼引入 啟動項目,訪問接口,短信發(fā)送成功!

    2024年02月11日
    瀏覽(18)
  • python發(fā)送阿里云短信教程

    python發(fā)送阿里云短信教程

    1、開通云短信 注冊阿里云,開通短信服務(wù)。 2、快速學(xué)習(xí) 進(jìn)入控制臺后,點擊左邊的快速學(xué)習(xí),申請簽名,申請模板 簽名與模板的生成需要審核,需等待,注意簽名與模板作用范圍要一致。 2.1、添加簽名 添加簽名,如果是驗證碼就選驗證碼,如果是自己定義模板,則選擇

    2024年01月15日
    瀏覽(16)
  • 最近項目上需要發(fā)送短信整理了一篇文章 SpringBoot整合阿里云發(fā)送短信

    最近項目上需要發(fā)送短信整理了一篇文章 SpringBoot整合阿里云發(fā)送短信

    阿里云短信服務(wù)網(wǎng)址:阿里云登錄 - 歡迎登錄阿里云,安全穩(wěn)定的云計算服務(wù)平臺 第一步:申請簽名(一般申請時長在1-2小時之間)特別注意:場景說明不要亂填以免申請不通過 ?第二步:申請短信模板(一般申請時長在1-2小時之間)特別注意:場景說明不要亂填以免申請不

    2024年02月06日
    瀏覽(14)
  • java 阿里云 發(fā)送短信功能實現(xiàn)

    java 阿里云 發(fā)送短信功能實現(xiàn)

    ????????常用短信服務(wù)平臺:阿里云、華為云、騰訊云、京東、夢網(wǎng)、樂信等 ????????AccessKey 是訪問阿里云 API 的密鑰,具有賬戶的完全權(quán)限,我們要想在后面通過API調(diào)用阿里云短信服務(wù)的接口發(fā)送短信,那么就必須要設(shè)置AccessKey。 ????????控制臺頁面---點擊右上

    2024年02月02日
    瀏覽(21)
  • Java阿里云短信發(fā)送工具類

    阿里云短信發(fā)送:調(diào)用SendSms發(fā)送短信_短信服務(wù)-阿里云幫助中心 ?工具類:

    2024年02月12日
    瀏覽(18)
  • (短信服務(wù))java SpringBoot 阿里云短信功能實現(xiàn)發(fā)送手機(jī)驗證碼

    (短信服務(wù))java SpringBoot 阿里云短信功能實現(xiàn)發(fā)送手機(jī)驗證碼

    阿里云官網(wǎng):?https://www.aliyun.com/ 點擊官網(wǎng)首頁注冊按鈕。 注冊成功后,點擊登錄按鈕進(jìn)行登錄。登錄后進(jìn)入短信服務(wù)管理頁面,選擇國內(nèi)消息菜單: 短信簽名是短信發(fā)送者的署名,表示發(fā)送方的身份。 切換到【模板管理】標(biāo)簽頁: 短信模板包含短信發(fā)送內(nèi)容、場景、變量信息

    2024年02月02日
    瀏覽(34)
  • 通過阿里大于發(fā)送短信,新手入門指導(dǎo)手冊

    通過阿里大于發(fā)送短信,新手入門指導(dǎo)手冊

    官網(wǎng)地址: 阿里云官網(wǎng) 支持釘釘賬號, 支付寶賬號等第三方登錄,如果沒有這些賬號,請注冊阿里云賬號. 第一步: 如果找不到短信服務(wù)菜單,請根據(jù)下圖操作: 第二步:在彈出的搜索框里面,輸入短信服務(wù) 第三步:根據(jù)搜索的短信服務(wù),下面會顯示短信服務(wù)的頁面,選中任意一個點擊進(jìn)

    2023年04月08日
    瀏覽(26)
  • 【Springboot】| 阿里云發(fā)送短信驗證碼,你會了嗎?

    【Springboot】| 阿里云發(fā)送短信驗證碼,你會了嗎?

    專欄 名字 ??Elasticsearch專欄 es ??spring專欄 spring開發(fā) redis專欄 redis學(xué)習(xí)筆記 ??項目專欄 項目集錦 修bug專欄 bug修理廠 獅子之前發(fā)了一篇《郵箱發(fā)送驗證碼,你會了嗎?》,很快上了熱度榜單,但是那篇文章只是簡單介紹了如何接收驗證碼的流程以及安利了一個接收驗證碼的

    2024年02月08日
    瀏覽(16)
  • springboot整合阿里大于并結(jié)合mq發(fā)送短信

    在 pom.xml 文件中添加以下依賴: 在 application.properties 文件中添加以下配置: 其中, accessKeyId 和 accessKeySecret 是阿里云控制臺上的AccessKey, signName 是短信簽名, templateCode 是短信模板ID。 在Spring Boot中,我們可以使用MQ來異步發(fā)送短信,提高系統(tǒng)的響應(yīng)速度。這里以ActiveMQ為例

    2024年02月08日
    瀏覽(20)
  • Sms多平臺短信服務(wù)商系統(tǒng)~完成阿里云短信服務(wù)發(fā)送可自行配置

    Sms多平臺短信服務(wù)商系統(tǒng)~完成阿里云短信服務(wù)發(fā)送可自行配置

    阿里云地址 不同編程語言都有對應(yīng)的SDK,你們下載自己需要的即可。 pom.xml中添加maven坐標(biāo) 接下來的代碼不是單純的使用短信服務(wù)商提供的發(fā)送代碼來完成短信的發(fā)送那樣子就太簡單了,我想你們也不想看這樣的文章了CSDN一抓一大把,或者看官方文檔即可。為了通用短信服務(wù)

    2024年02月09日
    瀏覽(24)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包