From 2206ea32c14191676ae99e9ae2921ecd4e7f3863 Mon Sep 17 00:00:00 2001 From: yuanye <418471657@qq.com> Date: Mon, 9 Dec 2024 11:11:00 +0800 Subject: [PATCH] /1 --- .../main/java/com/bweb/config/AuthConfig.java | 1 + .../com/bweb/controller/TestController.java | 39 +++++++ .../bweb/controller/api/ApiMerController.java | 68 ++++++++++++ .../src/main/resources/prod/application.yml | 4 +- .../controller/notify/MeiTuanController.java | 16 ++- .../main/java/com/hfkj/api/ApiMerService.java | 68 ++++++++++++ .../com/hfkj/api/impl/ApiMerServiceImpl.java | 68 ++++++++++++ .../com/hfkj/service/user/BsUserService.java | 1 + .../service/user/impl/BsUserServiceImpl.java | 28 +++++ .../com/hfkj/sysenum/UserLoginPlatform.java | 1 + .../java/com/hfkj/sysenum/UserLoginType.java | 1 + .../com/user/controller/BsUserController.java | 105 +++++++++++------- 12 files changed, 354 insertions(+), 46 deletions(-) create mode 100644 bweb/src/main/java/com/bweb/controller/api/ApiMerController.java create mode 100644 service/src/main/java/com/hfkj/api/ApiMerService.java create mode 100644 service/src/main/java/com/hfkj/api/impl/ApiMerServiceImpl.java diff --git a/bweb/src/main/java/com/bweb/config/AuthConfig.java b/bweb/src/main/java/com/bweb/config/AuthConfig.java index 48cc9e7..52b84aa 100644 --- a/bweb/src/main/java/com/bweb/config/AuthConfig.java +++ b/bweb/src/main/java/com/bweb/config/AuthConfig.java @@ -89,6 +89,7 @@ public class AuthConfig implements WebMvcConfigurer { .excludePathPatterns("/fileUpload/*") .excludePathPatterns("/common/*") .excludePathPatterns("/test/*") + .excludePathPatterns("/apiMer/*") .excludePathPatterns("/secMenu/queryMenuList") .excludePathPatterns("/user/phgDataUser") .excludePathPatterns("/user/phgDataUserDetail") diff --git a/bweb/src/main/java/com/bweb/controller/TestController.java b/bweb/src/main/java/com/bweb/controller/TestController.java index d1fa36f..6dfb830 100644 --- a/bweb/src/main/java/com/bweb/controller/TestController.java +++ b/bweb/src/main/java/com/bweb/controller/TestController.java @@ -450,6 +450,24 @@ public class TestController { } } + @RequestMapping(value="/queryHltBalance",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询工会卡余额") + public ResponseData queryHltBalance(@RequestParam(value = "cardNo", required = false) String cardNo) { + try { + + JSONObject cardInfo = HuiLianTongUnionCardService.queryBalance(cardNo); + if (StringUtils.isBlank(cardInfo.getString("data"))) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请求失败"); + } + return ResponseMsgUtil.success(HuiLianTongUnionCardService.resolveResponse(cardInfo.getString("data"))); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + @RequestMapping(value="/getGoodsUpdate",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "更新商品") @@ -478,4 +496,25 @@ public class TestController { return ResponseMsgUtil.exception(e); } } + + + @RequestMapping(value="/phgSignLogin",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "加密登陆") + public ResponseData phgSignLogin() { + try { + + Map map = new HashMap<>(); + map.put("appid" , "20241266600"); + map.put("phone" , "18390580471"); + map.put("sign" , SignatureUtil.createSign(map , "BCB83776BDA7F609FBE99BBB8AC33840")); + map.put("platform" , "HIGH"); + map.put("type" , "HIGH_SIGN"); + return ResponseMsgUtil.success( HttpsUtils.doPost("http://localhost:9704/user/client/phgSignLogin" , map , new HashMap<>())); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } } diff --git a/bweb/src/main/java/com/bweb/controller/api/ApiMerController.java b/bweb/src/main/java/com/bweb/controller/api/ApiMerController.java new file mode 100644 index 0000000..7f8671a --- /dev/null +++ b/bweb/src/main/java/com/bweb/controller/api/ApiMerController.java @@ -0,0 +1,68 @@ +package com.bweb.controller.api; + +import com.hfkj.api.ApiMerService; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.common.utils.DateUtil; +import com.hfkj.common.utils.IDGenerator; +import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.common.utils.WxUtils; +import com.hfkj.entity.ApiMer; +import com.hfkj.model.ResponseData; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +import java.util.Date; + + +@Controller +@RequestMapping(value = "/apiMer") +@Api(value = "api商户") +public class ApiMerController { + + Logger log = LoggerFactory.getLogger(ApiMerController.class); + + @Resource + private ApiMerService apiMerService; + + @RequestMapping(value="/insertMerchant",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "增加商户") + public ResponseData insertMer(@RequestBody ApiMer apiMer) { + try { + + + if (StringUtils.isBlank(apiMer.getMerName()) + || StringUtils.isBlank(apiMer.getContact()) + || StringUtils.isBlank(apiMer.getContactPhone()) + ) { + log.error("ApiMerchantsController -> insertMerchant() error!","参数错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + apiMer.setCreateTime(new Date()); + apiMer.setUpdateTime(new Date()); + apiMer.setStatus(1); + apiMer.setAppId(DateUtil.date2String(new Date(), "yyyyMM") + IDGenerator.nextId(5)); + apiMer.setAppSecret(WxUtils.MD5(apiMer.getAppId() , true)); + apiMerService.create(apiMer); + + return ResponseMsgUtil.success("新增成功"); + } catch (Exception e) { + log.error("ApiMerchantsController -> insertMerchant() error!",e); + return ResponseMsgUtil.exception(e); + } + } + + + +} diff --git a/openapi/src/main/resources/prod/application.yml b/openapi/src/main/resources/prod/application.yml index 300889c..40f8e3b 100644 --- a/openapi/src/main/resources/prod/application.yml +++ b/openapi/src/main/resources/prod/application.yml @@ -1,7 +1,7 @@ server: - port: 9301 + port: 9505 servlet: - context-path: /crest + context-path: /openapi #配置是否为debug模式,debug模式下,不开启权限校验 debug: false diff --git a/order/src/main/java/com/order/controller/notify/MeiTuanController.java b/order/src/main/java/com/order/controller/notify/MeiTuanController.java index 8a0da23..785cddb 100644 --- a/order/src/main/java/com/order/controller/notify/MeiTuanController.java +++ b/order/src/main/java/com/order/controller/notify/MeiTuanController.java @@ -5,6 +5,7 @@ import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; import com.hfkj.common.utils.OrderUtil; +import com.hfkj.common.utils.SignatureUtil; import com.hfkj.config.CommonSysConst; import com.hfkj.entity.BsOrderMeituan; import com.hfkj.entity.BsOrderRefund; @@ -103,11 +104,22 @@ public class MeiTuanController { JSONObject staffInfo = jsonObject.getJSONObject("staffInfo"); + // 请求加密 + Map map = new HashMap<>(); + map.put("appid" , "20241266600"); + map.put("phone" , staffInfo.getString("staffPhone")); + String sign = SignatureUtil.createSign(map , "BCB83776BDA7F609FBE99BBB8AC33840"); + object.put("thirdTradeNo", thirdTradeNo); object.put("thirdPayUrl", "https://phg.dctpay.com/cweb/#/pages/meiTuanPay/index?tradeNo=" + jsonObject.getString("tradeNo") + "&tradeAmount=" + jsonObject.getString("tradeAmount") + - "&outSidePhone=" + staffInfo.getString("staffPhone") - ); + "&outSideAppid=" + map.get("appid") + + "&outSideSign=" + sign + + "&outSidePhone=" + staffInfo.getString("staffPhone") + + "&outsidePlatform=" + "WXAPPLETS" + + "&outSideType=" + "SIGN" + ); + log.info("美团下单-参数: {}", object); data.put("status", 0); data.put("msg", "成功"); diff --git a/service/src/main/java/com/hfkj/api/ApiMerService.java b/service/src/main/java/com/hfkj/api/ApiMerService.java new file mode 100644 index 0000000..b13ebbc --- /dev/null +++ b/service/src/main/java/com/hfkj/api/ApiMerService.java @@ -0,0 +1,68 @@ +package com.hfkj.api; + +import com.hfkj.entity.ApiMer; + +import java.util.List; + +public interface ApiMerService { + + /** + * @MethodName create + * @Description: 创建api商户 + * @param apiMer + * @Author: Sum1Dream + * @Date: 2024/12/5 下午3:19 + */ + void create(ApiMer apiMer); + + /** + * @MethodName update + * @Description: /** + * @Description: 更新api商户 + * @param apiMer + * @Author: Sum1Dream + * @Date: 2024/12/5 下午3:19 + */ + void update(ApiMer apiMer); + + /** + * @MethodName delete + * @Description: 删除api商户 + * @param id + * @param fullDelete + * @Author: Sum1Dream + * @Date: 2024/12/5 下午3:19 + */ + void delete(Long id , Boolean fullDelete); + + /** + * @MethodName queryDetail + * @Description: 查询api商户详情 + * @param id + * @return: com.hfkj.entity.ApiMer + * @Author: Sum1Dream + * @Date: 2024/12/5 下午3:19 + */ + ApiMer queryDetail(Long id); + + /** + * @MethodName queryDetail + * @Description: 根据appId查询商户 + * @param appId + * @return: com.hfkj.entity.ApiMer + * @Author: Sum1Dream + * @Date: 2024/12/5 下午3:20 + */ + ApiMer queryDetail(String appId); + + /** + * @MethodName queryList + * @Description: 查询api商户列表 + * @param apiMer + * @return: java.util.List + * @Author: Sum1Dream + * @Date: 2024/12/5 下午3:20 + */ + List queryList(ApiMer apiMer); + +} diff --git a/service/src/main/java/com/hfkj/api/impl/ApiMerServiceImpl.java b/service/src/main/java/com/hfkj/api/impl/ApiMerServiceImpl.java new file mode 100644 index 0000000..fd711ba --- /dev/null +++ b/service/src/main/java/com/hfkj/api/impl/ApiMerServiceImpl.java @@ -0,0 +1,68 @@ +package com.hfkj.api.impl; + +import com.hfkj.api.ApiMerService; +import com.hfkj.dao.ApiMerMapper; +import com.hfkj.entity.ApiMer; +import com.hfkj.entity.ApiMerExample; +import com.hfkj.entity.BsOrderGoods; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Collections; +import java.util.Date; +import java.util.List; + +@Service("apiMerService") +public class ApiMerServiceImpl implements ApiMerService { + + @Resource + private ApiMerMapper apiMerMapper; + + @Override + public void create(ApiMer apiMer) { + apiMerMapper.insert(apiMer); + } + + @Override + public void update(ApiMer apiMer) { + apiMerMapper.updateByPrimaryKey(apiMer); + } + + @Override + public void delete(Long id, Boolean fullDelete) { + if (fullDelete) { + apiMerMapper.deleteByPrimaryKey(id); + } else { + ApiMer apiMer = queryDetail(id); + apiMer.setStatus(0); + apiMer.setUpdateTime(new Date()); + update(apiMer); + } + } + + @Override + public ApiMer queryDetail(Long id) { + return apiMerMapper.selectByPrimaryKey(id); + } + + @Override + public ApiMer queryDetail(String appId) { + ApiMerExample example = new ApiMerExample(); + ApiMerExample.Criteria criteria = example.createCriteria(); + + criteria.andAppIdEqualTo(appId).andStatusEqualTo(1); + + List list = apiMerMapper.selectByExample(example); + + if (!list.isEmpty()) { + return list.get(0); + } + + return null; + } + + @Override + public List queryList(ApiMer apiMer) { + return Collections.emptyList(); + } +} diff --git a/service/src/main/java/com/hfkj/service/user/BsUserService.java b/service/src/main/java/com/hfkj/service/user/BsUserService.java index 8156d14..e637944 100644 --- a/service/src/main/java/com/hfkj/service/user/BsUserService.java +++ b/service/src/main/java/com/hfkj/service/user/BsUserService.java @@ -113,6 +113,7 @@ public interface BsUserService { */ SessionObject login(UserLoginPlatform platform, UserLoginType loginType, String outsideOpenid, Map other) throws Exception; + SessionObject signLogin(UserLoginPlatform platform, UserLoginType loginType, String phone) throws Exception; /** * 退出登录 * @param token diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java index 01a257c..feb4cc5 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java @@ -30,6 +30,7 @@ import org.springframework.web.context.request.RequestContextHolder; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -238,6 +239,33 @@ public class BsUserServiceImpl implements BsUserService { return sessionObject; } + @Override + public SessionObject signLogin(UserLoginPlatform platform, UserLoginType loginType, String phone) throws Exception { + // 查询用户 + BsUser user = getUser(phone); + if (user == null) { + user = register(phone, null , new HashMap<>()); + } + + // 缓存 + UserSessionObject session = new UserSessionObject(); + session.setUser(user); + + // 查询汇联通工会卡 + List hltCardList = userCardService.getCardList(user.getId(), UserCardTypeEnum.type1); + if (hltCardList.isEmpty()) { + session.setHltCardBind(false); + } else { + session.setHltCardBind(true); + session.setHltCard(hltCardList.get(0)); + } + SessionObject sessionObject = new SessionObject(token(user), session); + userCenter.save(sessionObject); + // 异步记录登录信息 + userLoginLogService.asyncCreateLog(platform, loginType, user, (HttpServletRequest) RequestContextHolder.getRequestAttributes().resolveReference(RequestAttributes.REFERENCE_REQUEST)); + return sessionObject; + } + @Override public void loginOut(String token) { userCenter.remove(token); diff --git a/service/src/main/java/com/hfkj/sysenum/UserLoginPlatform.java b/service/src/main/java/com/hfkj/sysenum/UserLoginPlatform.java index 355630c..ba81a98 100644 --- a/service/src/main/java/com/hfkj/sysenum/UserLoginPlatform.java +++ b/service/src/main/java/com/hfkj/sysenum/UserLoginPlatform.java @@ -13,6 +13,7 @@ public enum UserLoginPlatform { WXAPPLETS("WXAPPLETS", "普汇GO"), VFAMILY("VFAMILY", "V家园"), GZGOV("GZGOV", "省自机关"), + HIGH("HIGH", "嗨加油"), ; private String code; diff --git a/service/src/main/java/com/hfkj/sysenum/UserLoginType.java b/service/src/main/java/com/hfkj/sysenum/UserLoginType.java index 37deecb..dbbb142 100644 --- a/service/src/main/java/com/hfkj/sysenum/UserLoginType.java +++ b/service/src/main/java/com/hfkj/sysenum/UserLoginType.java @@ -16,6 +16,7 @@ public enum UserLoginType { WECHAT_MP_OPENID("WECHAT_MP_OPENID", "微信公众号openId"), V_FAMILY_OPENID("V_FAMILY_OPENID", "V家园openId"), GZ_GOV_OPENID("GZ_GOV_OPENID", "省自机关openId"), + SIGN("SIGN", "加密登陆"), ; private String code; diff --git a/user/src/main/java/com/user/controller/BsUserController.java b/user/src/main/java/com/user/controller/BsUserController.java index e502ca7..5148713 100644 --- a/user/src/main/java/com/user/controller/BsUserController.java +++ b/user/src/main/java/com/user/controller/BsUserController.java @@ -3,12 +3,15 @@ package com.user.controller; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import com.alibaba.fastjson.JSONObject; +import com.hfkj.api.ApiMerService; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; import com.hfkj.common.security.UserCenter; import com.hfkj.common.utils.*; +import com.hfkj.config.CommonSysConst; import com.hfkj.config.WxMaConfig; +import com.hfkj.entity.ApiMer; import com.hfkj.entity.BsUser; import com.hfkj.entity.BsUserComplaint; import com.hfkj.model.ResponseData; @@ -54,6 +57,8 @@ public class BsUserController { private RedisUtil redisUtil; @Resource private BsUserComplaintService userComplaintService; + @Resource + private ApiMerService apiMerService; @RequestMapping(value = "/phone", method = RequestMethod.POST) @ResponseBody @@ -156,48 +161,64 @@ public class BsUserController { } } -// @RequestMapping(value = "/phoneNotVerify", method = RequestMethod.POST) -// @ResponseBody -// @ApiOperation(value = "H5手机号不校验登陆") -// public ResponseData phoneNotVerify(@RequestBody JSONObject body) { -// try { -// if (body == null -// || StringUtils.isBlank(body.getString("platform")) -// || StringUtils.isBlank(body.getString("type")) -// || StringUtils.isBlank(body.getString("phone")) -// ) { -// log.error("LoginController --> phone() error!", "请求参数校验失败"); -// throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); -// } -// String phone = body.getString("phone"); -// String password = body.getString("password"); -// -// // 客户端 -// UserLoginPlatform platform = UserLoginPlatform.getDataByType(body.getString("platform")); -// if (platform == null) { -// log.error("LoginController --> phone() error!", "未知客户端"); -// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知客户端"); -// } -// // 校验手机号格式 -// if (!MemberValidateUtil.validatePhone(phone)) { -// log.error("LoginController --> phone() error!", "请输入正确的手机号"); -// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号"); -// } -// // 登录类型 -// UserLoginType loginType = UserLoginType.getDataByType(body.getString("type")); -// if (loginType == null) { -// log.error("LoginController --> phone() error!", "未知登录类型;" + body.getString("type")); -// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知登录类型"); -// } -// -// Map other = new HashMap<>(); -// return ResponseMsgUtil.success(userService.login(platform, loginType, phone, password, other)); -// -// } catch (Exception e) { -// log.error("LoginController --> phone() error!", e); -// return ResponseMsgUtil.exception(e); -// } -// } + @RequestMapping(value = "/phgSignLogin", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "普惠go加密登陆") + public ResponseData phgSignLogin(@RequestBody JSONObject body) { + try { + if (body == null + || StringUtils.isBlank(body.getString("platform")) + || StringUtils.isBlank(body.getString("type")) + || StringUtils.isBlank(body.getString("phone")) + || StringUtils.isBlank(body.getString("sign")) + || StringUtils.isBlank(body.getString("appid")) + ) { + log.error("LoginController --> phone() error!", "请求参数校验失败"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + String phone = body.getString("phone"); + + // 客户端 + UserLoginPlatform platform = UserLoginPlatform.getDataByType(body.getString( "platform")); + if (platform == null) { + log.error("LoginController --> phone() error!", "未知客户端"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知客户端"); + } + // 校验手机号格式 + if (!MemberValidateUtil.validatePhone(phone)) { + log.error("LoginController --> phone() error!", "请输入正确的手机号"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号"); + } + // 登录类型 + UserLoginType loginType = UserLoginType.getDataByType(body.getString("type")); + + if (loginType == null) { + log.error("LoginController --> phone() error!", "未知登录类型;" + body.getString("type")); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知登录类型"); + } + + // 校验签名 + // 查询api商户信息 + ApiMer apiMer = apiMerService.queryDetail(body.getString("appid")); + if (apiMer == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户不存在"); + } + Map map = new HashMap<>(); + map.put("appid" , body.getString("appid")); + map.put("phone" , body.getString("phone")); + String sign = SignatureUtil.createSign(map , apiMer.getAppSecret()); + if (!body.getString("sign").equals(sign)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "签名校验失败!"); + } + + + return ResponseMsgUtil.success(userService.signLogin(platform, loginType, phone)); + + } catch (Exception e) { + log.error("LoginController --> phone() error!", e); + return ResponseMsgUtil.exception(e); + } + } @RequestMapping(value = "/phoneTest", method = RequestMethod.POST) @ResponseBody