首先申请一个腾讯云的账户,登陆后访问以下网址
https://console.cloud.tencent.com/sms
新建一个应用
查看SDK AppID和App Key
设置常量 SMSContentUtil中常量皆由腾讯云中申请
服务类代码
package com.util;
import com.github.qcloudsms.*;
import com.github.qcloudsms.httpclient.HTTPException;
import org.json.JSONException;
import java.io.IOException;
/**
* 短信服务类
* 2018-05-16
*/
public class SMSService {
/**
* 自定义短信内容发送
* @param msg 短信内容
* @param number 用户手机号
* @return OK 成功 null 失败
*/
public static String sendMess(String msg , String number){
try {
SmsSingleSender ssender = new SmsSingleSender(SMSContentUtil.APPID, SMSContentUtil.APPKEY);
SmsSingleSenderResult result = ssender.send(0, "86", number,
msg, "", "");
System.out.print(result);