|
|
@@ -5,19 +5,19 @@ import com.steerinfo.framework.service.impl.BaseServiceImpl;
|
|
|
import com.steerinfo.baseinfo.appverificationcode.model.AppVerificationCode;
|
|
|
import com.steerinfo.baseinfo.appverificationcode.mapper.AppVerificationCodeMapper;
|
|
|
import com.steerinfo.baseinfo.appverificationcode.service.IAppVerificationCodeService;
|
|
|
-import com.wellbole.sms.client.callback.InboundMessageFetchCallback;
|
|
|
-import com.wellbole.sms.client.callback.StatusReportMessageFetchCallback;
|
|
|
-import com.wellbole.sms.client.impl.HttpPostSmsClient;
|
|
|
-import com.wellbole.sms.client.impl.SmsFetcherImpl;
|
|
|
-import com.wellbole.sms.client.impl.SmsSenderImpl;
|
|
|
-import com.wellbole.sms.client.impl.StatusReportFetcherImpl;
|
|
|
-import com.wellbole.sms.client.message.InboundMessage;
|
|
|
-import com.wellbole.sms.client.message.OutboundMessage;
|
|
|
-import com.wellbole.sms.client.message.StatusReportMessage;
|
|
|
-import com.wellbole.sms.client.result.SmsFetchResult;
|
|
|
-import com.wellbole.sms.client.result.SmsSendResult;
|
|
|
-import com.wellbole.sms.client.service.SmsFetcherThreadService;
|
|
|
-import com.wellbole.sms.client.service.StatusReportFetcherThreadService;
|
|
|
+//import com.wellbole.sms.client.callback.InboundMessageFetchCallback;
|
|
|
+//import com.wellbole.sms.client.callback.StatusReportMessageFetchCallback;
|
|
|
+//import com.wellbole.sms.client.impl.HttpPostSmsClient;
|
|
|
+//import com.wellbole.sms.client.impl.SmsFetcherImpl;
|
|
|
+//import com.wellbole.sms.client.impl.SmsSenderImpl;
|
|
|
+//import com.wellbole.sms.client.impl.StatusReportFetcherImpl;
|
|
|
+//import com.wellbole.sms.client.message.InboundMessage;
|
|
|
+//import com.wellbole.sms.client.message.OutboundMessage;
|
|
|
+//import com.wellbole.sms.client.message.StatusReportMessage;
|
|
|
+//import com.wellbole.sms.client.result.SmsFetchResult;
|
|
|
+//import com.wellbole.sms.client.result.SmsSendResult;
|
|
|
+//import com.wellbole.sms.client.service.SmsFetcherThreadService;
|
|
|
+//import com.wellbole.sms.client.service.StatusReportFetcherThreadService;
|
|
|
import org.apache.log4j.LogManager;
|
|
|
import org.apache.log4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -54,168 +54,168 @@ public class AppVerificationCodeServiceImpl extends BaseServiceImpl<AppVerificat
|
|
|
|
|
|
@Override
|
|
|
public void sendInfo(String phoneNum) throws InterruptedException{
|
|
|
- Logger logger = LogManager.getLogger(AppVerificationCodeServiceImpl.class);
|
|
|
-
|
|
|
- /*********************************************
|
|
|
- * 构造基本发送数据客户端,短信发送器,短信接收器
|
|
|
- ********************************************/
|
|
|
- //构造基于HTTP POST方式的发送数据客户端
|
|
|
- //注入方式HttpPostSmsClient实现了SmsClient接口
|
|
|
- HttpPostSmsClient client = new HttpPostSmsClient();
|
|
|
- client.setServerUrl("http://10.99.200.19:10086/router");
|
|
|
- //f2e0d49b4f7c4735a0e3e3b9d173e5e4]
|
|
|
- //以前的
|
|
|
-// client.setAppKey("53e548b23a784379b6c30ec88b28c801");
|
|
|
-// client.setAppSecret("c339eaa1099449fba94751649f185f63");
|
|
|
- // 任学宏发我的
|
|
|
- client.setAppKey("dfaeca54542e4eb99e93973aa145e82b");
|
|
|
- client.setAppSecret("1c080c93037243618d5497611c21ccdb");
|
|
|
-
|
|
|
- //构造短信发送器(平台-》用户手机)
|
|
|
- //SmsSenderImpl smsSender = new SmsSenderImpl(client);
|
|
|
- //注入方式,SmsSenderImpl实现了SmsSender接口
|
|
|
- SmsSenderImpl smsSender = new SmsSenderImpl();
|
|
|
- smsSender.setClient(client);
|
|
|
-
|
|
|
- /*********************************************
|
|
|
- * 短信发送测试
|
|
|
- ********************************************/
|
|
|
- //构造下行短信(平台-》用户手机)
|
|
|
- OutboundMessage message = new OutboundMessage();
|
|
|
- message.setPhone(phoneNum);
|
|
|
- //开会通知,xxx在xxx召开xxx会议,请准时参加。
|
|
|
- //系统异常报告:xxx系统于xxx 发生故障,请及时处理。
|
|
|
- //message.setContent("系统异常报告:站群系统于2016-01-18 20:32:04 发生故障,请及时处理。");
|
|
|
- //message.setExtCode("");
|
|
|
-
|
|
|
- //随机生成六位数的密码
|
|
|
- Integer randNum = (int)(Math.random()* (999999)+1);
|
|
|
- String password = String.format("%06d",randNum);
|
|
|
- //查询出有多少与phoneNum匹配的号码
|
|
|
- AppVerificationCode modelTemp = appVerificationCodeMapper.selectByPhone(phoneNum);
|
|
|
-
|
|
|
- Calendar c = Calendar.getInstance();
|
|
|
- //如果电话号码已存在,只需更新新建时间、过期时间、标志位,
|
|
|
- if(appVerificationCodeMapper.selectByPhone(phoneNum) != null && modelTemp.getPhoneNo().equals(phoneNum)) {
|
|
|
- //验证码有效
|
|
|
- modelTemp.setValueFlag("1");
|
|
|
- //验证码发送时间
|
|
|
- modelTemp.setCreateTime(new Date());
|
|
|
- //过期时间:当前时间后三分钟
|
|
|
- //实例化
|
|
|
- c.add(Calendar.MINUTE, 3); //分钟+3
|
|
|
- modelTemp.setExpirationTime(c.getTime());
|
|
|
- //设置验证码
|
|
|
- modelTemp.setCode(password);
|
|
|
- appVerificationCodeMapper.updateByPrimaryKey(modelTemp);
|
|
|
- }else{ //未查到号码直接插入验证码匹配信息
|
|
|
- //生成ID
|
|
|
- AppVerificationCode model = new AppVerificationCode();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
- model.setInfoId(sdf.format(new Date()));
|
|
|
- //设置电话号码
|
|
|
- model.setPhoneNo(phoneNum);
|
|
|
- //设置验证码
|
|
|
- model.setCode(password);
|
|
|
- //验证码有效
|
|
|
- model.setValueFlag("1");
|
|
|
- //验证码发送时间
|
|
|
- model.setCreateTime(new Date());
|
|
|
- //过期时间:当前时间后三分钟
|
|
|
- c.add(Calendar.MINUTE, 3);
|
|
|
- model.setExpirationTime(c.getTime());
|
|
|
-
|
|
|
- appVerificationCodeMapper.insertSelective(model);
|
|
|
- }
|
|
|
-
|
|
|
- message.setContent("您的验证码是"+ password +"(3分钟之内有效),请不要把验证码泄露给其他人。如非本人操作,可不用理会");
|
|
|
- //以下是可选参数
|
|
|
- //默认不指定该参数,若指定,平台将返回该指定的msgid,若不指定,则由平台自动生成
|
|
|
- //message.setMsgid("用户指定的id");
|
|
|
- //设定发送时间,可指定未来的时间,表示延迟发送,若不指定,则默认立即发送。
|
|
|
- //message.setSendAt(new Date());
|
|
|
- //发送短信
|
|
|
- StatusReportFetcherThreadService statusService = new StatusReportFetcherThreadService();
|
|
|
- StatusReportFetcherImpl statusReportFetcher = new StatusReportFetcherImpl();
|
|
|
- statusReportFetcher.setClient(client);
|
|
|
- statusService.setStatusReportFetcher(statusReportFetcher);
|
|
|
- statusService.setPeriod(10);
|
|
|
- statusService.setStatusReportMessageFetchCallback(new StatusReportMessageFetchCallback(){
|
|
|
- @Override
|
|
|
- public void onFetch(StatusReportMessage msg) {
|
|
|
- logger.info("phone=" + msg.getPhone());
|
|
|
- logger.info("status="+msg.getStatusCode());
|
|
|
- }
|
|
|
- });
|
|
|
- statusService.start();
|
|
|
- for(int index =0 ;index < 1; index++){
|
|
|
- SmsSendResult sendResult = smsSender.send(message);
|
|
|
- if(sendResult != null){
|
|
|
- //statusService.AddToStatusReportQueue(sendResult.getMsgid());
|
|
|
- }
|
|
|
- //发送结果检查
|
|
|
- if(sendResult.hasError()){
|
|
|
- logger.info("发送失败,原因=" + sendResult.getErrorMessage());
|
|
|
- }else{
|
|
|
- //发送成功时,服务器端会生成一个36字节长度的唯一标示。
|
|
|
- logger.info("发送成功,服务器端返回的msgid=" +sendResult.getMsgid());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /*********************************************
|
|
|
- * 短信接收测试(由调用端调用接收接口进行接收,手动模式)
|
|
|
- ********************************************/
|
|
|
-
|
|
|
-
|
|
|
- //构造短信接收器(用户手机-》平台)
|
|
|
- //SmsFetcher smsFetcher = new SmsFetcherImpl(client);
|
|
|
- //注入方式,SmsFetcherImpl实现了SmsFetcher接口
|
|
|
- SmsFetcherImpl smsFetcher = new SmsFetcherImpl();
|
|
|
- smsFetcher.setClient(client);
|
|
|
- //获取上行短信,建议每间隔5秒以上获取一次,
|
|
|
- //太频繁会造成短信服务负载过大。
|
|
|
- String extCode = "";
|
|
|
- SmsFetchResult fetchResult = smsFetcher.fetch(extCode);
|
|
|
- if(fetchResult.hasError()){
|
|
|
- logger.info("获取上行短信失败,原因=" + fetchResult.getErrorMessage());
|
|
|
- }else if(fetchResult.hasData()){//有数据返回。
|
|
|
- for(InboundMessage inboundMessage : fetchResult.getInboundMessageList()){
|
|
|
- //msgid,平台自动生成的消息id
|
|
|
- logger.info("msgid=" + inboundMessage.getMsgid());
|
|
|
- //扩展代码,默认为空。
|
|
|
- logger.info("extcode=" + inboundMessage.getExtCode());
|
|
|
- //用户手机号码
|
|
|
- logger.info("phone=" + inboundMessage.getPhone());
|
|
|
- //用户发送的短信内容
|
|
|
- logger.info("content=" + inboundMessage.getContent());
|
|
|
- //平台接收上行短信时间
|
|
|
- logger.info("receiverAt=" + inboundMessage.getReceiveAt());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /*********************************************
|
|
|
- * 短信接收测试(内置线程自动获取方式,需要提供回调接口实现,自动模式)
|
|
|
- *******************************************
|
|
|
- //构造回调接口实现
|
|
|
-
|
|
|
- //上行短信(用户手机-》平台)回调接口实现
|
|
|
- InboundMessageFetchCallback callback = new InboundMessageCallbackTestImpl();
|
|
|
- //构造短息获取服务线程
|
|
|
- SmsFetcherThreadService fetcherService = new SmsFetcherThreadService();
|
|
|
- //注入接收器(服务线程定期调用接收器来获取平台的上行短信)
|
|
|
- fetcherService.setSmsFetcher(smsFetcher);
|
|
|
- //每隔10秒检查一次
|
|
|
- fetcherService.setPeriod(5);
|
|
|
- //设定回调接口
|
|
|
- fetcherService.setInboundMessageFetchCallback(callback);
|
|
|
- //开始服务
|
|
|
- fetcherService.start();
|
|
|
- //15分钟后停止服务
|
|
|
- Thread.sleep(1000);
|
|
|
- fetcherService.stop();
|
|
|
- statusService.stop();*/
|
|
|
+// Logger logger = LogManager.getLogger(AppVerificationCodeServiceImpl.class);
|
|
|
+//
|
|
|
+// /*********************************************
|
|
|
+// * 构造基本发送数据客户端,短信发送器,短信接收器
|
|
|
+// ********************************************/
|
|
|
+// //构造基于HTTP POST方式的发送数据客户端
|
|
|
+// //注入方式HttpPostSmsClient实现了SmsClient接口
|
|
|
+// HttpPostSmsClient client = new HttpPostSmsClient();
|
|
|
+// client.setServerUrl("http://10.99.200.19:10086/router");
|
|
|
+// //f2e0d49b4f7c4735a0e3e3b9d173e5e4]
|
|
|
+// //以前的
|
|
|
+//// client.setAppKey("53e548b23a784379b6c30ec88b28c801");
|
|
|
+//// client.setAppSecret("c339eaa1099449fba94751649f185f63");
|
|
|
+// // 任学宏发我的
|
|
|
+// client.setAppKey("dfaeca54542e4eb99e93973aa145e82b");
|
|
|
+// client.setAppSecret("1c080c93037243618d5497611c21ccdb");
|
|
|
+//
|
|
|
+// //构造短信发送器(平台-》用户手机)
|
|
|
+// //SmsSenderImpl smsSender = new SmsSenderImpl(client);
|
|
|
+// //注入方式,SmsSenderImpl实现了SmsSender接口
|
|
|
+// SmsSenderImpl smsSender = new SmsSenderImpl();
|
|
|
+// smsSender.setClient(client);
|
|
|
+//
|
|
|
+// /*********************************************
|
|
|
+// * 短信发送测试
|
|
|
+// ********************************************/
|
|
|
+// //构造下行短信(平台-》用户手机)
|
|
|
+// OutboundMessage message = new OutboundMessage();
|
|
|
+// message.setPhone(phoneNum);
|
|
|
+// //开会通知,xxx在xxx召开xxx会议,请准时参加。
|
|
|
+// //系统异常报告:xxx系统于xxx 发生故障,请及时处理。
|
|
|
+// //message.setContent("系统异常报告:站群系统于2016-01-18 20:32:04 发生故障,请及时处理。");
|
|
|
+// //message.setExtCode("");
|
|
|
+//
|
|
|
+// //随机生成六位数的密码
|
|
|
+// Integer randNum = (int)(Math.random()* (999999)+1);
|
|
|
+// String password = String.format("%06d",randNum);
|
|
|
+// //查询出有多少与phoneNum匹配的号码
|
|
|
+// AppVerificationCode modelTemp = appVerificationCodeMapper.selectByPhone(phoneNum);
|
|
|
+//
|
|
|
+// Calendar c = Calendar.getInstance();
|
|
|
+// //如果电话号码已存在,只需更新新建时间、过期时间、标志位,
|
|
|
+// if(appVerificationCodeMapper.selectByPhone(phoneNum) != null && modelTemp.getPhoneNo().equals(phoneNum)) {
|
|
|
+// //验证码有效
|
|
|
+// modelTemp.setValueFlag("1");
|
|
|
+// //验证码发送时间
|
|
|
+// modelTemp.setCreateTime(new Date());
|
|
|
+// //过期时间:当前时间后三分钟
|
|
|
+// //实例化
|
|
|
+// c.add(Calendar.MINUTE, 3); //分钟+3
|
|
|
+// modelTemp.setExpirationTime(c.getTime());
|
|
|
+// //设置验证码
|
|
|
+// modelTemp.setCode(password);
|
|
|
+// appVerificationCodeMapper.updateByPrimaryKey(modelTemp);
|
|
|
+// }else{ //未查到号码直接插入验证码匹配信息
|
|
|
+// //生成ID
|
|
|
+// AppVerificationCode model = new AppVerificationCode();
|
|
|
+// SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
+// model.setInfoId(sdf.format(new Date()));
|
|
|
+// //设置电话号码
|
|
|
+// model.setPhoneNo(phoneNum);
|
|
|
+// //设置验证码
|
|
|
+// model.setCode(password);
|
|
|
+// //验证码有效
|
|
|
+// model.setValueFlag("1");
|
|
|
+// //验证码发送时间
|
|
|
+// model.setCreateTime(new Date());
|
|
|
+// //过期时间:当前时间后三分钟
|
|
|
+// c.add(Calendar.MINUTE, 3);
|
|
|
+// model.setExpirationTime(c.getTime());
|
|
|
+//
|
|
|
+// appVerificationCodeMapper.insertSelective(model);
|
|
|
+// }
|
|
|
+//
|
|
|
+// message.setContent("您的验证码是"+ password +"(3分钟之内有效),请不要把验证码泄露给其他人。如非本人操作,可不用理会");
|
|
|
+// //以下是可选参数
|
|
|
+// //默认不指定该参数,若指定,平台将返回该指定的msgid,若不指定,则由平台自动生成
|
|
|
+// //message.setMsgid("用户指定的id");
|
|
|
+// //设定发送时间,可指定未来的时间,表示延迟发送,若不指定,则默认立即发送。
|
|
|
+// //message.setSendAt(new Date());
|
|
|
+// //发送短信
|
|
|
+// StatusReportFetcherThreadService statusService = new StatusReportFetcherThreadService();
|
|
|
+// StatusReportFetcherImpl statusReportFetcher = new StatusReportFetcherImpl();
|
|
|
+// statusReportFetcher.setClient(client);
|
|
|
+// statusService.setStatusReportFetcher(statusReportFetcher);
|
|
|
+// statusService.setPeriod(10);
|
|
|
+// statusService.setStatusReportMessageFetchCallback(new StatusReportMessageFetchCallback(){
|
|
|
+// @Override
|
|
|
+// public void onFetch(StatusReportMessage msg) {
|
|
|
+// logger.info("phone=" + msg.getPhone());
|
|
|
+// logger.info("status="+msg.getStatusCode());
|
|
|
+// }
|
|
|
+// });
|
|
|
+// statusService.start();
|
|
|
+// for(int index =0 ;index < 1; index++){
|
|
|
+// SmsSendResult sendResult = smsSender.send(message);
|
|
|
+// if(sendResult != null){
|
|
|
+// //statusService.AddToStatusReportQueue(sendResult.getMsgid());
|
|
|
+// }
|
|
|
+// //发送结果检查
|
|
|
+// if(sendResult.hasError()){
|
|
|
+// logger.info("发送失败,原因=" + sendResult.getErrorMessage());
|
|
|
+// }else{
|
|
|
+// //发送成功时,服务器端会生成一个36字节长度的唯一标示。
|
|
|
+// logger.info("发送成功,服务器端返回的msgid=" +sendResult.getMsgid());
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// /*********************************************
|
|
|
+// * 短信接收测试(由调用端调用接收接口进行接收,手动模式)
|
|
|
+// ********************************************/
|
|
|
+//
|
|
|
+//
|
|
|
+// //构造短信接收器(用户手机-》平台)
|
|
|
+// //SmsFetcher smsFetcher = new SmsFetcherImpl(client);
|
|
|
+// //注入方式,SmsFetcherImpl实现了SmsFetcher接口
|
|
|
+// SmsFetcherImpl smsFetcher = new SmsFetcherImpl();
|
|
|
+// smsFetcher.setClient(client);
|
|
|
+// //获取上行短信,建议每间隔5秒以上获取一次,
|
|
|
+// //太频繁会造成短信服务负载过大。
|
|
|
+// String extCode = "";
|
|
|
+// SmsFetchResult fetchResult = smsFetcher.fetch(extCode);
|
|
|
+// if(fetchResult.hasError()){
|
|
|
+// logger.info("获取上行短信失败,原因=" + fetchResult.getErrorMessage());
|
|
|
+// }else if(fetchResult.hasData()){//有数据返回。
|
|
|
+// for(InboundMessage inboundMessage : fetchResult.getInboundMessageList()){
|
|
|
+// //msgid,平台自动生成的消息id
|
|
|
+// logger.info("msgid=" + inboundMessage.getMsgid());
|
|
|
+// //扩展代码,默认为空。
|
|
|
+// logger.info("extcode=" + inboundMessage.getExtCode());
|
|
|
+// //用户手机号码
|
|
|
+// logger.info("phone=" + inboundMessage.getPhone());
|
|
|
+// //用户发送的短信内容
|
|
|
+// logger.info("content=" + inboundMessage.getContent());
|
|
|
+// //平台接收上行短信时间
|
|
|
+// logger.info("receiverAt=" + inboundMessage.getReceiveAt());
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// /*********************************************
|
|
|
+// * 短信接收测试(内置线程自动获取方式,需要提供回调接口实现,自动模式)
|
|
|
+// *******************************************
|
|
|
+// //构造回调接口实现
|
|
|
+//
|
|
|
+// //上行短信(用户手机-》平台)回调接口实现
|
|
|
+// InboundMessageFetchCallback callback = new InboundMessageCallbackTestImpl();
|
|
|
+// //构造短息获取服务线程
|
|
|
+// SmsFetcherThreadService fetcherService = new SmsFetcherThreadService();
|
|
|
+// //注入接收器(服务线程定期调用接收器来获取平台的上行短信)
|
|
|
+// fetcherService.setSmsFetcher(smsFetcher);
|
|
|
+// //每隔10秒检查一次
|
|
|
+// fetcherService.setPeriod(5);
|
|
|
+// //设定回调接口
|
|
|
+// fetcherService.setInboundMessageFetchCallback(callback);
|
|
|
+// //开始服务
|
|
|
+// fetcherService.start();
|
|
|
+// //15分钟后停止服务
|
|
|
+// Thread.sleep(1000);
|
|
|
+// fetcherService.stop();
|
|
|
+// statusService.stop();*/
|
|
|
}
|
|
|
}
|