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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java实现阿里云接口发送短信验证码

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

版本

aliyun-java-sdk-core 4.4.6aliyun-java-sdk-ecs 4.17.6

請(qǐng)求參數(shù)

返回?cái)?shù)據(jù)

返回錯(cuò)誤碼請(qǐng)看我的另一篇文章 阿里云短信錯(cuò)誤碼
如何開通阿里云賬號(hào)即開啟短信服務(wù) 如何開啟阿里云短信服務(wù)

示例

package com.ncst;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;public class SendMs {public static void main(String[] args) {//隨機(jī)驗(yàn)證碼int newcode = (int) (Math.random() * 9999) + 100;//手機(jī)號(hào)long num = 15028999627L;CommonResponse response = sendMs(Integer.toString(newcode), Long.toString(num));System.out.println(response.getData());}/*** 發(fā)送短信** @param code* @param num* @return*/public static CommonResponse sendMs(String code, String num) {DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "你的阿里云:AccessKey ID", "你的阿里云:AccessKey Secret");IAcsClient client = new DefaultAcsClient(profile);CommonRequest request = new CommonRequest();request.setSysMethod(MethodType.POST);request.setSysDomain("dysmsapi.aliyuncs.com");request.setSysVersion("2017-05-25");request.setSysAction("SendSms");request.putQueryParameter("RegionId", "cn-hangzhou");//必填:待發(fā)送手機(jī)號(hào)request.putQueryParameter("PhoneNumbers", num);//必填:短信簽名-可在短信控制臺(tái)中找到request.putQueryParameter("SignName", "你的阿里云短信簽名");//必填:短信模板-可在短信控制臺(tái)中找到request.putQueryParameter("TemplateCode", "你的阿里云短信模板");//可選:模板中的變量替換JSON串,如模板內(nèi)容為"親愛的${name},您的驗(yàn)證碼為${code}"時(shí),此處的值為request.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}");try {CommonResponse response = client.getCommonResponse(request);return response;} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {e.printStackTrace();}throw new RuntimeException("ERROR");} }

運(yùn)行效果

總結(jié)

以上是生活随笔為你收集整理的java实现阿里云接口发送短信验证码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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