多因素

This commit is contained in:
jlzhangyx5
2023-08-28 10:08:31 +08:00
parent c99eb8d848
commit 603671e86c
5 changed files with 101 additions and 31 deletions

View File

@ -5,6 +5,7 @@ import com.chinaunicom.mall.ebtp.common.base.service.IBaseService;
import com.chinaunicom.mall.ebtp.extend.blockchain.entity.BlockChainLogVo; import com.chinaunicom.mall.ebtp.extend.blockchain.entity.BlockChainLogVo;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypBean; import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypBean;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypConfigure; import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypConfigure;
import com.chinaunicom.mall.ebtp.extend.shortmessage.entity.BaseRespVo;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
/** /**
@ -33,7 +34,7 @@ public interface ICrypConfigureService extends IBaseService<CrypConfigure> {
* @param bean * @param bean
* @return true/false * @return true/false
*/ */
Boolean callUniInterfaceMessage(CrypBean bean); BaseRespVo callUniInterfaceMessage(CrypBean bean);
/** /**
* 加载失败日志再发送 * 加载失败日志再发送
* @param * @param

View File

@ -31,6 +31,7 @@ import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypConfigure;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypUniBss; import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypUniBss;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.service.ICrypConfigureService; import com.chinaunicom.mall.ebtp.extend.crypconfigure.service.ICrypConfigureService;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.util.SslUtil; import com.chinaunicom.mall.ebtp.extend.crypconfigure.util.SslUtil;
import com.chinaunicom.mall.ebtp.extend.shortmessage.entity.BaseRespVo;
import com.chinaunicom.mall.ebtp.extend.uniBss.UniBssUtil; import com.chinaunicom.mall.ebtp.extend.uniBss.UniBssUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -208,8 +209,9 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
} }
@Override @Override
public Boolean callUniInterfaceMessage(CrypBean bean) { public BaseRespVo callUniInterfaceMessage(CrypBean bean) {
log.info("多因素------callUniInterfaceMessage---入参-----" + JSON.toJSONString(bean)); log.info("多因素------callUniInterfaceMessage---入参-----" + JSON.toJSONString(bean));
BaseRespVo bodys = new BaseRespVo();
BlockChainLog blockChainLog = new BlockChainLog(); BlockChainLog blockChainLog = new BlockChainLog();
blockChainLog.setId(PropertyUtils.getSnowflakeId()); blockChainLog.setId(PropertyUtils.getSnowflakeId());
//天擎地址 //天擎地址
@ -235,7 +237,7 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
log.info("多因素map------callUniInterfaceMessage---入参map-----" + JSON.toJSONString(map)); log.info("多因素map------callUniInterfaceMessage---入参map-----" + JSON.toJSONString(map));
//传入数据解密 //传入数据解密
String sign = getSignValue(map); // String sign = getSignValue(map);
// map.put("SIGN", sign); // map.put("SIGN", sign);
@ -244,29 +246,31 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
blockChainLog.setParam(json);//请求参数 blockChainLog.setParam(json);//请求参数
str = UniBssServiceImpl.uniBssHttpPost(bean.getUrl(), json); str = UniBssServiceImpl.uniBssHttpPost(bean.getUrl(), json);
blockChainLog.setResult(str);//返回参数 blockChainLog.setResult(str);//返回参数
UniBss uniBssRsp = JSONArray.parseObject(str, UniBss.class); CrypUniBss uniBssRsp = JSONArray.parseObject(str, CrypUniBss.class);
if (uniBssRsp != null && UniBssConstant.RESP_CODE_00000.equals(uniBssRsp.getUniBssHead().getRespCode())) { if (uniBssRsp != null && UniBssConstant.RESP_CODE_00000.equals(uniBssRsp.getUniBssHead().getRespCode())) {
System.out.println("返回接口:" + uniBssRsp); System.out.println("返回接口:" + uniBssRsp);
Map<String, Object> body = uniBssRsp.getUniBssBodyMap();
Object js = body.get("MESSAGE_SEND_VERIFYCODE_REQ".equals(bean.getReqName())?"MESSAGE_SEND_VERIFYCODE_RSP":"MESSAGE_CHECK_VERIFYCODE_RSP");
bodys = JSONArray.parseObject(js.toString(),BaseRespVo.class);
if (str != null && !"".equals(str) && str.indexOf("_RSP\":{\"Code\":200,") >= 0) { if (str != null && !"".equals(str) && str.indexOf("_RSP\":{\"Code\":200,") >= 0
&& ("0".equals(bodys.getCode()) || "200".equals(bodys.getCode()) )) {
blockChainLog.setStatus(0);//成功 blockChainLog.setStatus(0);//成功
this.iBlockChainLogService.save(blockChainLog); this.iBlockChainLogService.save(blockChainLog);
return true; return bodys;
} else { } else {
blockChainLog.setStatus(1);//失败 blockChainLog.setStatus(1);//失败
return bodys;
} }
} else { } else {
blockChainLog.setStatus(1);//失败 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) { } catch (Exception e) {
blockChainLog.setStatus(1); blockChainLog.setStatus(1);
blockChainLog.setResult(e.getMessage()); blockChainLog.setResult(e.getMessage());
}finally { }finally {
this.iBlockChainLogService.save(blockChainLog);
if(blockChainLog.getStatus().equals(1)){ if(blockChainLog.getStatus().equals(1)){
log.error("多因素调用失败!~-----------------"); log.error("多因素调用失败!~-----------------");
operationLogService.addOperationLog("多因素同步失败信息,参数{}"+json+"返回信息{}"+str,false, EbtpLogBusinessModule.OTHER, EbtpLogType.INSERT); operationLogService.addOperationLog("多因素同步失败信息,参数{}"+json+"返回信息{}"+str,false, EbtpLogBusinessModule.OTHER, EbtpLogType.INSERT);
@ -274,7 +278,7 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
} }
return false; return bodys;
} }
/** /**
@ -472,7 +476,7 @@ public class CrypConfigureServiceImpl extends BaseServiceImpl<CrypConfigureMappe
*/ */
private String getUniBssMessage(String reqName, Map<String, Object> map) { private String getUniBssMessage(String reqName, Map<String, Object> map) {
UniBss uniBss = new UniBss(); CrypUniBss uniBss = new CrypUniBss();
uniBss.setUniBssAttached(new UniBssAttached().setMediaInf("")); uniBss.setUniBssAttached(new UniBssAttached().setMediaInf(""));
//天擎部分head //天擎部分head
UniBssUtil util = new UniBssUtil(app_id, app_secret); UniBssUtil util = new UniBssUtil(app_id, app_secret);

View File

@ -0,0 +1,24 @@
package com.chinaunicom.mall.ebtp.extend.shortmessage.entity;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
@Data
public class BaseRespVo {
/**
*
*/
@JSONField(name = "code")
private String code;
/**
*
*/
@JSONField(name = "msg")
private String msg;
/**
*
*/
@JSONField(name = "data")
private String data;
}

View File

@ -2,9 +2,11 @@ package com.chinaunicom.mall.ebtp.extend.shortmessage.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chinaunicom.mall.ebtp.common.exception.common.CommonExceptionEnum;
import com.chinaunicom.mall.ebtp.common.util.PropertyUtils; import com.chinaunicom.mall.ebtp.common.util.PropertyUtils;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypBean; import com.chinaunicom.mall.ebtp.extend.crypconfigure.entity.CrypBean;
import com.chinaunicom.mall.ebtp.extend.crypconfigure.service.ICrypConfigureService; import com.chinaunicom.mall.ebtp.extend.crypconfigure.service.ICrypConfigureService;
import com.chinaunicom.mall.ebtp.extend.shortmessage.entity.BaseRespVo;
import com.chinaunicom.mall.ebtp.extend.shortmessage.entity.SmsCheckRequest; 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.entity.SmsSendRequest;
import com.chinaunicom.mall.ebtp.extend.shortmessage.utils.SignUtil; import com.chinaunicom.mall.ebtp.extend.shortmessage.utils.SignUtil;
@ -37,6 +39,10 @@ public class BizShortMessageServiceImpl extends BaseServiceImpl<BizShortMessageM
private String sendVerifycodeHttpUrl; private String sendVerifycodeHttpUrl;
@Value("${message.checkVerifycodeHttpUrl}") @Value("${message.checkVerifycodeHttpUrl}")
private String checkVerifycodeHttpUrl; private String checkVerifycodeHttpUrl;
@Value("${message.appCode}")
private String appCode;
@Value("${message.callBackUrl}")
private String callBackUrl;
@Autowired @Autowired
private ICrypConfigureService iCrypConfigureService; private ICrypConfigureService iCrypConfigureService;
@Autowired(required = false) @Autowired(required = false)
@ -45,13 +51,14 @@ public class BizShortMessageServiceImpl extends BaseServiceImpl<BizShortMessageM
/** /**
* 业务系统私钥在SignUtil会用到--这里在切换对接环境时会变化,由集团多因素项目项目组提供 * 业务系统私钥在SignUtil会用到--这里在切换对接环境时会变化,由集团多因素项目项目组提供
*/ */
private static final String PRI_KEY = "MHgCAQECIQCQO3m5phHk2I8SwgCIcQVcF5FkyCjnXWc2uRUz2/54N6AKBggqgRzPVQGCLaFEA0IABOnuKDS5zOzu5dW9bk0881GPpJkCMRa7yK4AopUoAzADZqddHqMmWl9VKI9n2qrIcx8rgRuv08tPGvV2Vo7776Q="; private static final String PRI_KEY = "MHgCAQECIQCA7a1i8iMeG0QoNfLYkAaj3IugsHjBGwcQv9/PmXY+cKAKBggqgRzPVQGCLaFEA0IABDBEOwQYJia5S4b5vbWy8YEh1LebhTTB2s2XlQfpjAEP7o8yYgwXWW20sXR+DcOPLwE1qqj9wUWz4zeeiv1+mzk=";
@Override @Override
public Boolean authCodeSend(String mobile) { public Boolean authCodeSend(String mobile) {
String id = PropertyUtils.getSnowflakeId(); String id = PropertyUtils.getSnowflakeId();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
String bizSn = "ebtp"+id+"ebtp"+ LocalDate.now().format(formatter); String bizSn = "ebtp"+id+"ebtp"+ LocalDate.now().format(formatter);
String s=appCode;
BizShortMessage shortMessage = new BizShortMessage(); BizShortMessage shortMessage = new BizShortMessage();
shortMessage.setId(id) shortMessage.setId(id)
.setBizsn(bizSn) .setBizsn(bizSn)
@ -71,21 +78,23 @@ public class BizShortMessageServiceImpl extends BaseServiceImpl<BizShortMessageM
SmsSendRequest smsSendRequest = new SmsSendRequest(); SmsSendRequest smsSendRequest = new SmsSendRequest();
//必传参数 //必传参数
//应用标识,调用方使用自己的应用标识 //应用标识,调用方使用自己的应用标识
smsSendRequest.setAppCode("appCode"); smsSendRequest.setAppCode(appCode);
//流水号,调用方生成,保持唯一 //流水号,调用方生成,保持唯一
smsSendRequest.setBizSn(bizSn); smsSendRequest.setBizSn(bizSn);
smsSendRequest.setSign(sign); smsSendRequest.setSign(sign);
//手机号 未传时使用应用系统账号查询用户手机号 //手机号 未传时使用应用系统账号查询用户手机号
smsSendRequest.setMobile(mobile); smsSendRequest.setMobile(mobile);
//用户状态验证回调url //用户状态验证回调url
smsSendRequest.setCallBackUrl("http://10.124.150.230:8000/api/chinaUnicom/manageCenter/eshop/mobilecheck/v1"); smsSendRequest.setCallBackUrl(callBackUrl);
CrypBean bean = new CrypBean(); CrypBean bean = new CrypBean();
bean.setReqName("MESSAGE_SEND_VERIFYCODE_REQ"); bean.setReqName("MESSAGE_SEND_VERIFYCODE_REQ");
bean.setUrl(sendVerifycodeHttpUrl); bean.setUrl(sendVerifycodeHttpUrl);
bean.setObject(smsSendRequest); bean.setObject(smsSendRequest);
boolean result = iCrypConfigureService.callUniInterfaceMessage(bean); BaseRespVo result = iCrypConfigureService.callUniInterfaceMessage(bean);
this.saveOrUpdate(shortMessage.setStatus(result?1:2)); this.saveOrUpdate(shortMessage.setStatus(("0".equals(result.getCode()) || "200".equals(result.getCode()) )?1:2));
return result; CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR
.customValidName(result.getMsg(),!("0".equals(result.getCode()) || "200".equals(result.getCode()) ));
return ("0".equals(result.getCode()) || "200".equals(result.getCode()) );
} }
@Override @Override
@ -100,9 +109,9 @@ public class BizShortMessageServiceImpl extends BaseServiceImpl<BizShortMessageM
//必传参数 //必传参数
//应用标识 //应用标识
smsCheckRequest.setAppCode(message.getAppcode()); smsCheckRequest.setAppCode(appCode);
//流水号,使用发送认证短信时的流水号 //流水号,使用发送认证短信时的流水号
smsCheckRequest.setBizSn(message.getBizsn()); smsCheckRequest.setBizSn(value.toString());
//生成签名 //生成签名
byte[] signByte = SignUtil.sign(PRI_KEY,value.toString().getBytes(StandardCharsets.UTF_8)); byte[] signByte = SignUtil.sign(PRI_KEY,value.toString().getBytes(StandardCharsets.UTF_8));
String sign = com.cuca.bouncycastle.util.encoders.Base64.toBase64String(signByte); String sign = com.cuca.bouncycastle.util.encoders.Base64.toBase64String(signByte);
@ -112,13 +121,15 @@ public class BizShortMessageServiceImpl extends BaseServiceImpl<BizShortMessageM
//验证码,手机收到的验证码 //验证码,手机收到的验证码
smsCheckRequest.setAuthCode(authCode); smsCheckRequest.setAuthCode(authCode);
CrypBean bean = new CrypBean(); CrypBean bean = new CrypBean();
bean.setReqName("MESSAGE_SEND_VERIFYCODE_REQ"); bean.setReqName("MESSAGE_CHECK_VERIFYCODE_REQ");
bean.setUrl(checkVerifycodeHttpUrl); bean.setUrl(checkVerifycodeHttpUrl);
bean.setObject(smsCheckRequest); bean.setObject(smsCheckRequest);
this.saveOrUpdate(message.setStatus(3)); this.saveOrUpdate(message.setStatus(3));
boolean result = iCrypConfigureService.callUniInterfaceMessage(bean); BaseRespVo result = iCrypConfigureService.callUniInterfaceMessage(bean);
this.saveOrUpdate(message.setStatus(result?4:5)); this.saveOrUpdate(message.setStatus(("0".equals(result.getCode()) || "200".equals(result.getCode()) )?4:5));
return result; CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR
.customValidName(result.getMsg(),!("0".equals(result.getCode()) || "200".equals(result.getCode()) ));
return ("0".equals(result.getCode()) || "200".equals(result.getCode()) );
} else { } else {
return false; return false;
} }

View File

@ -35,7 +35,7 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
username: mall username: mall
password: unicom password: Unicom160_30
jdbc-url: jdbc:mysql://10.125.160.30:3306/ebtp_mall_extend?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true jdbc-url: jdbc:mysql://10.125.160.30:3306/ebtp_mall_extend?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
url: jdbc:mysql://10.125.160.30:3306/ebtp_mall_extend?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true url: jdbc:mysql://10.125.160.30:3306/ebtp_mall_extend?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
filters: stat,wall,log4j filters: stat,wall,log4j
@ -157,6 +157,21 @@ ribbon:
MaxAutoRetriesNextServer: 1 #切换实例的重试次数 1 MaxAutoRetriesNextServer: 1 #切换实例的重试次数 1
mconfig: mconfig:
wps:
bssAppId: ue32TUnBeW
bssAppSecret: 23Ue8DKUM4VTR5uz9LiADBTI3lbCJPqF
bssAppUrl: http://10.124.150.230:8000
appid: AK20230531MTEMAF
appKey: 4ab670a08faf182d6a99a82cd8a6e05b
bss:
appTokenUrl: /api/chinaUnicom/manageCenter/documentCenter/apptoken/v1
previewUrl: /api/chinaUnicom/manageCenter/documentCenter/previewUrl/v1
editUrl: /api/chinaUnicom/manageCenter/documentCenter/webofficeurl/v1
url:
appTokenUrl: /auth/v1/app/inscope/token
previewUrl: /preview/v2/url
editUrl: /weboffice/v2/url
downFileUrl: http://10.242.31.158:18022/api/doc/v1.0/files/download
workerId: 1 workerId: 1
datacenterId: 1 datacenterId: 1
# 服务名 # 服务名
@ -182,7 +197,11 @@ mconfig:
app-url: 1mb6n6635cJkDb3pEQPUFXc2nRJ8RPaS app-url: 1mb6n6635cJkDb3pEQPUFXc2nRJ8RPaS
document: document:
clientHttpUrl: http://10.242.31.158:8100/auth/oauth/token?grant_type=client_credentials&client_id=bVS46ElU&client_secret=58ea04ba02475c8da2321cc99849d2a10f15b749 clientHttpUrl: http://10.242.31.158:8100/auth/oauth/token?grant_type=client_credentials&client_id=bVS46ElU&client_secret=58ea04ba02475c8da2321cc99849d2a10f15b749
message:
appCode: WEB9849352
sendVerifycodeHttpUrl: http://10.124.150.230:8000/api/chinaUnicom/dataMidPlatform/authenticationCenter/messageSendVerifycode/v1
checkVerifycodeHttpUrl: http://10.124.150.230:8000/api/chinaUnicom/dataMidPlatform/authenticationCenter/messageCheckVerifycode/v1
callBackUrl: http://10.124.150.230:8000/api/chinaUnicom/manageCenter/eshop/mobilecheck/v1
# 用户暴露给 prometheus 的健康数据 # 用户暴露给 prometheus 的健康数据
management: management:
endpoints: endpoints:
@ -209,11 +228,11 @@ xxl:
unifast: unifast:
sso: sso:
public-key: 11 public-key: 0428D625CEEB71CE823BD7D78DFEE7B122F2DA5C4D21E32253AD684D0FE21810394A799639C0CDFBFEB535A1DFD6A366A637E582CE0B1466A5FE7858841135DE6B
clientId: 1 clientId: p6IPukcJ
redirectUrl: 1 redirectUrl: http://10.125.86.213:18000/redirect
getCode: getCode:
url: 1 url: http://10.125.86.213:18808/outer/v1.0/sso/decide
client: client:
@ -222,3 +241,14 @@ allow:
apis: apis:
- ^GET\./?v1/send/msg/interest/getcode$ - ^GET\./?v1/send/msg/interest/getcode$
- ^POST\./?v1/send/msg/interest/code$ - ^POST\./?v1/send/msg/interest/code$
- ^POST\./?v1/bizshortmessage/send/authCode$
- ^POST\./?v1/bizshortmessage/check/authCode$
oss:
endpoint: oss-cn-guangzhou-gz-d01-a.ops.super.guangzhou.unicom.local
accessKeyId: wikrNkei48gp4buV
accessKeySecret: LD8jDhf0qow4iel8vO7wno6bp4ZM7q
# accessKeyId: ENC(F3Coanx/L2UF6XjF4Uk7yp/UvkNhAlEDzLsCoBKCStBSsCZNjnzvQhpg28NUvCdG71MJZZbwCoCG5j6R7XX13A==)
# accessKeySecret: ENC(QBot3xocahGOFoGM8G7G998htTLPrbLzWa2ud05MdD6hAKPUpFAmbewui8wngQglGvZKbc8Uz+K8TpHJdSJtqw==)
bucketName: test-mall3