java对接阿里云短信平台
生活随笔
收集整理的這篇文章主要介紹了
java对接阿里云短信平台
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一. 阿里云管理平臺部分:
第一步:
注冊阿里云賬號(釘釘或者支付寶或淘寶都可以登錄)
第二步:
開通短信服務
第三步:
申請短信簽名(說是要兩個小時審核,其實半小時到1小時之間就差不多了.~~阿里效率還是很高的)
第四步:
添加短信模板
第五步:
使用云賬號登錄RAM控制臺。
在左側導航欄的人員管理菜單下,單擊用戶。
在用戶登錄名稱/顯示名稱列表下,單擊目標RAM用戶名稱。
在用戶AccessKey區域下,單擊創建AccessKey。
怎么進入RAM控制臺?
創建用戶:
添加權限:
后邊我們要查看短信接口的api文檔,看下怎么對接!
二. 代碼部分:
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.3</version> </dependency> */ public class SendSms {public static void main(String[] args) {DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");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");//需要注意的一點TemplateParam不是你在短信模板中的變量,code才是你在短信模板中的設置的變量JSONObject jsonCode = new JSONObject();jsonCode.put("code",code);request.putQueryParameter("TemplateParam", jsonCode.toJSONString());// 驗證碼try {CommonResponse response = client.getCommonResponse(request);System.out.println(response.getData());} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {e.printStackTrace();}} }
完畢 ! 有不明白的地方歡迎下方評論…
總結
以上是生活随笔為你收集整理的java对接阿里云短信平台的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CnOpenData中国专利详细地址数据
- 下一篇: 转:手机解锁码大全