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