From 62e00afee9b9a912d5427d206ad9b57c3c8d56e2 Mon Sep 17 00:00:00 2001 From: jlzhangyx5 <1254353766@qq.com> Date: Fri, 25 Aug 2023 09:54:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E5=9B=A0=E7=B4=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 9 ++ .../service/ICrypConfigureService.java | 7 + .../impl/CrypConfigureServiceImpl.java | 96 +++++++++++- .../controller/BizShortMessageController.java | 141 ++++++++++++++++++ .../dao/BizShortMessageMapper.java | 11 ++ .../dao/mapper/BizShortMessageMapper.xml | 23 +++ .../shortmessage/entity/BizShortMessage.java | 78 ++++++++++ .../shortmessage/entity/SmsCheckRequest.java | 17 +++ .../shortmessage/entity/SmsSendRequest.java | 27 ++++ .../service/BizShortMessageService.java | 17 +++ .../impl/BizShortMessageServiceImpl.java | 129 ++++++++++++++++ .../extend/shortmessage/utils/SignUtil.java | 25 ++++ 12 files changed, 579 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/controller/BizShortMessageController.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/dao/BizShortMessageMapper.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/dao/mapper/BizShortMessageMapper.xml create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/entity/BizShortMessage.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/entity/SmsCheckRequest.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/entity/SmsSendRequest.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/service/BizShortMessageService.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/service/impl/BizShortMessageServiceImpl.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/utils/SignUtil.java diff --git a/pom.xml b/pom.xml index 08f9dd3..2ed65e7 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,15 @@ + + + com.cuca + cucasecuritysdk + 1.7 + + + + com.deepoove poi-tl diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/crypconfigure/service/ICrypConfigureService.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/crypconfigure/service/ICrypConfigureService.java index eca938c..4b21dd7 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/crypconfigure/service/ICrypConfigureService.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/crypconfigure/service/ICrypConfigureService.java @@ -27,6 +27,13 @@ public interface ICrypConfigureService extends IBaseService { * @return */ String callUniInterfaceJson(CrypBean bean); + + /** + * 调用天擎接口 + * @param bean + * @return true/false + */ + Boolean callUniInterfaceMessage(CrypBean bean); /** * 加载失败日志再发送 * @param diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/crypconfigure/service/impl/CrypConfigureServiceImpl.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/crypconfigure/service/impl/CrypConfigureServiceImpl.java index f8f52db..b1613be 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/crypconfigure/service/impl/CrypConfigureServiceImpl.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/crypconfigure/service/impl/CrypConfigureServiceImpl.java @@ -207,6 +207,76 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl map = JSONArray.parseObject(JSONArray.toJSONString(bean.getObject()), Map.class); + log.info("多因素map------callUniInterfaceMessage:---入参map-----" + JSON.toJSONString(map)); + + //传入数据解密 + String sign = getSignValue(map); + +// map.put("SIGN", sign); + + json = getUniBssMessage(bean.getReqName(), map); + + blockChainLog.setParam(json);//请求参数 + str = UniBssServiceImpl.uniBssHttpPost(bean.getUrl(), json); + blockChainLog.setResult(str);//返回参数 + UniBss uniBssRsp = JSONArray.parseObject(str, UniBss.class); + if (uniBssRsp != null && UniBssConstant.RESP_CODE_00000.equals(uniBssRsp.getUniBssHead().getRespCode())) { + System.out.println("返回接口:" + uniBssRsp); + + if (str != null && !"".equals(str) && str.indexOf("_RSP\":{\"Code\":200,") >= 0) { + blockChainLog.setStatus(0);//成功 + this.iBlockChainLogService.save(blockChainLog); + return true; + } else { + blockChainLog.setStatus(1);//失败 + } + } else { + blockChainLog.setStatus(1);//失败 + CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.assertStringNotNullByKey("天擎多因素接口调用错误," + + "RESP_CODE:" + uniBssRsp.getUniBssHead().getRespCode() + "" + + "(" + UniBssConstant.getRESP_CODE_Map(uniBssRsp.getUniBssHead().getRespCode()) + ")。" + + "RESP_DESC:" + uniBssRsp.getUniBssHead().getRespDesc(), bean); + } + } catch (Exception e) { + blockChainLog.setStatus(1); + blockChainLog.setResult(e.getMessage()); + + }finally { + if(blockChainLog.getStatus().equals(1)){ + log.error("多因素调用失败!~-----------------"); + operationLogService.addOperationLog("多因素同步失败信息,参数{}"+json+"返回信息{}"+str,false, EbtpLogBusinessModule.OTHER, EbtpLogType.INSERT); + } + } + + + return false; + } + /** * 加载失败日志再发送 * @@ -384,7 +454,7 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl map) { + + UniBss uniBss = new UniBss(); + uniBss.setUniBssAttached(new UniBssAttached().setMediaInf("")); + //天擎部分head + UniBssUtil util = new UniBssUtil(app_id, app_secret); + uniBss.setUniBssHead(util.getUniBssHead()); + + log.info("业务参数封装前:" + map); + Map reqMap = new HashMap(); + reqMap.put(reqName, map); + uniBss.setUniBssBodyMap(reqMap); + log.info("业务参数封装后:" + JSON.toJSONString(reqMap)); + log.info("业务参数封装后uniBss:" + JSON.toJSONString(uniBss)); + + return JSON.toJSONString(uniBss); + } /** * 中信天擎接口 数据格式 获取加密签名 * REQ:{ diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/controller/BizShortMessageController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/controller/BizShortMessageController.java new file mode 100644 index 0000000..71680d7 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/controller/BizShortMessageController.java @@ -0,0 +1,141 @@ +package com.chinaunicom.mall.ebtp.extend.shortmessage.controller; + + +import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse; +import com.chinaunicom.mall.ebtp.extend.shortmessage.entity.SmsSendRequest; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import javax.annotation.Resource; +import javax.validation.Valid; +import java.nio.charset.StandardCharsets; +import java.util.List; +import com.chinaunicom.mall.ebtp.extend.shortmessage.entity.BizShortMessage; +import com.chinaunicom.mall.ebtp.extend.shortmessage.service.BizShortMessageService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; + +@RestController +@Api(value = "多因素短信发送记录") +@RequestMapping("/v1/bizshortmessage") +public class BizShortMessageController{ + + @Resource + private BizShortMessageService iBizShortMessageService; + + /** + * 认证短信验证码发送 + * appCode 应用标识 + * bizSn 流水号 调用方生成 保持唯一 + * userAccount 应用系统账号 + * privateKey 调用方私钥 + * mobile 手机号 + * authCode 验证码 + * callbackUrl UrlEncode编码 应用系统回调确认用户有效性的地址,应用系统传了这个地址则用户有效性由该地址确定 + */ + @PostMapping("/send/authCode") + public BaseResponse authCodeSend(@RequestParam String mobile){ + return BaseResponse.success(iBizShortMessageService.authCodeSend(mobile)); + } + + /** + * 认证短信验证码发送 + * appCode 应用标识 + * bizSn 流水号 调用方生成 保持唯一 + * userAccount 应用系统账号 + * privateKey 调用方私钥 + * mobile 手机号 + * authCode 验证码 + * callbackUrl UrlEncode编码 应用系统回调确认用户有效性的地址,应用系统传了这个地址则用户有效性由该地址确定 + */ + @PostMapping("/check/authCode") + public BaseResponse authCodeCheck(@RequestParam String mobile, + @RequestParam String authCode){ + return BaseResponse.success(iBizShortMessageService.authCodeCheck(mobile, authCode)); + } + + /** + * 插入新数据 + * + * @param bizShortMessage + * + * @return + */ + @ApiOperation("插入新数据") + @PostMapping + public BaseResponse insert(@ApiParam(value = "对象数据", required = true) @RequestBody @Valid BizShortMessage bizShortMessage){ + + Boolean i = iBizShortMessageService.save(bizShortMessage); + + return BaseResponse.success(i); + } + + /** + * 修改数据 + * + * @param bizShortMessage + * + * @return + */ + @ApiOperation("修改数据") + @PutMapping + public BaseResponse update(@ApiParam(value = "对象数据", required = true) @RequestBody BizShortMessage bizShortMessage){ + + Boolean i = iBizShortMessageService.updateById(bizShortMessage); + + return BaseResponse.success(i); + } + + /** + * 查询数据 + * + * @param id + * + * @return + */ + @ApiOperation("根据id查询数据") + @GetMapping("/{id}") + public BaseResponse get(@ApiParam(value = "主键id", required = true) @PathVariable String id){ + + BizShortMessage bizShortMessage = iBizShortMessageService.getById(id); + + return BaseResponse.success(bizShortMessage); + } + + /** + * 删除数据 + * @param id 主键id + * @return BaseResponse + * @author dino + * @date 2020/10/21 14:56 + */ + @ApiOperation(value = "delete",notes = "删除数据") + @DeleteMapping("/{id}") + public BaseResponse delete(@ApiParam(value = "主键id", required = true) @PathVariable Long id) { + Boolean i = iBizShortMessageService.removeById(id); + return BaseResponse.success(i); + } + + /** + * 查询数据 + * + * @param param + * @return + */ + @ApiOperation("查询列表数据") + @GetMapping("/list") + public BaseResponse> list(@ApiParam(value = "查询对象数据", required = false) BizShortMessage param) { + //查询 + LambdaQueryWrapper query = Wrappers.lambdaQuery(param); + List list = iBizShortMessageService.list(query); + //异常处理 + //RespsExceptionEnum.FRAME_EXCEPTION_DEMO_NOT_FIND.customValid(list.isEmpty()); + return BaseResponse.success(list); + } +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/dao/BizShortMessageMapper.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/dao/BizShortMessageMapper.java new file mode 100644 index 0000000..588e900 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/dao/BizShortMessageMapper.java @@ -0,0 +1,11 @@ +package com.chinaunicom.mall.ebtp.extend.shortmessage.dao; + + +import com.chinaunicom.mall.ebtp.common.base.dao.IBaseMapper; +import java.util.List; +import org.springframework.stereotype.Repository; +import com.chinaunicom.mall.ebtp.extend.shortmessage.entity.BizShortMessage; + +@Repository +public interface BizShortMessageMapper extends IBaseMapper { +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/dao/mapper/BizShortMessageMapper.xml b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/dao/mapper/BizShortMessageMapper.xml new file mode 100644 index 0000000..a3cbf69 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/dao/mapper/BizShortMessageMapper.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/entity/BizShortMessage.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/entity/BizShortMessage.java new file mode 100644 index 0000000..81717af --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/entity/BizShortMessage.java @@ -0,0 +1,78 @@ +package com.chinaunicom.mall.ebtp.extend.shortmessage.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.chinaunicom.mall.ebtp.common.base.entity.BaseEntity; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** +* 实体类 BizShortMessage-多因素短信发送记录 +* +* @author yss +*/ +@Data +@Accessors(chain = true) +@TableName(value = "biz_short_message", autoResultMap = true) +@ApiModel(value = "BizShortMessage对象", description = "多因素短信发送记录") +public class BizShortMessage implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId + @ApiModelProperty(value = "主键ID") + private String id; + + @ApiModelProperty(value = "应用在多因素系统内注册的唯一标识") + private String appcode; + + @ApiModelProperty(value = "业务流水号") + private String bizsn; + + @ApiModelProperty(value = "接收人手机号") + private String mobile; + + @ApiModelProperty(value = "手机号") + private String callbackurl; + + @ApiModelProperty(value = "发送状态;0-发送中;1-发送成功;2-发送失败;3-校验中;4-校验成功;5-校验失败") + private Integer status; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "发送时间") + private LocalDateTime sendTime; + + @ApiModelProperty(value = "模板ID") + private String templateCode; + + @ApiModelProperty(value = "类型sms-短信") + private String type; + + @ApiModelProperty(value = "发送内容") + private String sendContent; + + @ApiModelProperty(value = "备用字段1") + private String attribute1; + + @ApiModelProperty(value = "备用字段2") + private String attribute2; + + @ApiModelProperty(value = "备用字段3") + private String attribute3; + + @ApiModelProperty(value = "备用字段4") + private String attribute4; + + @ApiModelProperty(value = "备用字段5") + private String attribute5; + + +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/entity/SmsCheckRequest.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/entity/SmsCheckRequest.java new file mode 100644 index 0000000..a51e054 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/entity/SmsCheckRequest.java @@ -0,0 +1,17 @@ +package com.chinaunicom.mall.ebtp.extend.shortmessage.entity; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class SmsCheckRequest extends BaseVo { + /** + * 手机号 + */ + private String mobile; + /** + * 验证码 + */ + private String authCode; +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/entity/SmsSendRequest.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/entity/SmsSendRequest.java new file mode 100644 index 0000000..bcd9d42 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/entity/SmsSendRequest.java @@ -0,0 +1,27 @@ +package com.chinaunicom.mall.ebtp.extend.shortmessage.entity; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class SmsSendRequest extends BaseVo { + /** + * 手机号 + */ + private String mobile; + /** + * 应用系统账号 + */ + private String userAccount; + /** + * 验证码 + */ + private String authCode; + + /** + * UrlEncode编码 + * 应用系统回调确认用户有效性的地址,应用系统传了这个地址则用户有效性由该地址确定 + */ + private String callBackUrl; +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/service/BizShortMessageService.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/service/BizShortMessageService.java new file mode 100644 index 0000000..9e47ef4 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/service/BizShortMessageService.java @@ -0,0 +1,17 @@ +package com.chinaunicom.mall.ebtp.extend.shortmessage.service; + + +import com.chinaunicom.mall.ebtp.common.base.service.IBaseService; +import com.chinaunicom.mall.ebtp.extend.shortmessage.entity.BizShortMessage; + +/** + * 对数据表 biz_short_message 操作的 service + * @author yss + * + */ +public interface BizShortMessageService extends IBaseService{ + + Boolean authCodeSend(String mobile); + + Boolean authCodeCheck(String mobile, String authCode); +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/service/impl/BizShortMessageServiceImpl.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/service/impl/BizShortMessageServiceImpl.java new file mode 100644 index 0000000..afc8f7d --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/service/impl/BizShortMessageServiceImpl.java @@ -0,0 +1,129 @@ +package com.chinaunicom.mall.ebtp.extend.shortmessage.service.impl; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.chinaunicom.mall.ebtp.common.util.PropertyUtils; +import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypBean; +import com.chinaunicom.mall.ebtp.extend.crypconfigure.service.ICrypConfigureService; +import com.chinaunicom.mall.ebtp.extend.shortmessage.entity.SmsCheckRequest; +import com.chinaunicom.mall.ebtp.extend.shortmessage.entity.SmsSendRequest; +import com.chinaunicom.mall.ebtp.extend.shortmessage.utils.SignUtil; +import org.bouncycastle.util.encoders.Base64; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import com.chinaunicom.mall.ebtp.common.base.service.impl.BaseServiceImpl; +import com.chinaunicom.mall.ebtp.extend.shortmessage.dao.BizShortMessageMapper; +import com.chinaunicom.mall.ebtp.extend.shortmessage.entity.BizShortMessage; +import com.chinaunicom.mall.ebtp.extend.shortmessage.service.BizShortMessageService; + +import java.nio.charset.StandardCharsets; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.concurrent.TimeUnit; + +/** + * 对数据表 biz_short_message 操作的 serviceImpl + * @author yss + * + */ +@Service +public class BizShortMessageServiceImpl extends BaseServiceImpl implements BizShortMessageService { + + @Value("${message.sendVerifycodeHttpUrl}") + private String sendVerifycodeHttpUrl; + @Value("${message.checkVerifycodeHttpUrl}") + private String checkVerifycodeHttpUrl; + @Autowired + private ICrypConfigureService iCrypConfigureService; + @Autowired(required = false) + @Qualifier("cacheRedisTemplate") + private RedisTemplate redisTemplate; + /** + * 业务系统私钥,在SignUtil会用到--这里在切换对接环境时会变化,由集团多因素项目项目组提供 + */ + private static final String PRI_KEY = "MHgCAQECIQCQO3m5phHk2I8SwgCIcQVcF5FkyCjnXWc2uRUz2/54N6AKBggqgRzPVQGCLaFEA0IABOnuKDS5zOzu5dW9bk0881GPpJkCMRa7yK4AopUoAzADZqddHqMmWl9VKI9n2qrIcx8rgRuv08tPGvV2Vo7776Q="; + + @Override + public Boolean authCodeSend(String mobile) { + String id = PropertyUtils.getSnowflakeId(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); + String bizSn = "ebtp"+id+"ebtp"+ LocalDate.now().format(formatter); + BizShortMessage shortMessage = new BizShortMessage(); + shortMessage.setId(id) + .setBizsn(bizSn) + .setCallbackurl(sendVerifycodeHttpUrl) + .setMobile(mobile) + .setSendTime(LocalDateTime.now()) + .setStatus(0) + .setType("sms"); + this.save(shortMessage); + redisTemplate.opsForValue().set("user:" + mobile, bizSn, 10, TimeUnit.MINUTES); + + //使用业务系统私钥对业务数据签名Base64编码后的数据(对bizSn进行签名的base64字符串)签名值 + byte[] signBytes = SignUtil.sign(PRI_KEY, bizSn.getBytes(StandardCharsets.UTF_8)); + String sign = Base64.toBase64String(signBytes); + + //组装参数 + SmsSendRequest smsSendRequest = new SmsSendRequest(); + //必传参数 + //应用标识,调用方使用自己的应用标识 + smsSendRequest.setAppCode("appCode"); + //流水号,调用方生成,保持唯一 + smsSendRequest.setBizSn(bizSn); + smsSendRequest.setSign(sign); + //手机号 未传时使用应用系统账号查询用户手机号 + smsSendRequest.setMobile(mobile); + //用户状态验证回调url + smsSendRequest.setCallBackUrl("http://10.124.150.230:8000/api/chinaUnicom/manageCenter/eshop/mobilecheck/v1"); + CrypBean bean = new CrypBean(); + bean.setReqName("MESSAGE_SEND_VERIFYCODE_REQ"); + bean.setUrl(sendVerifycodeHttpUrl); + bean.setObject(smsSendRequest); + boolean result = iCrypConfigureService.callUniInterfaceMessage(bean); + this.saveOrUpdate(shortMessage.setStatus(result?1:2)); + return result; + } + + @Override + public Boolean authCodeCheck(String mobile, String authCode) { + QueryWrapper query = new QueryWrapper<>(new BizShortMessage().setMobile(mobile).setStatus(1)); + BizShortMessage message = this.getBaseMapper().selectOne(query); +// String bizSn = message.getBizsn(); + Object value = redisTemplate.opsForValue().get("user:" + mobile); + if (value != null) { + //组装参数 + SmsCheckRequest smsCheckRequest = new SmsCheckRequest(); + + //必传参数 + //应用标识 + smsCheckRequest.setAppCode(message.getAppcode()); + //流水号,使用发送认证短信时的流水号 + smsCheckRequest.setBizSn(message.getBizsn()); + //生成签名 + byte[] signByte = SignUtil.sign(PRI_KEY,value.toString().getBytes(StandardCharsets.UTF_8)); + String sign = com.cuca.bouncycastle.util.encoders.Base64.toBase64String(signByte); + smsCheckRequest.setSign(sign); + //手机号 + smsCheckRequest.setMobile(mobile); + //验证码,手机收到的验证码 + smsCheckRequest.setAuthCode(authCode); + CrypBean bean = new CrypBean(); + bean.setReqName("MESSAGE_SEND_VERIFYCODE_REQ"); + bean.setUrl(checkVerifycodeHttpUrl); + bean.setObject(smsCheckRequest); + this.saveOrUpdate(message.setStatus(3)); + boolean result = iCrypConfigureService.callUniInterfaceMessage(bean); + this.saveOrUpdate(message.setStatus(result?4:5)); + return result; + } else { + return false; + } +// if (message!=null){ +// +// } + } +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/utils/SignUtil.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/utils/SignUtil.java new file mode 100644 index 0000000..e82fda8 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/shortmessage/utils/SignUtil.java @@ -0,0 +1,25 @@ +package com.chinaunicom.mall.ebtp.extend.shortmessage.utils; + +import com.cuca.security.algorithm.impl.soft.SoftSM2; +import com.cuca.security.soft.sm2.SM2PrivateKey; +import com.cuca.security.util.KeyFromDER; + +/** + * 签名生成演示方法 + */ +public class SignUtil { + + private static final SoftSM2 SM2 = new SoftSM2(); + private static final String SIGN_ALG = "SM3withSM2"; + + /** + * 签名 + * @param priKey Base64私钥字符串 + * @param inData 签名原文 + * @return 签名值 + */ + public static byte[] sign(String priKey, byte[] inData) { + SM2PrivateKey privateKey = KeyFromDER.getSM2PrivateKey("", priKey); + return SM2.externalSign(SIGN_ALG, privateKey, inData); + } +}