一、pom.xml添加
<!-- 腾讯短信 --> <dependency> <groupId>com.github.qcloudsms</groupId> <artifactId>qcloudsms</artifactId> <version>1.0.3</version> </dependency>
二、
import com.github.qcloudsms.SmsSingleSender; import com.github.qcloudsms.SmsSingleSenderResult; import com.github.qcloudsms.httpclient.HTTPException; import org.json.JSONException; import java.io.IOException; /** * 腾讯云短信工具 */ public class TencentSms { private static int appid = ; private static String appkey = ""; //发送验证码 public static void sendVerificationCode(String mobile,String verificationCode){ String msg = "你的验证码为:"+verificationCode+",请妥善保管."; try { SmsSingleSender ssender = new SmsSingleSender(appid, appkey); SmsSingleSenderResult result = ssender.send(0, "86", mobile, msg, "", ""); System.out.print(result); } catch (HTTPException e) { // HTTP响应码错误 e.printStackTrace(); } catch (JSONException e) { // json解析错误 e.printStackTrace(); } catch (IOException e) { // 网络IO错误 e.printStackTrace(); } } public static void main(String[] args) { TencentSms.sendVerificationCode("",""); } }