验证码
This commit is contained in:
@ -2,13 +2,11 @@ package com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.controller;
|
|||||||
|
|
||||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||||
import com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.entity.BizSendMsgInfoVO;
|
import com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.entity.BizSendMsgInfoVO;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.entity.InterestOutcome;
|
||||||
import com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.service.BizSendMsgTemplateService;
|
import com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.service.BizSendMsgTemplateService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -27,4 +25,16 @@ public class BizSendMsgController {
|
|||||||
return BaseResponse.success(sendMsgService.sendMsg(msgInfo));
|
return BaseResponse.success(sendMsgService.sendMsg(msgInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("代理机构转出利息发送校验码")
|
||||||
|
@PostMapping("/interest/code")
|
||||||
|
public BaseResponse<Boolean> interestOutcomSendMsg(@RequestBody InterestOutcome interestOutcome) {
|
||||||
|
return BaseResponse.success(sendMsgService.interestOutcomSendMsg(interestOutcome));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("代理机构转出利息发送校验码")
|
||||||
|
@GetMapping("/interest/getcode")
|
||||||
|
public BaseResponse<InterestOutcome> getinterestOutcomSendMsg(String subAcctNum) {
|
||||||
|
return BaseResponse.success(sendMsgService.getinterestOutcomSendMsg(subAcctNum));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,134 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.chinaunicom.mall.ebtp.common.base.entity.BaseEntity;
|
||||||
|
import com.chinaunicom.mall.ebtp.common.config.CustomLocalDateTimeTypeHandler;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实体类 InterestOutcome
|
||||||
|
*
|
||||||
|
* @author yinxue
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@ApiModel(value = "InterestOutcome对象", description = "代理机构转出利息发送校验码接口对象")
|
||||||
|
public class InterestOutcome{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "ID")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验码
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "校验码")
|
||||||
|
private String checkCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 联系电话
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "联系电话")
|
||||||
|
private String contactPhone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 银行-客户流水号:用于查交易状态
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "银行-客户流水号:用于查交易状态")
|
||||||
|
private String clientId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分薄账号
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "分薄账号")
|
||||||
|
private String subAcctNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请人id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "申请人id")
|
||||||
|
private String applyerId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请人名称
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "申请人名称")
|
||||||
|
private String applyerName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT,typeHandler = CustomLocalDateTimeTypeHandler.class)
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@ApiModelProperty("申请时间")
|
||||||
|
private LocalDateTime applyTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请人机构id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "申请人机构id")
|
||||||
|
private String companyId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请人机构名称
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "申请人机构名称")
|
||||||
|
private String companyName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "状态")
|
||||||
|
private Integer state;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 交易类型
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "交易类型")
|
||||||
|
private Integer tradeType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 交易金额
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "交易金额")
|
||||||
|
private String txnAmt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收款账号名称
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "收款账号名称")
|
||||||
|
private String accountName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收款银行账号
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "收款银行账号")
|
||||||
|
private String cardNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收款银联号
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "收款银联号")
|
||||||
|
private String bankUnionNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "备注")
|
||||||
|
private String remark;
|
||||||
|
}
|
@ -4,6 +4,7 @@ package com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.service;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.entity.BizSendMsgInfoVO;
|
import com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.entity.BizSendMsgInfoVO;
|
||||||
import com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.entity.BizSendMsgTemplate;
|
import com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.entity.BizSendMsgTemplate;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.entity.InterestOutcome;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对数据表 biz_send_msg_template 操作的 service
|
* 对数据表 biz_send_msg_template 操作的 service
|
||||||
@ -14,4 +15,8 @@ public interface BizSendMsgTemplateService extends IService<BizSendMsgTemplate>
|
|||||||
|
|
||||||
Boolean sendMsg(BizSendMsgInfoVO msgInfo);
|
Boolean sendMsg(BizSendMsgInfoVO msgInfo);
|
||||||
|
|
||||||
|
Boolean interestOutcomSendMsg(InterestOutcome interestOutcome);
|
||||||
|
|
||||||
|
InterestOutcome getinterestOutcomSendMsg(String subAcctNum);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.service.impl;
|
package com.chinaunicom.mall.ebtp.extend.bizshortmessageemail.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
||||||
import com.chinaunicom.mall.ebtp.common.base.service.IBaseCacheUserService;
|
import com.chinaunicom.mall.ebtp.common.base.service.IBaseCacheUserService;
|
||||||
import com.chinaunicom.mall.ebtp.common.util.JsonUtils;
|
import com.chinaunicom.mall.ebtp.common.util.JsonUtils;
|
||||||
import com.chinaunicom.mall.ebtp.common.util.PropertyUtils;
|
import com.chinaunicom.mall.ebtp.common.util.PropertyUtils;
|
||||||
@ -18,13 +20,15 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Map;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对数据表 biz_send_msg_template 操作的 serviceImpl
|
* 对数据表 biz_send_msg_template 操作的 serviceImpl
|
||||||
@ -43,6 +47,8 @@ public class BizSendMsgTemplateServiceImpl extends ServiceImpl<BizSendMsgTemplat
|
|||||||
private BizSendMsgLogService msgLogService;
|
private BizSendMsgLogService msgLogService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private BizFuncSwitchConfigMapper funcSwitchConfigMapper;
|
private BizFuncSwitchConfigMapper funcSwitchConfigMapper;
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean sendMsg(BizSendMsgInfoVO msgInfoVO) {
|
public Boolean sendMsg(BizSendMsgInfoVO msgInfoVO) {
|
||||||
@ -96,6 +102,87 @@ public class BizSendMsgTemplateServiceImpl extends ServiceImpl<BizSendMsgTemplat
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean interestOutcomSendMsg(InterestOutcome interestOutcome) {
|
||||||
|
boolean result = false;
|
||||||
|
BaseCacheUser user = cacheUserService.getCacheUser();
|
||||||
|
String verifyCode = String.valueOf((int)(Math.random()*900000 + 100000));
|
||||||
|
interestOutcome.setCheckCode(verifyCode);
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
||||||
|
String nowTime = df.format(now);
|
||||||
|
//模板ID
|
||||||
|
String templateId = "interest_outcome_msg";
|
||||||
|
QueryWrapper<BizSendMsgTemplate> query = new QueryWrapper<>(new BizSendMsgTemplate().setTemplateId(templateId));
|
||||||
|
//获得短信模板信息
|
||||||
|
BizSendMsgTemplate msgTemplate = this.getOne(query);
|
||||||
|
//替换模板参数:【联通招标采购中心】您的账号;{subAcctNum}正在申请转出金额:{txnAmt}元,收款账号名称:{accountName}收款银行账号:{cardNumber},短信验证码:{checkCode},验证码的有效期:5分钟,切勿将验证码泄露于他人。发送时间:{sendTime}
|
||||||
|
Map<String, String> tempParamMap = new HashMap<>();
|
||||||
|
tempParamMap.put("subAcctNum",interestOutcome.getSubAcctNum());
|
||||||
|
tempParamMap.put("txnAmt",interestOutcome.getTxnAmt());
|
||||||
|
tempParamMap.put("accountName",interestOutcome.getAccountName());
|
||||||
|
tempParamMap.put("cardNumber",interestOutcome.getCardNumber());
|
||||||
|
tempParamMap.put("checkCode",verifyCode);
|
||||||
|
tempParamMap.put("sendTime",nowTime);
|
||||||
|
//替换字段,形成需要发送的短信内容
|
||||||
|
String magContent = generateMsgFromTemplete(msgTemplate.getContent(), tempParamMap);
|
||||||
|
//当前用户userId
|
||||||
|
String userId = user.getUserId();//"ex-wanghy623";
|
||||||
|
String userName = user.getFullName();//"曹鹏";
|
||||||
|
BizSendMsgVO msgVO = new BizSendMsgVO();
|
||||||
|
msgVO.setSendUid(userId)
|
||||||
|
.setSendUName(userName)
|
||||||
|
.setStrMobileNumberr(interestOutcome.getContactPhone())
|
||||||
|
.setStrContent(magContent);
|
||||||
|
|
||||||
|
//判断当前资金分簿是否已经发送过校验码
|
||||||
|
Object tokenValue = redisTemplate.opsForValue().get("subAcctNum:" + interestOutcome.getSubAcctNum());
|
||||||
|
if (tokenValue != null) {
|
||||||
|
redisTemplate.delete("subAcctNum:" + interestOutcome.getSubAcctNum());
|
||||||
|
}
|
||||||
|
redisTemplate.opsForValue().set("subAcctNum:" + interestOutcome.getSubAcctNum(), JSON.toJSONString(interestOutcome), 5, TimeUnit.MINUTES);
|
||||||
|
//active使能(1:是;0:否)
|
||||||
|
int active =funcSwitchConfigMapper.selectByType("send-sms-func");
|
||||||
|
//发送状态;0-失败;1-成功;2-短信功能未开启
|
||||||
|
int sendResult = 2;
|
||||||
|
if (active==1) {
|
||||||
|
//发送短信
|
||||||
|
result = msgService.sendMsg(msgVO);
|
||||||
|
sendResult = result?1:0;
|
||||||
|
}
|
||||||
|
//保存日志
|
||||||
|
BizSendMsgLog msgLog = new BizSendMsgLog();
|
||||||
|
String id = PropertyUtils.getSnowflakeId();
|
||||||
|
msgLog.setId(id)
|
||||||
|
.setType("sms")
|
||||||
|
.setTemplateId(templateId)
|
||||||
|
.setSendContent(magContent)
|
||||||
|
.setReceiverCompanyId(user.getOrganizationId())
|
||||||
|
.setReceiverCompanyName(interestOutcome.getAccountName())
|
||||||
|
.setReceiverAccount(interestOutcome.getContactPhone())
|
||||||
|
.setStatus(sendResult)//发送状态;0-失败;1-成功;2-短信功能未开启
|
||||||
|
.setSendTime(now)
|
||||||
|
.setSenderUserId(userId)
|
||||||
|
.setSenderUserName(userName);
|
||||||
|
log.info("sendMsgLog传入数据:"+ JsonUtils.objectToJson(msgLog));
|
||||||
|
//active使能(1:是;0:否)
|
||||||
|
int logactive =funcSwitchConfigMapper.selectByType("send-sms-record-log");
|
||||||
|
if (logactive==1) {
|
||||||
|
msgLogService.save(msgLog);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InterestOutcome getinterestOutcomSendMsg(String subAcctNum) {
|
||||||
|
Object tokenValue = redisTemplate.opsForValue().get("subAcctNum:" + subAcctNum);
|
||||||
|
if (tokenValue != null) {
|
||||||
|
return JSON.parseObject(tokenValue.toString(), InterestOutcome.class);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送短信
|
* 发送短信
|
||||||
* @param msgInfo
|
* @param msgInfo
|
||||||
|
Reference in New Issue
Block a user