From a1b1a18d4df3d0110211153d00ab87da741f4af2 Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Thu, 13 Mar 2025 17:01:04 +0800 Subject: [PATCH] healthbody --- .../app/manage/dto/AppMobileUserLoginDTO.java | 38 +++ .../dto/AppMobileUserModifyPhoneDTO.java | 26 ++ .../manage/dto/AuthAppModifyAvatarDTO.java | 39 +++ .../manage/dto/AuthAppModifyPasswordDTO.java | 51 ++++ .../manage/dto/AuthAppModifyUsernameDTO.java | 17 ++ .../manage/dto/AuthAppResetPasswordDTO.java | 36 +++ .../auth/oauth/controller/AuthController.java | 271 ++++++++++++++++++ .../manage/dto/MgrDeviceUserLoginDTO.java | 79 +++++ .../auth/oauth/pad/vo/AllocCanteenPadVO.java | 42 +++ .../auth/oauth/vo/DeviceLoginResponseVo.java | 45 +++ .../bonus/canteen/core/config/SmUtils.java | 143 +++++++++ .../core/device/mq/MacMessageService.java | 17 ++ 12 files changed, 804 insertions(+) create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AppMobileUserLoginDTO.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AppMobileUserModifyPhoneDTO.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppModifyAvatarDTO.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppModifyPasswordDTO.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppModifyUsernameDTO.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppResetPasswordDTO.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/controller/AuthController.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/device/manage/dto/MgrDeviceUserLoginDTO.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/pad/vo/AllocCanteenPadVO.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/vo/DeviceLoginResponseVo.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/config/SmUtils.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/mq/MacMessageService.java diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AppMobileUserLoginDTO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AppMobileUserLoginDTO.java new file mode 100644 index 00000000..ce6433f7 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AppMobileUserLoginDTO.java @@ -0,0 +1,38 @@ +package com.bonus.canteen.core.auth.oauth.app.manage.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotBlank; + +@ApiModel("app手机验证码登录入参") +public class AppMobileUserLoginDTO { + @ApiModelProperty("手机号") + private @NotBlank( + message = "{auth_mobile_null}" +) String telephoneNumber; + @ApiModelProperty("短信验证码") + private @NotBlank( + message = "{auth_code_null}" +) String code; + + public String getTelephoneNumber() { + return this.telephoneNumber; + } + + public String getCode() { + return this.code; + } + + public void setTelephoneNumber(final String telephoneNumber) { + this.telephoneNumber = telephoneNumber; + } + + public void setCode(final String code) { + this.code = code; + } + + public String toString() { + String var10000 = this.getTelephoneNumber(); + return "AppMobileUserLoginDTO(telephoneNumber=" + var10000 + ", code=" + this.getCode() + ")"; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AppMobileUserModifyPhoneDTO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AppMobileUserModifyPhoneDTO.java new file mode 100644 index 00000000..761f1d8c --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AppMobileUserModifyPhoneDTO.java @@ -0,0 +1,26 @@ +package com.bonus.canteen.core.auth.oauth.app.manage.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotBlank; + +@ApiModel("app手机验证码登录入参") +public class AppMobileUserModifyPhoneDTO extends AppMobileUserLoginDTO { + @ApiModelProperty("原手机号") + private @NotBlank( + message = "{auth_mobile_null}" +) String oldTelephoneNumber; + + public String getOldTelephoneNumber() { + return this.oldTelephoneNumber; + } + + public void setOldTelephoneNumber(final String oldTelephoneNumber) { + this.oldTelephoneNumber = oldTelephoneNumber; + } + + public String toString() { + return "AppMobileUserModifyPhoneDTO(oldTelephoneNumber=" + this.getOldTelephoneNumber() + ")"; + } + +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppModifyAvatarDTO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppModifyAvatarDTO.java new file mode 100644 index 00000000..d9a094d9 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppModifyAvatarDTO.java @@ -0,0 +1,39 @@ +package com.bonus.canteen.core.auth.oauth.app.manage.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@ApiModel("app 更换人员头像") +public class AuthAppModifyAvatarDTO { + @ApiModelProperty("用户ID") + private @NotNull( + message = "用户id 不能为空" +) Long userId; + @ApiModelProperty("人员头像地址") + private @NotBlank( + message = "人员头像地址 不能为空" +) String custPhotoUrl; + + public Long getUserId() { + return this.userId; + } + + public String getCustPhotoUrl() { + return this.custPhotoUrl; + } + + public void setUserId(final Long userId) { + this.userId = userId; + } + + public void setCustPhotoUrl(final String custPhotoUrl) { + this.custPhotoUrl = custPhotoUrl; + } + + public String toString() { + Long var10000 = this.getUserId(); + return "AuthAppModifyAvatarDTO(userId=" + var10000 + ", custPhotoUrl=" + this.getCustPhotoUrl() + ")"; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppModifyPasswordDTO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppModifyPasswordDTO.java new file mode 100644 index 00000000..dc211f79 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppModifyPasswordDTO.java @@ -0,0 +1,51 @@ +package com.bonus.canteen.core.auth.oauth.app.manage.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@ApiModel("app 修改密码DTO") +public class AuthAppModifyPasswordDTO { + @ApiModelProperty("用户编号") + private @NotNull( + message = "{auth_no_username}" +) Long userId; + @ApiModelProperty("原始密码") + private @NotBlank( + message = "{auth_no_old_password}" +) String oldPassword; + @ApiModelProperty("新密码") + private @NotBlank( + message = "{auth_no_new_password}" +) String newPassword; + + public Long getUserId() { + return this.userId; + } + + public String getOldPassword() { + return this.oldPassword; + } + + public String getNewPassword() { + return this.newPassword; + } + + public void setUserId(final Long userId) { + this.userId = userId; + } + + public void setOldPassword(final String oldPassword) { + this.oldPassword = oldPassword; + } + + public void setNewPassword(final String newPassword) { + this.newPassword = newPassword; + } + + public String toString() { + Long var10000 = this.getUserId(); + return "AuthAppModifyPasswordDTO(userId=" + var10000 + ", oldPassword=" + this.getOldPassword() + ", newPassword=" + this.getNewPassword() + ")"; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppModifyUsernameDTO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppModifyUsernameDTO.java new file mode 100644 index 00000000..fda3a410 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppModifyUsernameDTO.java @@ -0,0 +1,17 @@ +package com.bonus.canteen.core.auth.oauth.app.manage.dto; + +public class AuthAppModifyUsernameDTO { + private String username; + + public String getUsername() { + return this.username; + } + + public void setUsername(final String username) { + this.username = username; + } + + public String toString() { + return "AuthAppModifyUsernameDTO(username=" + this.getUsername() + ")"; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppResetPasswordDTO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppResetPasswordDTO.java new file mode 100644 index 00000000..5f5650e6 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/app/manage/dto/AuthAppResetPasswordDTO.java @@ -0,0 +1,36 @@ +package com.bonus.canteen.core.auth.oauth.app.manage.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotBlank; + +@ApiModel("app 重置密码DTO") +public class AuthAppResetPasswordDTO { + @ApiModelProperty("用户ID") + private Long userId; + @ApiModelProperty("密码") + private @NotBlank( + message = "{auth_no_password}" +) String password; + + public Long getUserId() { + return this.userId; + } + + public String getPassword() { + return this.password; + } + + public void setUserId(final Long userId) { + this.userId = userId; + } + + public void setPassword(final String password) { + this.password = password; + } + + public String toString() { + Long var10000 = this.getUserId(); + return "AuthAppResetPasswordDTO(userId=" + var10000 + ", password=" + this.getPassword() + ")"; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/controller/AuthController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/controller/AuthController.java new file mode 100644 index 00000000..c2d0cadc --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/controller/AuthController.java @@ -0,0 +1,271 @@ +package com.bonus.canteen.core.auth.oauth.controller; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.text.CharSequenceUtil; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.bonus.canteen.core.config.SecureProperties; +import com.bonus.canteen.core.config.SmUtils; +import com.bonus.canteen.core.device.mq.MacMessageService; +import com.bonus.common.core.web.domain.AjaxResult; +import com.google.common.base.Joiner; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import com.bonus.canteen.core.auth.oauth.vo.DeviceLoginResponseVo; +import com.bonus.canteen.core.common.utils.HeaderFetchUtil; +import com.bonus.canteen.core.device.manage.controller.deprecated.vo.MessageConfigVO; +import com.bonus.canteen.core.device.manage.model.DeviceInfoInSystem; +import com.bonus.canteen.core.device.manage.service.DeviceInfoService; +import com.bonus.canteen.core.merchant.api.MercMerchantApi; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.web.bind.annotation.*; +import java.lang.invoke.SerializedLambda; +import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +@RestController +@RequestMapping({"/oauth"}) +@Api( + value = "auth", + tags = {"登陆模块"} +) +public class AuthController { + private static final Logger log = LoggerFactory.getLogger(AuthController.class); + private static final String HEADER_SECURITY_TENANT_ID = "X-Security-Tenant-Id"; + private static final String HEADER_SECURITY_TOKEN = "X-Security-Token"; + private static final String HEADER_SECURITY_SN = "X-Security-Sn"; +// @Autowired +// private MgrUserService mgrUserService; + @Autowired + @Lazy + private MercMerchantApi mercMerchantApi; + @Autowired + @Lazy + private DeviceInfoService deviceInfoService; + @Autowired + @Lazy + private MacMessageService macMessageService; + @Autowired + @Lazy + private SecureProperties secureProperties; +// @Autowired +// @Lazy +// BackDeviceApi backDeviceApi; +// @Autowired +// private OpenAppService openAppService; + +// @RequireVerifyCode +// @PostMapping({"/web/token"}) +// @RequiresGuest +// @ApiOperation("web登陆") +// public LeResponse webLogin(@RequestParam String content) { +// MgrUserLoginDTO loginDTO = (MgrUserLoginDTO)JSON.parseObject(content, MgrUserLoginDTO.class); +// +// JSONObject object; +// try { +// PigxUser user = this.mgrUserService.login(loginDTO); +// object = JSON.parseObject(JSON.toJSONString(user)); +// if (ObjectUtil.isNotNull(user.getMerchantId())) { +// TenantContextHolder.setTenantId(user.getMerchantId()); +// MercMerchant mercMerchant = this.mercMerchantApi.getMerchant(); +// object.put("merchantName", mercMerchant.getMerchantName()); +// } +// +// if (WebContext.get().getAccessToken().isPresent()) { +// object.put("securityTokenSign", OAuthUtil.responseSetSecurityTokenSign(user.getMerchantId(), ((AccessToken)WebContext.get().getAccessToken().get()).getId())); +// } +// } catch (LeCheckedException var6) { +// return LeResponse.fail(var6.getMessage()); +// } +// +// return LeResponse.succ(object); +// } +// +// @PostMapping({"/token"}) +// @RequiresGuest +// @ApiOperation("设备登陆接口登陆") +// public LeResponse login(@RequestParam String content) { +// MgrUserLoginDTO loginDTO = (MgrUserLoginDTO)JSON.parseObject(content, MgrUserLoginDTO.class); +// +// JSONObject object; +// try { +// PigxUser user = this.mgrUserService.login(loginDTO); +// object = JSON.parseObject(JSON.toJSONString(user)); +// object.put("user_id", user.getId()); +// object.put("merchant_id", user.getMerchantId()); +// if (WebContext.get().getAccessToken().isPresent()) { +// object.put("securityTokenSign", OAuthUtil.responseSetSecurityTokenSign(user.getMerchantId(), ((AccessToken)WebContext.get().getAccessToken().get()).getId())); +// } +// } catch (LeCheckedException var5) { +// return LeResponse.fail(var5.getMessage()); +// } +// +// return LeResponse.succ(object); +// } +// +// @DeleteMapping({"/logOut"}) +// @RequiresAuthentication +// @ApiOperation("退出登陆") +// @AnLogRecord( +// value = "退出登录", +// type = LogRecordOperTypeEnum.SIGN_OUT +// ) +// public LeResponse logOut() { +// SecureManager.logout(); +// return LeResponse.succ("操作成功"); +// } +// +// @PostMapping({"/public/login"}) +// @RequiresGuest +// @ApiOperation("采购库存公众号登陆接口") +// public LeResponse publicLogin(@RequestBody LeRequest request) { +// MgrUserLoginDTO loginDTO = (MgrUserLoginDTO)request.getContent(); +// loginDTO.setUsername(new String(loginDTO.getUsername().getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8)); +// +// PigxUser user; +// try { +// user = this.mgrUserService.login(loginDTO); +// if (CharSequenceUtil.isBlank(loginDTO.getOpenid())) { +// return LeResponse.succ(user); +// } +// +// MgrUser mgrUser = (MgrUser)this.mgrUserService.getOne((Wrapper)Wrappers.lambdaQuery().eq(MgrUser::getUserId, user.getId())); +// String wxOpenids = mgrUser.getWxOpenid(); +// List openidList = CharSequenceUtil.isNotBlank(wxOpenids) ? CharSequenceUtil.split(wxOpenids, ",") : CollUtil.newArrayList(new String[0]); +// ((List)openidList).add(loginDTO.getOpenid()); +// mgrUser.setWxOpenid(CollUtil.join((Iterable)openidList, ",")); +// this.mgrUserService.updateById(mgrUser); +// } catch (LeCheckedException var7) { +// return LeResponse.fail(var7.getMessage()); +// } +// +// return LeResponse.succ(user); +// } +// +// @ApiOperation("web-单点登陆") +// @PostMapping({"/web/single-sign-on"}) +// @RequiresGuest +// public PigxUser webSingleSignOn(@RequestParam("tenantId") Long tenantId, @RequestBody LeRequest request) { +// return this.mgrUserService.webSingleSignOn(tenantId, (MgrUserSsoDTO)request.getContent()); +// } + + @ApiOperation("设备认证") + @PostMapping({"/device/login"}) + public AjaxResult deviceLogin(@RequestHeader Map header, @RequestBody String request) { + String deviceSn = SmUtils.decryptBySm2(request); + String encryptKey = HeaderFetchUtil.getValueFromHeadersIgnoreCase(header, this.secureProperties.getSecurity().getServerEncryptedClientKeyHeaderName()); + String clientKey = SmUtils.decryptBySm4WithServerKey(encryptKey); + if (CharSequenceUtil.isEmpty(deviceSn)) { + return AjaxResult.success(); + } else { + DeviceInfoInSystem deviceInfo = this.deviceInfoService.getBySnInSys(deviceSn); + if (ObjectUtil.isNull(deviceInfo)) { + return AjaxResult.success(); + } else { + MessageConfigVO messageConfigVO = this.macMessageService.getMessageConfig(); + DeviceLoginResponseVo responseVo = new DeviceLoginResponseVo(); + responseVo.setTenantId(deviceInfo.getTenantId()); + responseVo.setMqClientAddress(messageConfigVO.getMqClientAddress()); + String deviceToken = this.generatorToken(deviceSn, clientKey, deviceInfo.getTenantId()); + String securityTokenSign = this.getSecurityTokenSign(deviceSn, clientKey, deviceInfo.getTenantId(), deviceToken); + responseVo.setDeviceToken(deviceToken); + responseVo.setSecurityTokenSign(securityTokenSign); + return AjaxResult.success(responseVo); + } + } + } + +// @ApiOperation("后场设备认证") +// @PostMapping({"/back/device/login"}) +// @RequiresGuest +// public LeResponse backDeviceLogin(@RequestHeader Map header, @RequestBody LeRequest request) { +// String deviceSn = SmUtils.decryptBySm2((String)request.getContent()); +// String encryptKey = HeaderFetchUtil.getValueFromHeadersIgnoreCase(header, this.secureProperties.getSecurity().getServerEncryptedClientKeyHeaderName()); +// String clientKey = SmUtils.decryptBySm4WithServerKey(encryptKey); +// if (CharSequenceUtil.isEmpty(deviceSn)) { +// return LeResponse.succ(); +// } else { +// BackDevicesInSystem backDevicesInSystem = this.backDeviceApi.getBySnInSyS(deviceSn); +// if (ObjectUtil.isNull(backDevicesInSystem)) { +// return LeResponse.succ(); +// } else { +// MessageConfigVO messageConfigVO = this.macMessageService.getMessageConfig(); +// DeviceLoginResponseVo responseVo = new DeviceLoginResponseVo(); +// responseVo.setTenantId(backDevicesInSystem.getTenantId()); +// responseVo.setMqClientAddress(messageConfigVO.getMqClientAddress()); +// String deviceToken = this.generatorToken(deviceSn, clientKey, backDevicesInSystem.getTenantId()); +// String securityTokenSign = this.getSecurityTokenSign(deviceSn, clientKey, backDevicesInSystem.getTenantId(), deviceToken); +// responseVo.setDeviceToken(deviceToken); +// responseVo.setSecurityTokenSign(securityTokenSign); +// return LeResponse.succ(responseVo); +// } +// } +// } + + private String getSecurityTokenSign(String deviceSn, String clientKey, Long tenantId, String deviceToken) { + TreeMap needSignMap = new TreeMap(); + needSignMap.put("X-Security-Tenant-Id", String.valueOf(tenantId)); + needSignMap.put("X-Security-Sn", deviceSn); + needSignMap.put("X-Security-Token", deviceToken); + return SmUtils.signAuthTokenBySm3(needSignMap, clientKey); + } + + private String generatorToken(String deviceSn, String clientKey, Long tenantId) { + TreeMap paramMap = new TreeMap(); + paramMap.put("X-Security-Sn", deviceSn); + paramMap.put("X-Security-Tenant-Id", String.valueOf(tenantId)); + log.info("设备登录待签名:{}", Joiner.on("&").useForNull("").withKeyValueSeparator("=").join(paramMap)); + return SmUtils.signAuthTokenBySm3(paramMap, clientKey); + } + +// @ApiOperation("openapi认证") +// @PostMapping({"/openapi/login"}) +// @RequiresGuest +// @ResponseWrapperByPass +// public OpenApiLoginVo openApiLogin(@RequestHeader Map header, @RequestBody Map content) { +// String appIdEncrypt = (String)content.get("content"); +// if (ObjectUtil.isNull(appIdEncrypt)) { +// throw new LeException(CheckEnum.VALID_APPID_MISS.getCode(), CheckEnum.VALID_APPID_MISS.getErrorMsg()); +// } else { +// String appIdStr = SmUtils.decryptBySm2(appIdEncrypt); +// if (!NumberUtil.isLong(appIdStr)) { +// throw new LeException(CheckEnum.VALID_APPID_FORMAT_ERROR.getCode(), CheckEnum.VALID_APPID_FORMAT_ERROR.getErrorMsg()); +// } else { +// Long appid = Long.parseLong(appIdStr); +// OpenApp app = this.openAppService.getAppInfoByAppId(appid); +// if (ObjectUtil.isNull(app)) { +// throw new LeException(CheckEnum.VALID_APPID_ERROR.getCode(), CheckEnum.VALID_APPID_ERROR.getErrorMsg()); +// } else if (ObjectUtil.equals(app.getDisable(), LeConstants.COMMON_YES)) { +// throw new LeException(CheckEnum.VALID_APPID_DISABLE.getCode(), CheckEnum.VALID_APPID_DISABLE.getErrorMsg()); +// } else { +// LocalDateTime startTime = app.getStartTime(); +// LocalDateTime endTime = app.getEndTime(); +// LocalDateTime now = LocalDateTime.now(); +// if (ObjectUtil.isNotNull(startTime) && now.isBefore(startTime)) { +// throw new LeException(CheckEnum.VALID_APPID_BEFORE.getCode(), CheckEnum.VALID_APPID_BEFORE.getErrorMsg()); +// } else if (ObjectUtil.isNotNull(endTime) && now.isAfter(endTime)) { +// throw new LeException(CheckEnum.VALID_APPID_EXPIRED.getCode(), CheckEnum.VALID_APPID_EXPIRED.getErrorMsg()); +// } else { +// String encryptKey = HeaderFetchUtil.getValueFromHeadersIgnoreCase(header, this.secureProperties.getSecurity().getServerEncryptedClientKeyHeaderName()); +// String clientKey = SmUtils.decryptBySm4WithServerKey(encryptKey); +// String token = this.generatorToken(String.valueOf(appid), clientKey, app.getTenantId()); +// OpenApiLoginVo loginVo = new OpenApiLoginVo(); +// loginVo.setToken(token).setTenantId(app.getTenantId()).setSecurityTokenSign(OAuthUtil.responseSetSecurityTokenSign(app.getTenantId(), token)).setAppName(app.getAppName()); +// return loginVo; +// } +// } +// } +// } +// } + +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/device/manage/dto/MgrDeviceUserLoginDTO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/device/manage/dto/MgrDeviceUserLoginDTO.java new file mode 100644 index 00000000..f36f101e --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/device/manage/dto/MgrDeviceUserLoginDTO.java @@ -0,0 +1,79 @@ +package com.bonus.canteen.core.auth.oauth.device.manage.dto; + +import io.swagger.annotations.ApiModelProperty; + +public class MgrDeviceUserLoginDTO { + @ApiModelProperty("用户名") + private String username; + @ApiModelProperty("密码") + private String password; + private String scope; + private String grant_type; + @ApiModelProperty("用户id,刷脸必传") + private Long custId; + @ApiModelProperty("卡号,刷卡必传") + private String serialNum; + @ApiModelProperty("扫码值,扫码必传") + private String authCode; + + public String getUsername() { + return this.username; + } + + public String getPassword() { + return this.password; + } + + public String getScope() { + return this.scope; + } + + public String getGrant_type() { + return this.grant_type; + } + + public Long getCustId() { + return this.custId; + } + + public String getSerialNum() { + return this.serialNum; + } + + public String getAuthCode() { + return this.authCode; + } + + public void setUsername(final String username) { + this.username = username; + } + + public void setPassword(final String password) { + this.password = password; + } + + public void setScope(final String scope) { + this.scope = scope; + } + + public void setGrant_type(final String grant_type) { + this.grant_type = grant_type; + } + + public void setCustId(final Long custId) { + this.custId = custId; + } + + public void setSerialNum(final String serialNum) { + this.serialNum = serialNum; + } + + public void setAuthCode(final String authCode) { + this.authCode = authCode; + } + + public String toString() { + String var10000 = this.getUsername(); + return "MgrDeviceUserLoginDTO(username=" + var10000 + ", password=" + this.getPassword() + ", scope=" + this.getScope() + ", grant_type=" + this.getGrant_type() + ", custId=" + this.getCustId() + ", serialNum=" + this.getSerialNum() + ", authCode=" + this.getAuthCode() + ")"; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/pad/vo/AllocCanteenPadVO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/pad/vo/AllocCanteenPadVO.java new file mode 100644 index 00000000..01096147 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/pad/vo/AllocCanteenPadVO.java @@ -0,0 +1,42 @@ +package com.bonus.canteen.core.auth.oauth.pad.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import com.bonus.canteen.core.allocation.canteen.model.AllocCanteen; + +@ApiModel("AllocCanteenPadVO") +public class AllocCanteenPadVO { + @ApiModelProperty("食堂id") + private Long canteenId; + @ApiModelProperty("食堂名称") + private String canteenName; + + public AllocCanteenPadVO(AllocCanteen allocCanteen) { + this.canteenId = allocCanteen.getId(); + this.canteenName = allocCanteen.getCanteenName(); + } + + public Long getCanteenId() { + return this.canteenId; + } + + public String getCanteenName() { + return this.canteenName; + } + + public void setCanteenId(final Long canteenId) { + this.canteenId = canteenId; + } + + public void setCanteenName(final String canteenName) { + this.canteenName = canteenName; + } + + public String toString() { + Long var10000 = this.getCanteenId(); + return "AllocCanteenPadVO(canteenId=" + var10000 + ", canteenName=" + this.getCanteenName() + ")"; + } + + public AllocCanteenPadVO() { + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/vo/DeviceLoginResponseVo.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/vo/DeviceLoginResponseVo.java new file mode 100644 index 00000000..8199dda6 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/auth/oauth/vo/DeviceLoginResponseVo.java @@ -0,0 +1,45 @@ +package com.bonus.canteen.core.auth.oauth.vo; + +public class DeviceLoginResponseVo { + private Long tenantId; + private String mqClientAddress; + private String deviceToken; + private String securityTokenSign; + + public Long getTenantId() { + return this.tenantId; + } + + public String getMqClientAddress() { + return this.mqClientAddress; + } + + public String getDeviceToken() { + return this.deviceToken; + } + + public String getSecurityTokenSign() { + return this.securityTokenSign; + } + + public void setTenantId(final Long tenantId) { + this.tenantId = tenantId; + } + + public void setMqClientAddress(final String mqClientAddress) { + this.mqClientAddress = mqClientAddress; + } + + public void setDeviceToken(final String deviceToken) { + this.deviceToken = deviceToken; + } + + public void setSecurityTokenSign(final String securityTokenSign) { + this.securityTokenSign = securityTokenSign; + } + + public String toString() { + Long var10000 = this.getTenantId(); + return "DeviceLoginResponseVo(tenantId=" + var10000 + ", mqClientAddress=" + this.getMqClientAddress() + ", deviceToken=" + this.getDeviceToken() + ", securityTokenSign=" + this.getSecurityTokenSign() + ")"; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/config/SmUtils.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/config/SmUtils.java new file mode 100644 index 00000000..bff6c6ad --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/config/SmUtils.java @@ -0,0 +1,143 @@ +package com.bonus.canteen.core.config; + +import cn.hutool.core.codec.Base64Decoder; +import cn.hutool.core.codec.Base64Encoder; +import cn.hutool.core.util.PrimitiveArrayUtil; +import cn.hutool.core.util.RandomUtil; +import cn.hutool.crypto.Mode; +import cn.hutool.crypto.Padding; +import cn.hutool.crypto.SmUtil; +import cn.hutool.crypto.asymmetric.KeyType; +import cn.hutool.crypto.asymmetric.SM2; +import cn.hutool.crypto.symmetric.SM4; +import com.google.common.base.Joiner; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; +import java.io.PrintStream; +import java.nio.charset.StandardCharsets; +import java.security.NoSuchAlgorithmException; +import java.util.SortedMap; + +public class SmUtils { + private static final Logger log = LoggerFactory.getLogger(SmUtils.class); + private static SecureProperties secureProperties; + + public static void setSecureProperties(SecureProperties secureProperties) { + if (SmUtils.secureProperties == null) { + SmUtils.secureProperties = secureProperties; + } + } + + public static String signBySm3(SortedMap data, String clientKey) { + data.put(secureProperties.getSecurity().getClientKeySignParamName(), clientKey); + String joinedParam = Joiner.on("&").useForNull("").withKeyValueSeparator("=").join(data); + log.debug("Sign param:{}", joinedParam); + return Base64Encoder.encode(SmUtil.sm3().digest(joinedParam)); + } + + public static String signBySm3WithServerKey(SortedMap data, String clientKey) { + data.put(secureProperties.getSecurity().getServerKeySignParamName(), secureProperties.getSecurity().getServerSm4Key()); + return signBySm3(data, clientKey); + } + + public static String signAuthTokenBySm3(SortedMap data, String clientKey) { + return signBySm3WithServerKey(data, clientKey); + } + + public static String decryptBySm2(String data) { + return SmUtil.sm2(secureProperties.getSecurity().getServerSm2Key(), secureProperties.getSecurity().getClientSm2Key()).decryptStr(data, KeyType.PrivateKey); + } + + public static String signBySm2(String data) { + return Base64Encoder.encode(SmUtil.sm2(secureProperties.getSecurity().getServerSm2Key(), secureProperties.getSecurity().getClientSm2Key()).sign(data.getBytes(StandardCharsets.UTF_8))); + } + + public static String decryptBySm4(String data, byte[] key) { + byte[] decodedData = Base64Decoder.decode(data); + if (decodedData.length <= 16) { + throw new IllegalArgumentException("Encrypted data byte length must greater than 16"); + } else { + byte[] iv = PrimitiveArrayUtil.sub(decodedData, 0, 16); + byte[] dataBytes = PrimitiveArrayUtil.sub(decodedData, 16, decodedData.length); + return (new SM4(Mode.CBC, Padding.PKCS5Padding, key, iv)).decryptStr(dataBytes); + } + } + + public static String decryptBySm4(String data, String key) { + return decryptBySm4(data, Base64Decoder.decode(key)); + } + + public static String decryptBySm4WithServerKey(String data) { + return decryptBySm4(data, secureProperties.getSecurity().getServerSm4KeyBytes()); + } + + public static String encryptBySm4(String data, byte[] key) { + SM4 var10000 = new SM4(Mode.CBC, Padding.PKCS5Padding, key, RandomUtil.randomBytes(16)); + String var10001 = RandomUtil.randomString(16); + return var10000.encryptBase64(var10001 + data); + } + + public static String encryptBySm4WithServerKey(String data) { + return encryptBySm4(data, secureProperties.getSecurity().getServerSm4KeyBytes()); + } + + public static void main(String[] args) throws NoSuchAlgorithmException { + sm2(); + sm4(); + sm4WithoutIV(); + } + + private static void sm2() { + System.out.println("=================sm2==================="); + String privateKeyStr = "MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgCtqk5Jj7pPWh91d9mPA4Kd7fOfzBULrnAERNDV+4XBCgCgYIKoEcz1UBgi2hRANCAARykhB6sXHWTbB60Pr+laPqEP5JBRpEcySONKKP5Q03o/g3OpnQXc7aVMdLUxL8wD1wQHEu4KHmHQr7jvVt0rkM"; + String pubKeyStr = "MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEcpIQerFx1k2wetD6/pWj6hD+SQUaRHMkjjSij+UNN6P4NzqZ0F3O2lTHS1MS/MA9cEBxLuCh5h0K+471bdK5DA=="; + SM2 sm2 = SmUtil.sm2("MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgCtqk5Jj7pPWh91d9mPA4Kd7fOfzBULrnAERNDV+4XBCgCgYIKoEcz1UBgi2hRANCAARykhB6sXHWTbB60Pr+laPqEP5JBRpEcySONKKP5Q03o/g3OpnQXc7aVMdLUxL8wD1wQHEu4KHmHQr7jvVt0rkM", "MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEcpIQerFx1k2wetD6/pWj6hD+SQUaRHMkjjSij+UNN6P4NzqZ0F3O2lTHS1MS/MA9cEBxLuCh5h0K+471bdK5DA=="); + String data = "liolay"; + byte[] encrypt = sm2.encrypt("liolay".getBytes(StandardCharsets.UTF_8)); + System.out.println("encrypt:" + Base64Encoder.encode(encrypt)); + PrintStream var10000 = System.out; + byte[] var10001 = sm2.sign(data.getBytes(StandardCharsets.UTF_8)); + var10000.println("sign:" + Base64Encoder.encode(var10001)); + var10000 = System.out; + String var5 = new String(sm2.decrypt(encrypt)); + var10000.println("decrypt:" + var5); + } + + private static void sm4() throws NoSuchAlgorithmException { + System.out.println("================sm4=================="); + BouncyCastleProvider provider = new BouncyCastleProvider(); + KeyGenerator generator = KeyGenerator.getInstance("SM4", provider); + SecretKey secretKey = generator.generateKey(); + byte[] encoded = secretKey.getEncoded(); + String key = Base64Encoder.encode(encoded); + System.out.println("key: " + key); + String data = "liolay"; + String encryptBySm4 = encryptBySm4(data, encoded); + System.out.println("encrypt: " + encryptBySm4); + PrintStream var10000 = System.out; + String var10001 = decryptBySm4(encryptBySm4, encoded); + var10000.println("decrypt: " + var10001); + var10000 = System.out; + var10001 = decryptBySm4(encryptBySm4, key); + var10000.println("decrypt: " + var10001); + } + + private static void sm4WithoutIV() throws NoSuchAlgorithmException { + System.out.println("================sm4WithoutIV=================="); + BouncyCastleProvider provider = new BouncyCastleProvider(); + KeyGenerator generator = KeyGenerator.getInstance("SM4", provider); + SecretKey secretKey = generator.generateKey(); + byte[] key = secretKey.getEncoded(); + String keyEncode = Base64Encoder.encode(key); + System.out.println("key: " + keyEncode); + String plainData = "liolay"; + String encryptedData = encryptBySm4(plainData, key); + System.out.println("encrypt: " + encryptedData); + String decryptData = decryptBySm4(encryptedData, key); + System.out.println("decrypt: " + decryptData); + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/mq/MacMessageService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/mq/MacMessageService.java new file mode 100644 index 00000000..71beb029 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/mq/MacMessageService.java @@ -0,0 +1,17 @@ +package com.bonus.canteen.core.device.mq; + +import com.bonus.canteen.core.device.manage.controller.deprecated.vo.MessageConfigVO; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +@Service +public class MacMessageService { + @Value("${system.mqtt-tcp-address:}") + private String mqClientAddress; + @Value("${system.mqtt-websocket-address:}") + private String mqWebClientAddress; + + public MessageConfigVO getMessageConfig() { + return new MessageConfigVO(this.mqClientAddress, this.mqWebClientAddress); + } +}