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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

阿里云的短信服务acsClient+java

發布時間:2024/3/13 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 阿里云的短信服务acsClient+java 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. 開通aliyun上的短信服務,主要得到

(1)訪問秘鑰 accessKeyId <==>AccessKeySecret
(2)短信簽名+模板code
參考官方文檔

2. API測試短信發送:

參考官方文檔
(1)下載sdk (原版)

<dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId><version>4.5.3</version></dependency>

(2) 測試

import com.aliyuncs.CommonRequest; import com.aliyuncs.CommonResponse; import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.IAcsClient; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.exceptions.ServerException; import com.aliyuncs.http.MethodType; import com.aliyuncs.profile.DefaultProfile; /* pom.xml <dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId><version>4.5.16</version> </dependency> */public void sendSms( ) {// 1. 初始化acsClientDefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret); IAcsClient client = new DefaultAcsClient(profile);// 2. 組裝請求對象/***http(s)://dysmsapi.aliyuncs.com/?Action=SendSms&PhoneNumbers=1381111*****&SignName=阿里云&TemplateCode=SMS_1530****&<公共請求參數>***/CommonRequest request = new CommonRequest();request.setSysMethod(MethodType.POST);request.setSysDomain("dysmsapi.aliyuncs.com"); // urlrequest.setSysVersion("2017-05-25");request.setSysAction("SendSms");/*****/request.putQueryParameter("RegionId", "cn-hangzhou");request.putQueryParameter("PhoneNumbers", phone); // 待發送手機號request.putQueryParameter("SignName", "aliyun"); // 短信簽名request.putQueryParameter("TemplateCode", "SMS_200191424"); // 短信模板code/**填充短信模板**/Map<String, String> params = new HashMap<>();params.put("station", "station");params.put("channel", "channel");params.put("alarm", "alarm");params.put("message", "message");request.putQueryParameter("TemplateParam", JSON.toJSONString(params)); // 短信模板變量對應的實際值// 3. 發送請求try {CommonResponse response = client.getCommonResponse(request); log.info(response.getData());} catch (Exception e) {log.error("短信發送失敗:", e);}}

總結

以上是生活随笔為你收集整理的阿里云的短信服务acsClient+java的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。