Tencent cloud messaging
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import org.json.JSONException;
import javax.xml.ws.http.HTTPException;
import java.io.IOException;
public class SmsUtil {
private static final int appid = 1400285071;
private static final String appkey = "填写你申请的appkey";
private static String res;
private static final int templateId = 填写你申请的templateId;
private static final String smsSign = "填写你申请的smsSign";
public static String sendSMS(String phoneNumber, String stationName, String context) {
SmsSingleSenderResult result = null;
try {
String[] params = {stationName, context};
SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
result = ssender.sendWithParam("86", phoneNumber, templateId, params, smsSign, "", "");
if (result.result == 0) {
res = "短信发送成功";
} else {
res = "短信发送失败";
}
} catch (HTTPException e) {
return result.toString();
} catch (JSONException e) {
return result.toString();
} catch (IOException e) {
return result.toString();
} catch (com.github.qcloudsms.httpclient.HTTPException e) {
e.printStackTrace();
}
return res;
}
public static void main(String[] args) {
String res = sendSMS("phoneNumber","测试标题","测试内容");
System.out.println(res);
}
}