生活随笔
收集整理的這篇文章主要介紹了
阿里短信服务 JAVA
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
阿里短信服務 JAVA 操作
進入阿里云控制臺 獲取到相關的 key
進入阿里的短信服務
將這里全部弄好 如果沒有審核通過的話 只能 配置測試賬號 進行一個測試操作
配置好測試賬號 也就完成了
接下來是代碼 測試賬號 用阿里提供的就行
package com.aliyun.sample;import com.aliyun.tea.*;
import com.aliyun.dysmsapi20170525.*;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;
import com.aliyun.teautil.*;
import com.aliyun.teautil.models.*;public class Sample {public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId
, String accessKeySecret
) throws Exception {Config config
= new Config().setAccessKeyId(accessKeyId
).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");SendSmsRequest sendSmsRequest
= new SendSmsRequest().setSignName("阿里云短信測試").setTemplateCode("SMS_154950909").setPhoneNumbers("測試手機號”").setTemplateParam("{\"code\":\"1234\"}");RuntimeOptions runtime
= new RuntimeOptions();try {client
.sendSmsWithOptions(sendSmsRequest
, runtime
);} catch (TeaException error
) {com.aliyun.teautil.Common.assertAsString(error
.message
);} catch (Exception _error
) {TeaException error
= new TeaException(_error
.getMessage(), _error
);com.aliyun.teautil.Common.assertAsString(error
.message
);} }
}
總結
以上是生活随笔為你收集整理的阿里短信服务 JAVA的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。