進入阿里云市場頁面:登錄后,選擇API,
在API服務(wù)頁面選擇我需要的短信接口項,點擊進入
選擇看對眼的接口服務(wù),
如果是試用就選擇0元/5次,如果有錢不愁花就選擇30000元/100000次的購買
支付完成后,點擊進入管理控制臺,
控制臺有剛剛購買的服務(wù)的一些參數(shù),最重要的是appcode,最為已購買的一個重要參數(shù),用于在代碼中發(fā)送參數(shù)后,進行相應(yīng)次數(shù)遞減的根據(jù)。
返回查看接口代碼。
復(fù)制頁面上提供的對應(yīng)語言的? main 方法 ,
創(chuàng)建云工具的包,與api接口的utils對應(yīng)
創(chuàng)建對應(yīng)的java類
復(fù)制HttpUtils的代碼過來。
添加對應(yīng)的依賴,
<dependencies> <!-- <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http-hc</artifactId> <version>3.1.10</version> </dependency> --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.15</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.2.1</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.2.1</version> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-util</artifactId> <version>9.3.7.v20160115</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.5</version> <scope>test</scope> </dependency> </dependencies>
Ctrl shirt o 自動導(dǎo)包, httpUtils自動導(dǎo)包,不再報錯。
在main方法的代碼上微調(diào),修改appcode的值
管理中心有已購買后生成的appcode,換掉就好
可用于發(fā)送參數(shù)的位置,如發(fā)送驗證碼等。
配置完成后,啟動main方法,返回執(zhí)行成功的resultType
手機收到的短信息:
?
鏈接:https://pan.baidu.com/s/1poKCr0hjw6xFUWIPoq-4xg
提取碼:u0dp
復(fù)制這段內(nèi)容后打開百度網(wǎng)盤手機App,操作更方便哦