2 changed files with 65 additions and 1 deletions
@ -0,0 +1,59 @@ |
|||
package com.wmeimob.bjyy.util; |
|||
|
|||
import cn.hutool.core.util.RandomUtil; |
|||
import cn.hutool.json.JSONException; |
|||
import com.github.qcloudsms.SmsSingleSender; |
|||
import com.github.qcloudsms.SmsSingleSenderResult; |
|||
import com.github.qcloudsms.httpclient.HTTPException; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.io.IOException; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
public class SmsTxUtil { |
|||
// 1400开头
|
|||
private static final int appid = 1400188778; |
|||
private static final String appkey = "c86ca104521ab2e28e1d4b558fdd665e"; |
|||
/** |
|||
* {1} 验证码{1}, 您正在通过{2}登录传控科技“时物链条”会议管理系统,请与{3}分钟内填写,如非本人操作,请忽略本短信。\ |
|||
*/ |
|||
private static final int templateId = 286731; |
|||
/** |
|||
* {1} 您正在通过{2}登录传控科技“时物链条”会议管理系统,请与{2}分钟内填写,如非本人操作,请忽略本短信。 |
|||
*/ |
|||
private static final int templateId1 = 286682; |
|||
/**验证码{1},{2}分钟内有效,如非本人操作请忽略 |
|||
* |
|||
*/ |
|||
private static final int templateId2 = 686476; |
|||
private static final String smsSign = "燕园睿耋"; |
|||
|
|||
public static void sendSms(String phone,String code, Integer seconds){ |
|||
String phoneNumbers[] = {phone}; |
|||
Integer minutes = (seconds - 1) / 60 + 1; |
|||
try { |
|||
//数组具体的元素个数和模板中变量个数必须一致,例如事例中templateId:5678对应一个变量,参数数组中元素个数也必须是一个
|
|||
String[] params = {code,String.valueOf(minutes)}; |
|||
SmsSingleSender ssender = new SmsSingleSender(appid, appkey); |
|||
// 签名参数未提供或者为空时,会使用默认签名发送短信
|
|||
SmsSingleSenderResult result = ssender.sendWithParam("86", phoneNumbers[0], |
|||
templateId2, params, smsSign, "", ""); |
|||
log.info(String.valueOf(result)); |
|||
} catch (HTTPException e) { |
|||
// HTTP响应码错误
|
|||
e.printStackTrace(); |
|||
} catch (JSONException e) { |
|||
// json解析错误
|
|||
e.printStackTrace(); |
|||
} catch (IOException e) { |
|||
// 网络IO错误
|
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
public static String generateRandomSmsCode(int length){ |
|||
return RandomUtil.randomNumbers(4); |
|||
} |
|||
} |
Loading…
Reference in new issue