package com.xzx.gc.common.utils.sms;
|
|
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.http.ContentType;
|
import cn.hutool.http.HttpException;
|
import cn.hutool.http.HttpRequest;
|
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONUtil;
|
import com.google.gson.Gson;
|
import lombok.extern.slf4j.Slf4j;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @Description: 相关工具类
|
* @author: wei
|
* @date: 2019-04-16 22:08
|
*/
|
@Slf4j
|
public class MixSmsUtil {
|
|
|
private static final String USER_NAME="xzx888hy";
|
//营销类账户
|
private static final String YX_USER_NAME="xzx888yx";
|
private static final String PWD="TRBiquIn65pO0tkY";
|
public static String SEND_SMS_TP_URL = "http://api.mix2.zthysms.com/v2/sendSmsTp";
|
public static String SEND_SMS_URL = "http://api.mix2.zthysms.com/v2/sendSms";
|
public static String sign="【小棕熊到家】";
|
|
|
/**
|
* 单点群发
|
* @return
|
*/
|
public static String sendSmsPoint(String mobile,String content){
|
String tKye = String.valueOf(DateUtil.currentSeconds());
|
SendSmsRequestInfo sendSmsTpRequestInfo = new SendSmsRequestInfo();
|
sendSmsTpRequestInfo.setUsername( USER_NAME );
|
String pwd = SecureUtil.md5( SecureUtil.md5( PWD ) + tKye );
|
sendSmsTpRequestInfo.setPassword( pwd );
|
sendSmsTpRequestInfo.setMobile(mobile);
|
sendSmsTpRequestInfo.setContent(content);
|
sendSmsTpRequestInfo.setTKey( tKye );
|
String json = new Gson().toJson( sendSmsTpRequestInfo);
|
|
String result;
|
try {
|
result = HttpRequest.post( SEND_SMS_URL )
|
.timeout( 30000 )
|
.body( json, ContentType.JSON.toString() )
|
.execute()
|
.body();
|
} catch (HttpException e) {
|
result= getErrResult(e.getMessage());
|
}
|
|
return result;
|
}
|
|
/**
|
* 模板发送
|
* @param mobile
|
* @param map
|
* @param templateCode
|
* @param type 1:通知类 2营销类
|
* @return
|
*/
|
public static String sendSms(String mobile,Map<String,String> map, String templateCode,int type) {
|
String tKye = String.valueOf(DateUtil.currentSeconds());
|
SendSmsTpRequestInfo sendSmsTpRequestInfo = new SendSmsTpRequestInfo();
|
if(type==1) {
|
sendSmsTpRequestInfo.setUsername(USER_NAME);
|
}else{
|
sendSmsTpRequestInfo.setUsername(YX_USER_NAME);
|
}
|
String pwd = SecureUtil.md5( SecureUtil.md5( PWD ) + tKye );
|
sendSmsTpRequestInfo.setPassword( pwd );
|
sendSmsTpRequestInfo.setTKey( tKye );
|
sendSmsTpRequestInfo.setTpId( templateCode );
|
sendSmsTpRequestInfo.setSignature( sign );
|
|
List<ContentTp> records = new ArrayList<>();
|
|
for (int i = 0; i < 1; i++) {
|
ContentTp contentTp = new ContentTp();
|
contentTp.setMobile(mobile);
|
contentTp.setTpContent( map );
|
records.add( contentTp );
|
}
|
|
sendSmsTpRequestInfo.setRecords( records );
|
String json = new Gson().toJson( sendSmsTpRequestInfo);
|
|
String result;
|
try {
|
result = HttpRequest.post( SEND_SMS_TP_URL )
|
.timeout( 30000 )
|
.body( json, ContentType.JSON.toString() )
|
.execute()
|
.body();
|
} catch (HttpException e) {
|
result= getErrResult(e.getMessage());
|
}
|
|
return result;
|
}
|
|
|
/**
|
*
|
* @return
|
*/
|
private static String getErrResult(String msg){
|
JSONObject jsonObject=new JSONObject();
|
jsonObject.put("code",-1);
|
jsonObject.put("msg",msg);
|
return JSONUtil.toJsonStr(jsonObject);
|
}
|
}
|