腾讯短信API对接实现代码

匿名 (未验证) 提交于 2019-12-03 00:26:01
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"));
}

}



更多精彩内容 可以加qq群 进行交流哦!

QQ群:566421339

微信公众号:仁杰网络工作室

微信号:XHKJ_IT

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!