Commit bc08adc3 by duanhq

短信发送 by duanht 2019/3/7

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@18254 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 47bea2f6
......@@ -40,4 +40,14 @@ public class Constants {
* 短信url的key
*/
public static final String SMS_SERVER_URL_KEY = "sms.url";
/**
* 注册成功发送source
*/
public static final String SMS_REGISTER_SOURCE ="sms.register.source" ;
/**
* 验证码短信source
*/
public static final String SMS_VERIFY_CODE = "sms.verify.code";
}
......@@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletRequest;
import com.alibaba.fastjson.JSONObject;
import com.glsx.common.utils.HttpUtils;
import com.glsx.publicservice.constants.Constants;
import com.glsx.publicservice.util.PropertiesUtil;
import com.glsx.publicservice.util.RedisCacheUtil;
import com.glsx.publicservice.util.SmsUtil;
import org.apache.commons.lang.StringUtils;
......@@ -113,7 +114,7 @@ public class CommonController {
SmsUtil smsUtil = new SmsUtil();
try {
String msgContent = MessageFormat.format("{0},您的包活干技工注册申请已通过。请打开微信小程序登陆,默认密码为{1}【包活干汽车服务共享平台】",name, phone);
smsUtil.send(phone, msgContent);
smsUtil.send(phone, msgContent, PropertiesUtil.getProperty(Constants.SMS_REGISTER_SOURCE));
}catch (Exception e) {
logger.error(phone+"技工注册成功发送短信失败" + e.getMessage(), e);
return new ResultObject(ResultCodeEnum.ERROR.getCode(), ResultCodeEnum.ERROR.getMsg());
......
......@@ -4,6 +4,7 @@ import java.text.MessageFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import com.glsx.publicservice.util.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -58,7 +59,8 @@ public class CommonServiceImpl implements CommonService {
smsLogDao.saveSMSLog(smsLog);
String result = "发送手机号phone=" + phone + ">>>smsCode=" + smsCode;
logger.info(result);
smsUtil.send(phone, msgContent);
String source = PropertiesUtil.getProperty(Constants.SMS_VERIFY_CODE);
smsUtil.send(phone, msgContent,source);
return smsCode;
}
......
......@@ -26,7 +26,7 @@ public class SmsUtil {
* @param phone
* @param msgContent
*/
public void send(String phone, String msgContent) {
public void send(String phone, String msgContent,String source) {
TreeMap<String, String> treeMap = new TreeMap<String, String>();
treeMap.put("method", "glsx.message.sendmessage");
......@@ -36,7 +36,7 @@ public class SmsUtil {
treeMap.put("channel", "1001");
treeMap.put("lock", "2AC16F3AB37C129E273A4979FD0A46B0");
String source = "frms_sms_assign";
// String source = "frms_sms_assign";
treeMap.put("source", source);
treeMap.put("type", "1");
treeMap.put("phone", phone);
......@@ -89,61 +89,61 @@ public class SmsUtil {
}
}
/**
* 短信派单(营销短信)
*
* @param phone
* @param msgContent
* @param source
*/
public void send(String phone, String msgContent, String source) {
TreeMap<String, String> treeMap = new TreeMap<String, String>();
treeMap.put("method", "glsx.message.sendmessage");
treeMap.put("format", "json");
treeMap.put("akey", "9c991f5abac812b7a2739beecde2fdc7");
treeMap.put("v", "1.0.0");
treeMap.put("channel", "1001");
treeMap.put("lock", "2AC16F3AB37C129E273A4979FD0A46B0");
treeMap.put("source", source);
treeMap.put("type", "1");
treeMap.put("phone", phone);
treeMap.put("content", msgContent);
treeMap.put("subcode", "");
logger.info("Send Sms:" + treeMap.toString());
// String url = "http://192.168.3.206:8118/router";//开发
// String url = "http://qcdidicb.glsx.net:7060/router";//测试(貌似已经废弃了)
String url = "http://qcapp.oss.glsx.net:7060/gop-message/router";//测试
HttpUtils httpUtils = new HttpUtils();
try {
String res = httpUtils.get(url, treeMap);
logger.info("Result:" + res);
JSONObject jsonObject = JSONObject.parseObject(res);
String code = jsonObject.getString("code");
if (!code.equals("0")) {
res = httpUtils.get(url, treeMap);
logger.info("Failure resend result:" + res);
}
} catch (Exception ex) {
logger.error("SendSmsException", ex);
try {
String res1 = httpUtils.get(url, treeMap);
logger.info("Exception resend result:" + res1);
} catch (Exception e) {
logger.error("ReSendSmsException", ex);
}
}
}
// /**
// * 短信派单(营销短信)
// *
// * @param phone
// * @param msgContent
// * @param source
// */
// public void send(String phone, String msgContent, String source) {
//
// TreeMap<String, String> treeMap = new TreeMap<String, String>();
// treeMap.put("method", "glsx.message.sendmessage");
// treeMap.put("format", "json");
// treeMap.put("akey", "9c991f5abac812b7a2739beecde2fdc7");
// treeMap.put("v", "1.0.0");
// treeMap.put("channel", "1001");
// treeMap.put("lock", "2AC16F3AB37C129E273A4979FD0A46B0");
//
// treeMap.put("source", source);
// treeMap.put("type", "1");
// treeMap.put("phone", phone);
// treeMap.put("content", msgContent);
// treeMap.put("subcode", "");
//
// logger.info("Send Sms:" + treeMap.toString());
//
//// String url = "http://192.168.3.206:8118/router";//开发
//// String url = "http://qcdidicb.glsx.net:7060/router";//测试(貌似已经废弃了)
// String url = "http://qcapp.oss.glsx.net:7060/gop-message/router";//测试
//
// HttpUtils httpUtils = new HttpUtils();
// try {
// String res = httpUtils.get(url, treeMap);
// logger.info("Result:" + res);
//
// JSONObject jsonObject = JSONObject.parseObject(res);
// String code = jsonObject.getString("code");
// if (!code.equals("0")) {
// res = httpUtils.get(url, treeMap);
// logger.info("Failure resend result:" + res);
// }
// } catch (Exception ex) {
// logger.error("SendSmsException", ex);
// try {
// String res1 = httpUtils.get(url, treeMap);
// logger.info("Exception resend result:" + res1);
// } catch (Exception e) {
// logger.error("ReSendSmsException", ex);
// }
// }
// }
public static void main(String[] args) {
SmsUtil smsUtil = new SmsUtil();
String msgContent = MessageFormat.format("您本次操作验证码为:{0},一分钟内有效。","18508458837");
smsUtil.send("18508458837", msgContent);
// smsUtil.send("18508458837", msgContent);
}
}
......@@ -78,6 +78,10 @@ feign.client.config.default.loggerLevel=basic
sms.url=http://qcdidicb.glsx.net:7060/router
sms.source=frms_sms_assign
sms.register.source=outsourcing_apply_warn
sms.verify.code=outsourcing_verify_code
##fastdfs
fdfs.soTimeout=1500
fdfs.connectTimeout=600
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!