package com.rjnetwork.software.dev.crsd.util;
import java.io.IOException;
import java.util.Date;
import com.alibaba.fastjson.JSONException;
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;
import com.xiaoleilu.hutool.date.DateUtil;
import com.xiaoleilu.hutool.json.JSONObject;
import com.xiaoleilu.hutool.json.JSONUtil;
import com.xiaoleilu.hutool.util.RandomUtil;
public class TencentCloudSmsUtil {
/**appid**/
public static final Integer appid = new Integer(140009*****);
/**appkey**/
public static final String appkey = new String("d0e864b34326bfb4155d421f6ea1c476");
/** 短信模板ID,需要在短信应用中申请**/
public static final Integer templateId = new Integer(129784);
/** 签名**/
/**发送短信**/
public static JSONObject sendSms(String phone) {
JSONObject jsonObject = JSONUtil.createObj();//{"result":0,"errmsg":"OK","ext":"","sid":"8:QDWcB3amfNukSewXgyR20180530","fee":1}
try {
date = new Date();//返回时间计算 返回时间是毫秒
} catch (HTTPException e) {
} catch (JSONException e) {
jsonObject.put("phone", phone);
jsonObject.put("state", "failed");
jsonObject.put("errmsg", "json格式化错误:"+e);
} catch (IOException e) {
jsonObject.put("phone", phone);
jsonObject.put("state", "failed");
jsonObject.put("errmsg", "网络连接错误:"+e);
}
return jsonObject;
}
public static void main(String[] args) {
System.out.println(TencentCloudSmsUtil.sendSms("135****2695"));
}
import java.io.IOException;
import java.util.Date;
import com.alibaba.fastjson.JSONException;
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;
import com.xiaoleilu.hutool.date.DateUtil;
import com.xiaoleilu.hutool.json.JSONObject;
import com.xiaoleilu.hutool.json.JSONUtil;
import com.xiaoleilu.hutool.util.RandomUtil;
public class TencentCloudSmsUtil {
/**appid**/
public static final Integer appid = new Integer(140009*****);
/**appkey**/
public static final String appkey = new String("d0e864b34326bfb4155d421f6ea1c476");
/** 短信模板ID,需要在短信应用中申请**/
public static final Integer templateId = new Integer(129784);
/** 签名**/
/**发送短信**/
public static JSONObject sendSms(String phone) {
JSONObject jsonObject = JSONUtil.createObj();//{"result":0,"errmsg":"OK","ext":"","sid":"8:QDWcB3amfNukSewXgyR20180530","fee":1}
try {
date = new Date();//返回时间计算 返回时间是毫秒
} catch (HTTPException e) {
} catch (JSONException e) {
jsonObject.put("phone", phone);
jsonObject.put("state", "failed");
jsonObject.put("errmsg", "json格式化错误:"+e);
} catch (IOException e) {
jsonObject.put("phone", phone);
jsonObject.put("state", "failed");
jsonObject.put("errmsg", "网络连接错误:"+e);
}
return jsonObject;
}
public static void main(String[] args) {
System.out.println(TencentCloudSmsUtil.sendSms("135****2695"));
}
}
更多精彩内容 可以加qq群 进行交流哦!
QQ群:566421339
微信公众号:仁杰网络工作室
微信号:XHKJ_IT
文章来源: 腾讯短信API对接实现代码