下载gradle project:https://start.spring.io/
将安装包解压到项目文件夹,并按住shift右键打开powershell,输入gradle build,回车,gradle编译完成后关闭窗口。
在eclipse中import编译后的文件夹
腾讯云:https://console.cloud.tencent.com/sms/smsinfo/1400211152/0
下载qcloudsms-1.0.5.jar,地址:https://console.cloud.tencent.com/sms/sdkAPI
UserController.java:
package com.sikiedu.sms.controller; import java.io.IOException; import org.json.JSONException; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.github.qcloudsms.SmsSingleSender; import com.github.qcloudsms.SmsSingleSenderResult; import com.github.qcloudsms.httpclient.HTTPException; @RestController public class UserController { @RequestMapping("/test") public String test(){ // 给手机发送短信 // 1.appid int appid=1400211152; // 2.APPkey String appkey="27832480cfa3f0c5c12aba338eecf29d"; // 短信的模板id int templateID=338115; // 签名的名字 String smsSign="李大疆公众号"; // 要发送对象的电话号码 String phoneNumber="18681693083"; // 验证码,需要是数组类型 String[] params={"1234"}; SmsSingleSender ssender=new SmsSingleSender(appid, appkey); try { // 地区,电话,使用的模板id,验证码,签名。后面两个不管,空字符串就行 SmsSingleSenderResult result = ssender.sendWithParam("86", phoneNumber, templateID, params, smsSign, "", ""); System.out.println(result); } catch (HTTPException | JSONException | IOException e) { e.printStackTrace(); } return "success"; } }运行。在SmsApplication.java上右键【run as】-【java application】,注意:运行前一定要关闭当前的运行状态
手机上面也收到短信了
