diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighMerchantStoreController.java b/hai-bweb/src/main/java/com/bweb/controller/HighMerchantStoreController.java index 87167f9e..b91ff548 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighMerchantStoreController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighMerchantStoreController.java @@ -128,6 +128,9 @@ public class HighMerchantStoreController { if (highMerchantStore.getType().equals(1) && StringUtils.isBlank(highMerchantStore.getStoreLogo())) { highMerchantStore.setStoreLogo(CommonSysConst.getSysConfig().getGasDefaultOilStationImg()); } + if (highMerchantStore.getSourceType() == 7) { + highMerchantStore.setStoreLogo(CommonSysConst.getSysConfig().getFileUrl() + highMerchantStore.getStoreLogo()); + } highMerchantStore.setCreateTime(new Date()); highMerchantStore.setUpdateTime(new Date()); highMerchantStore.setStatus(1); // 状态:0:删除,1:正常 diff --git a/hai-cweb/src/main/java/com/cweb/controller/CommonController.java b/hai-cweb/src/main/java/com/cweb/controller/CommonController.java index 5c597cb1..9fa2af46 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/CommonController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/CommonController.java @@ -517,7 +517,8 @@ public class CommonController { JSONObject object = new JSONObject(); - object.put("userLeve" , highUserService.findUserLevel(userId)); + object.put("userLeve" , new JSONObject()); +// object.put("userLeve" , highUserService.findUserLevel(userId)); object.put("price" , commonService.findSecConfigByType("LEVEL_PRICE").getCodeValue()); return ResponseMsgUtil.success(object); diff --git a/hai-service/src/main/java/com/hai/dao/HighTyAgentOilStationMapperExt.java b/hai-service/src/main/java/com/hai/dao/HighTyAgentOilStationMapperExt.java index 85ef6f8d..9df364df 100644 --- a/hai-service/src/main/java/com/hai/dao/HighTyAgentOilStationMapperExt.java +++ b/hai-service/src/main/java/com/hai/dao/HighTyAgentOilStationMapperExt.java @@ -30,7 +30,8 @@ public interface HighTyAgentOilStationMapperExt { " b.ty_salesman_id tySalesmanId," + " b.ty_salesman_name tySalesmanName," + " b.oil_station_id oilStationId," + - " b.oil_station_name oilStationName" + + " b.oil_station_name oilStationName," + + " a.source_type sourceType" + " from high_merchant_store a" + " LEFT JOIN high_ty_agent_oil_station b on a.id = b.oil_station_id and b.`status` = 1" + " where a.type = 1 and a.`status` = 1" + diff --git a/hai-service/src/main/java/com/hai/model/TyAgentOilStationModel.java b/hai-service/src/main/java/com/hai/model/TyAgentOilStationModel.java index 4c541b5d..82e414bf 100644 --- a/hai-service/src/main/java/com/hai/model/TyAgentOilStationModel.java +++ b/hai-service/src/main/java/com/hai/model/TyAgentOilStationModel.java @@ -1,5 +1,8 @@ package com.hai.model; +import lombok.Data; + +@Data public class TyAgentOilStationModel { private Long storeId; @@ -15,135 +18,9 @@ public class TyAgentOilStationModel { private Long tyAgentId; private String tyAgentName; private Long tySalesmanId; + private Integer sourceType; private String tySalesmanName; private Long oilStationId; private String oilStationName; - public Long getTyAgentOilStationId() { - return tyAgentOilStationId; - } - - public void setTyAgentOilStationId(Long tyAgentOilStationId) { - this.tyAgentOilStationId = tyAgentOilStationId; - } - - public Long getStoreId() { - return storeId; - } - - public void setStoreId(Long storeId) { - this.storeId = storeId; - } - - public Long getRegionId() { - return regionId; - } - - public void setRegionId(Long regionId) { - this.regionId = regionId; - } - - public String getRegionName() { - return regionName; - } - - public void setRegionName(String regionName) { - this.regionName = regionName; - } - - public String getStoreLogo() { - return storeLogo; - } - - public void setStoreLogo(String storeLogo) { - this.storeLogo = storeLogo; - } - - public String getStoreKey() { - return storeKey; - } - - public void setStoreKey(String storeKey) { - this.storeKey = storeKey; - } - - public String getStoreName() { - return storeName; - } - - public void setStoreName(String storeName) { - this.storeName = storeName; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public Long getOrganizationId() { - return organizationId; - } - - public void setOrganizationId(Long organizationId) { - this.organizationId = organizationId; - } - - public String getOrganizationName() { - return organizationName; - } - - public void setOrganizationName(String organizationName) { - this.organizationName = organizationName; - } - - public Long getTyAgentId() { - return tyAgentId; - } - - public void setTyAgentId(Long tyAgentId) { - this.tyAgentId = tyAgentId; - } - - public String getTyAgentName() { - return tyAgentName; - } - - public void setTyAgentName(String tyAgentName) { - this.tyAgentName = tyAgentName; - } - - public Long getTySalesmanId() { - return tySalesmanId; - } - - public void setTySalesmanId(Long tySalesmanId) { - this.tySalesmanId = tySalesmanId; - } - - public String getTySalesmanName() { - return tySalesmanName; - } - - public void setTySalesmanName(String tySalesmanName) { - this.tySalesmanName = tySalesmanName; - } - - public Long getOilStationId() { - return oilStationId; - } - - public void setOilStationId(Long oilStationId) { - this.oilStationId = oilStationId; - } - - public String getOilStationName() { - return oilStationName; - } - - public void setOilStationName(String oilStationName) { - this.oilStationName = oilStationName; - } } diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java index 9ae858a3..b898954e 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java @@ -575,8 +575,18 @@ public class OrderCreateHandleServiceImpl implements OrderCreateHandleService { gasOrderService.addGasOrder(gasOrder); if (store.getSourceType() == 7 ){ + + + SecConfig secConfig = secConfigService.findByCodeType(store.getId().toString()); + + if (secConfig == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "系统维护中,请联系工作人员!"); + } + + BigDecimal price = gasOrder.getGasRefuelPrice().multiply(new BigDecimal(secConfig.getCodeValue())).divide(new BigDecimal(100)); + HighOilCardOrder oilCardOrder = new HighOilCardOrder(); - oilCardOrder.setPrice(priceModel.getPayPrice()); + oilCardOrder.setPrice(price); oilCardOrder.setCardNo(createOrderChild.getOilCardNo()); oilCardOrder.setOrderNo(createOrderModel.getOrderNo()); oilCardOrder.setThirdOrderNo("HF" + OrderUtil.generateOrderNo()); @@ -606,7 +616,7 @@ public class OrderCreateHandleServiceImpl implements OrderCreateHandleService { log.error("HighOrderController --> addOrder() error!", ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "库存数量不足"); } - if (discountPackage.getPurchaseNum() < discountPackageActualService.userPurchaseByUserId(createOrderChild.getMemId().intValue(), discountPackage.getId())) { + if (discountPackage.getPurchaseNum() <= discountPackageActualService.userPurchaseByUserId(createOrderChild.getMemId().intValue(), discountPackage.getId())) { log.error("HighOrderController --> addOrder() error!", ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "超过购买限制"); } diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java index 3d90354e..0edc2b3a 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderPaySuccessServiceImpl.java @@ -131,6 +131,9 @@ public class OrderPaySuccessServiceImpl implements OrderPaySuccessService { @Resource private GroupCodeService groupCodeService; + @Resource + private SecConfigService secConfigService; + @Override public HighOrder orderPaySuccessHandle(String orderNo, OrderPayType payType, String paySerialNo, BigDecimal payRealPrice, HighUserCard userCard, Map other) { diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java index 00384d5a..6c3c184a 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderServiceImpl.java @@ -168,7 +168,7 @@ public class OrderServiceImpl implements OrderService { BsDistributionUserRel popularizeUser = bsDistributionUserRelService.findDistributionUserRel(mapUser); if (popularizeUser != null && createOrderModel.getMemId() != null) { - order.setPromoteCode(popularizeUser.getAgentId().toString()); + order.setPromoteCode(popularizeUser.getAgentId()==null ? "暂无" : "" + popularizeUser.getAgentId()); } } diff --git a/hai-service/src/main/java/com/hai/service/HighStoreUserService.java b/hai-service/src/main/java/com/hai/service/HighStoreUserService.java new file mode 100644 index 00000000..3aff9a52 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/HighStoreUserService.java @@ -0,0 +1,62 @@ +package com.hai.service; + +import com.hai.entity.HighChildOrder; +import com.hai.entity.HighOrder; +import com.hai.entity.HighStoreUser; + +import java.util.List; +import java.util.Map; + +/** + * @serviceName .java + * @author Sum1Dream + * @version 1.0.0 + * @Description // 门店用户绑定 + * @createTime 10:29 2023/11/27 + **/ +public interface HighStoreUserService { + + /** + * @Author Sum1Dream + * @Name insertStoreUser + * @Description // 新增 + * @Date 10:37 2023/11/27 + * @Param storeUser + * @return void + */ + void insertStoreUser(HighStoreUser storeUser); + + /** + * @Author Sum1Dream + * @Name updateStoreUser + * @Description // 更新 + * @Date 10:37 2023/11/27 + * @Param storeUser + * @return void + */ + void updateStoreUser(HighStoreUser storeUser); + + /** + * @Author Sum1Dream + * @Name findStoreUser + * @Description // 查询详情 + * @Date 10:37 2023/11/27 + * @Param map + * @return com.hai.entity.HighStoreUser + */ + HighStoreUser findStoreUser(Map map); + + /** + * @Author Sum1Dream + * @Name getStoreUserList + * @Description // 查询列表 + * @Date 10:37 2023/11/27 + * @Param map + * @return java.util.List + */ + List getStoreUserList(Map map); + + void storeUserRel(Long userId, Long storeId); + + +} diff --git a/hai-service/src/main/java/com/hai/service/impl/HighStoreUserServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighStoreUserServiceImpl.java new file mode 100644 index 00000000..fd13d75e --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/impl/HighStoreUserServiceImpl.java @@ -0,0 +1,103 @@ +package com.hai.service.impl; + +import com.hai.dao.HighStoreUserMapper; +import com.hai.entity.HighMerchantStore; +import com.hai.entity.HighStoreUser; +import com.hai.entity.HighStoreUserExample; +import com.hai.entity.HighUser; +import com.hai.service.HighMerchantStoreService; +import com.hai.service.HighStoreUserService; +import com.hai.service.HighUserService; +import org.apache.commons.collections4.MapUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service("highStoreUserService") +public class HighStoreUserServiceImpl implements HighStoreUserService { + + @Resource + private HighStoreUserMapper highStoreUserMapper; + + @Resource + private HighMerchantStoreService highMerchantStoreService; + + @Resource + private HighUserService highUserService; + + @Override + public void insertStoreUser(HighStoreUser storeUser) { + highStoreUserMapper.insert(storeUser); + } + + @Override + public void updateStoreUser(HighStoreUser storeUser) { + highStoreUserMapper.updateByPrimaryKey(storeUser); + } + + @Override + public HighStoreUser findStoreUser(Map map) { + HighStoreUserExample example = new HighStoreUserExample(); + HighStoreUserExample.Criteria criteria = example.createCriteria(); + + if (MapUtils.getLong(map, "userId") != null) { + criteria.andUserIdEqualTo(MapUtils.getLong(map, "userId")); + } + + List list = highStoreUserMapper.selectByExample(example); + + if (!list.isEmpty()) { + return list.get(0); + } + + + return null; + } + + @Override + public List getStoreUserList(Map map) { + HighStoreUserExample example = new HighStoreUserExample(); + HighStoreUserExample.Criteria criteria = example.createCriteria(); + + if (MapUtils.getLong(map, "userId") != null) { + criteria.andUserIdEqualTo(MapUtils.getLong(map, "userId")); + } + if (MapUtils.getLong(map, "storeId") != null) { + criteria.andUserIdEqualTo(MapUtils.getLong(map, "storeId")); + } + return highStoreUserMapper.selectByExample(example); + } + + @Override + public void storeUserRel(Long userId, Long storeId) { + Map map = new HashMap<>(); + map.put("userId" , userId); + + HighStoreUser storeUser = findStoreUser(map); + + if (storeUser == null) { + + HighMerchantStore merchantStore = highMerchantStoreService.getMerchantStoreById(storeId); + HighUser highUser = highUserService.findByUserId(userId); + + if (merchantStore != null && highUser != null) { + storeUser = new HighStoreUser(); + storeUser.setStoreName(merchantStore.getStoreName()); + storeUser.setStoreId(storeId); + storeUser.setUserPhone(highUser.getPhone()); + storeUser.setUserName(highUser.getName()); + storeUser.setCreateTime(new Date()); + storeUser.setUpdateTime(new Date()); + storeUser.setStatus(1); + + insertStoreUser(storeUser); + } + + } + + } +} diff --git a/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java index 237cd41c..980c30a7 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java @@ -82,6 +82,9 @@ public class HighUserServiceImpl implements HighUserService { @Resource private HighUserLoginLogMapper userLoginLogMapper; + @Resource + private HighStoreUserService highStoreUserService; + @Override @Transactional(propagation = Propagation.REQUIRES_NEW, timeout = 30, rollbackFor = Exception.class) public SessionObject loginAndRegister(LoginPlatform platform,String phone, Long popularizeUserId, Map other,HttpServletRequest request, HttpServletResponse response) throws Exception { @@ -126,6 +129,7 @@ public class HighUserServiceImpl implements HighUserService { } SecRegion region = commonService.getRegionsByName(loginLog.getProvinceName()); +// highStoreUserService.storeUserRel(user.getId() , MapUtils.getLong(other, "storeId")); // distributionUserRelService.insertDistributionRebate(user.getId(), popularizeUserId, "500000"); if (region != null) { // 绑定推广关联关系 diff --git a/hai-user/src/main/java/com/web/controller/LoginController.java b/hai-user/src/main/java/com/web/controller/LoginController.java index 9ffb1595..099e5a99 100644 --- a/hai-user/src/main/java/com/web/controller/LoginController.java +++ b/hai-user/src/main/java/com/web/controller/LoginController.java @@ -1 +1 @@ -package com.web.controller; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.security.UserCenter; import com.hai.common.utils.*; import com.hai.config.UnionUserConfig; import com.hai.config.WxMaConfiguration; import com.hai.entity.HighUser; import com.hai.enum_type.LoginPlatform; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; import com.hai.service.HighUserService; import com.web.type.LoginType; import com.hai.enum_type.RedisFileFolder; 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 javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/login") @Api(value = "登录业务") public class LoginController { private static Logger log = LoggerFactory.getLogger(LoginController.class); @Resource private RedisUtil redisUtil; @Resource private HighUserService userService; @Resource private UserCenter userCenter; @Resource private WxMaConfiguration wxMaConfiguration; @Resource private UnionUserConfig unionUserConfig; @RequestMapping(value = "/phone", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "手机号登录") public ResponseData phone(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) { 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"); // 客户端 LoginPlatform platform = LoginPlatform.getDataByType(body.getString("platform")); if (platform == null) { log.error("LoginController --> phone() error!", "未知客户端"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知客户端"); } // 校验手机号格式 if (MemberValidateUtil.validatePhone(phone) == false) { log.error("LoginController --> phone() error!", "请输入正确的手机号"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号"); } // 登录类型 LoginType loginType = LoginType.getDataByType(body.getString("type")); if (loginType == null) { log.error("LoginController --> phone() error!", "未知登录类型;" + body.getString("type")); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知登录类型"); } if (body.getString("type").equals(LoginType.SMS.getCode())) { if (StringUtils.isBlank(body.getString("smsCode"))) { log.error("LoginController --> phone() error!", "请输入短信验证码"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入短信验证码"); } // 手机号的验证码 Object phoneCodeObject = redisUtil.get(RedisFileFolder.SMS_CODE.getCode() + phone); if (phoneCodeObject == null) { log.error("LoginController --> phone() error!", "短信验证码错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信验证码错误"); } if (!body.getString("smsCode").equals(phoneCodeObject.toString())) { log.error("LoginController --> phone() error!", "短信验证码错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信验证码错误"); } redisUtil.del(RedisFileFolder.SMS_CODE.getCode() + phone); Map other = new HashMap<>(); other.put("openIdH5", body.getString("openIdH5")); return ResponseMsgUtil.success(userService.loginAndRegister(platform, phone, body.getLong("popularizeUserId"), other, request, response)); } throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "登录失败"); } catch (Exception e) { log.error("LoginController --> phone() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/openId", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "openId登录") public ResponseData openId(@RequestBody JSONObject body,HttpServletRequest request, HttpServletResponse response) { try { if (body == null || StringUtils.isBlank(body.getString("platform")) || StringUtils.isBlank(body.getString("type")) || StringUtils.isBlank(body.getString("openId")) ) { log.error("LoginController --> phone() error!", "请求参数校验失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } // 客户端 LoginPlatform platform = LoginPlatform.getDataByType(body.getString("platform")); if (platform == null) { log.error("LoginController --> phone() error!", "未知客户端"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知客户端"); } // 登录类型 LoginType loginType = LoginType.getDataByType(body.getString("type")); if (loginType == null) { log.error("LoginController --> phone() error!", "未知登录类型;" + body.getString("type")); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知登录类型"); } if (body.getString("type").equals(LoginType.WECHAT_MP_OPENID.getCode())) { Map param = new HashMap<>(); param.put("openId", body.getString("openId")); List userList = userService.getUserList(param); if (userList.size() > 0) { HighUser user = userList.get(0); if (StringUtils.isNotBlank(user.getPhone())){ return ResponseMsgUtil.success(userService.loginAndRegister(platform, user.getPhone(), body.getLong("popularizeUserId"), new HashMap<>(), request, response)); } } return ResponseMsgUtil.success(null); } else if (body.getString("type").equals(LoginType.WECHAT_MA_OPENID.getCode())) { Map param = new HashMap<>(); param.put("openIdH5", body.getString("openId")); List userList = userService.getUserList(param); if (userList.size() > 0) { HighUser user = userList.get(0); if (StringUtils.isNotBlank(user.getPhone())) { return ResponseMsgUtil.success(userService.loginAndRegister(platform, user.getPhone(), body.getLong("popularizeUserId"), new HashMap<>(), request, response)); } } return ResponseMsgUtil.success(null); } throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "登录失败"); } catch (Exception e) { log.error("LoginController --> phone() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/wxMiniHandleCode", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "微信小程序code解析") public ResponseData wxMiniHandleCode(@RequestBody JSONObject body) { try { if (body == null|| StringUtils.isBlank(body.getString("code"))) { log.error("LoginController --> phone() error!", "请求参数校验失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } WxMaJscode2SessionResult session; if (body.getInteger("type") != null) { //请求微信api,获取用户session_key以及openId session = WxMaConfiguration.getMaService(body.getInteger("type")).jsCode2SessionInfo(body.getString("code")); } else { //请求微信api,获取用户session_key以及openId session = WxMaConfiguration.getMaService().jsCode2SessionInfo(body.getString("code")); } //保存小程序用户登录的openId及sessionKey信息 redisUtil.hset("WX_OPENID_SESSION_REDIS", session.getOpenid(), session); JSONObject jo = new JSONObject(); jo.put("openId", session.getOpenid()); return ResponseMsgUtil.success(jo); } catch (Exception e) { return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/wxMini", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "微信小程序") public ResponseData wxMini(@RequestBody JSONObject body,HttpServletRequest request, HttpServletResponse response) { try { if (body == null || StringUtils.isBlank(body.getString("encryptedData")) || StringUtils.isBlank(body.getString("iv")) || StringUtils.isBlank(body.getString("openId"))) { log.error("LoginController --> phone() error!", "请求参数校验失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } String encryptedData = body.getString("encryptedData").replace(" ", "+"); String iv = body.getString("iv").replace(" ", "+"); //请求微信api,获取用户session_key以及openId Object skObject = redisUtil.hget("WX_OPENID_SESSION_REDIS", body.getString("openId")); if (skObject == null) { throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_LOGIN_ERROR); } WxMaJscode2SessionResult session = (WxMaJscode2SessionResult) skObject; WxMaPhoneNumberInfo phoneNoInfo; if (body.getInteger("type") != null) { phoneNoInfo = WxMaConfiguration .getMaService(body.getInteger("type")) .getUserService() .getPhoneNoInfo(session.getSessionKey(), encryptedData, iv); } else { phoneNoInfo = WxMaConfiguration .getMaService() .getUserService() .getPhoneNoInfo(session.getSessionKey(), encryptedData, iv); } if (phoneNoInfo == null || StringUtils.isEmpty(phoneNoInfo.getPurePhoneNumber())) { log.error("LoginController --> wxMini() error!", "登录失败! 用户手机号解析失败"); throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_DECRYPT_ERROR, "登录失败! 用户手机号解析失败"); } Map other = new HashMap<>(); other.put("openId", session.getOpenid()); return ResponseMsgUtil.success(userService.loginAndRegister(LoginPlatform.WXAPPLETS, phoneNoInfo.getPurePhoneNumber(), body.getLong("popularizeUserId"), other, request, response)); } catch (Exception e) { log.error("LoginController --> wxMini() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/union", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "银联授权手机号登录接口") public ResponseData union(@RequestBody JSONObject body,HttpServletRequest request, HttpServletResponse response) { try { if (body == null || StringUtils.isBlank(body.getString("code"))) { log.error("LoginController --> phone() error!", "请求参数校验失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } // 获取应用访问令牌 String backendToken = unionUserConfig.getBackendToken(); // 获取授权访问令牌 JSONObject token = unionUserConfig.getAccessToken(backendToken, body.getString("code")); if (token == null || !token.getString("resp").equals("00")) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, token.getString("msg")); } // 获取用户手机号 JSONObject userMobile = unionUserConfig.getUserMobile(backendToken, token.getJSONObject("params").getString("accessToken"), token.getJSONObject("params").getString("openId")); if (userMobile == null || !userMobile.getString("resp").equals("00")) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, userMobile.getString("msg")); } // 解密,获取手机号 String mobile = UnionUtils.getDecryptedValue(userMobile.getJSONObject("params").getString("mobile"), unionUserConfig.getRsaKey()); Map other = new HashMap<>(); other.put("unionId", token.getJSONObject("params").getString("openId")); other.put("unionUnionId", token.getJSONObject("params").getString("unionId")); return ResponseMsgUtil.success(userService.loginAndRegister(LoginPlatform.UNIONPAY, mobile, body.getLong("popularizeUserId"), other, request, response)); } catch (Exception e) { return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/out", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "退出登录") public ResponseData out(HttpServletRequest request, HttpServletResponse response) { try { HighUserModel userInfoModel = userCenter.getSessionModel(HighUserModel.class); if (userInfoModel == null) { log.error("CoresController --> outLogin() error!", "用户身份错误或已过期"); throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); } userCenter.remove(request, response); return ResponseMsgUtil.success("退出登录成功"); } catch (Exception e) { log.error("CoresController --> outLogin() error!", e); return ResponseMsgUtil.exception(e); } } } \ No newline at end of file +package com.web.controller; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.security.UserCenter; import com.hai.common.utils.*; import com.hai.config.UnionUserConfig; import com.hai.config.WxMaConfiguration; import com.hai.entity.HighUser; import com.hai.enum_type.LoginPlatform; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; import com.hai.service.HighUserService; import com.web.type.LoginType; import com.hai.enum_type.RedisFileFolder; 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 javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/login") @Api(value = "登录业务") public class LoginController { private static Logger log = LoggerFactory.getLogger(LoginController.class); @Resource private RedisUtil redisUtil; @Resource private HighUserService userService; @Resource private UserCenter userCenter; @Resource private WxMaConfiguration wxMaConfiguration; @Resource private UnionUserConfig unionUserConfig; @RequestMapping(value = "/phone", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "手机号登录") public ResponseData phone(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) { 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"); // 客户端 LoginPlatform platform = LoginPlatform.getDataByType(body.getString("platform")); if (platform == null) { log.error("LoginController --> phone() error!", "未知客户端"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知客户端"); } // 校验手机号格式 if (MemberValidateUtil.validatePhone(phone) == false) { log.error("LoginController --> phone() error!", "请输入正确的手机号"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号"); } // 登录类型 LoginType loginType = LoginType.getDataByType(body.getString("type")); if (loginType == null) { log.error("LoginController --> phone() error!", "未知登录类型;" + body.getString("type")); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知登录类型"); } if (body.getString("type").equals(LoginType.SMS.getCode())) { if (StringUtils.isBlank(body.getString("smsCode"))) { log.error("LoginController --> phone() error!", "请输入短信验证码"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入短信验证码"); } // 手机号的验证码 Object phoneCodeObject = redisUtil.get(RedisFileFolder.SMS_CODE.getCode() + phone); if (phoneCodeObject == null) { log.error("LoginController --> phone() error!", "短信验证码错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信验证码错误"); } if (!body.getString("smsCode").equals(phoneCodeObject.toString())) { log.error("LoginController --> phone() error!", "短信验证码错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信验证码错误"); } redisUtil.del(RedisFileFolder.SMS_CODE.getCode() + phone); Map other = new HashMap<>(); other.put("openIdH5", body.getString("openIdH5")); other.put("storeId", body.getLong("storeId")); return ResponseMsgUtil.success(userService.loginAndRegister(platform, phone, body.getLong("popularizeUserId"), other, request, response)); } throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "登录失败"); } catch (Exception e) { log.error("LoginController --> phone() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/openId", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "openId登录") public ResponseData openId(@RequestBody JSONObject body,HttpServletRequest request, HttpServletResponse response) { try { if (body == null || StringUtils.isBlank(body.getString("platform")) || StringUtils.isBlank(body.getString("type")) || StringUtils.isBlank(body.getString("openId")) ) { log.error("LoginController --> phone() error!", "请求参数校验失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } // 客户端 LoginPlatform platform = LoginPlatform.getDataByType(body.getString("platform")); if (platform == null) { log.error("LoginController --> phone() error!", "未知客户端"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知客户端"); } // 登录类型 LoginType loginType = LoginType.getDataByType(body.getString("type")); if (loginType == null) { log.error("LoginController --> phone() error!", "未知登录类型;" + body.getString("type")); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知登录类型"); } if (body.getString("type").equals(LoginType.WECHAT_MP_OPENID.getCode())) { Map param = new HashMap<>(); param.put("openId", body.getString("openId")); List userList = userService.getUserList(param); if (userList.size() > 0) { HighUser user = userList.get(0); if (StringUtils.isNotBlank(user.getPhone())){ return ResponseMsgUtil.success(userService.loginAndRegister(platform, user.getPhone(), body.getLong("popularizeUserId"), new HashMap<>(), request, response)); } } return ResponseMsgUtil.success(null); } else if (body.getString("type").equals(LoginType.WECHAT_MA_OPENID.getCode())) { Map param = new HashMap<>(); param.put("openIdH5", body.getString("openId")); List userList = userService.getUserList(param); if (userList.size() > 0) { HighUser user = userList.get(0); if (StringUtils.isNotBlank(user.getPhone())) { return ResponseMsgUtil.success(userService.loginAndRegister(platform, user.getPhone(), body.getLong("popularizeUserId"), new HashMap<>(), request, response)); } } return ResponseMsgUtil.success(null); } throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "登录失败"); } catch (Exception e) { log.error("LoginController --> phone() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/wxMiniHandleCode", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "微信小程序code解析") public ResponseData wxMiniHandleCode(@RequestBody JSONObject body) { try { if (body == null|| StringUtils.isBlank(body.getString("code"))) { log.error("LoginController --> phone() error!", "请求参数校验失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } WxMaJscode2SessionResult session; if (body.getInteger("type") != null) { //请求微信api,获取用户session_key以及openId session = WxMaConfiguration.getMaService(body.getInteger("type")).jsCode2SessionInfo(body.getString("code")); } else { //请求微信api,获取用户session_key以及openId session = WxMaConfiguration.getMaService().jsCode2SessionInfo(body.getString("code")); } //保存小程序用户登录的openId及sessionKey信息 redisUtil.hset("WX_OPENID_SESSION_REDIS", session.getOpenid(), session); JSONObject jo = new JSONObject(); jo.put("openId", session.getOpenid()); return ResponseMsgUtil.success(jo); } catch (Exception e) { return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/wxMini", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "微信小程序") public ResponseData wxMini(@RequestBody JSONObject body,HttpServletRequest request, HttpServletResponse response) { try { if (body == null || StringUtils.isBlank(body.getString("encryptedData")) || StringUtils.isBlank(body.getString("iv")) || StringUtils.isBlank(body.getString("openId"))) { log.error("LoginController --> phone() error!", "请求参数校验失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } System.out.println("============================" + body); String encryptedData = body.getString("encryptedData").replace(" ", "+"); String iv = body.getString("iv").replace(" ", "+"); //请求微信api,获取用户session_key以及openId Object skObject = redisUtil.hget("WX_OPENID_SESSION_REDIS", body.getString("openId")); if (skObject == null) { throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_LOGIN_ERROR); } WxMaJscode2SessionResult session = (WxMaJscode2SessionResult) skObject; WxMaPhoneNumberInfo phoneNoInfo; if (body.getInteger("type") != null) { phoneNoInfo = WxMaConfiguration .getMaService(body.getInteger("type")) .getUserService() .getPhoneNoInfo(session.getSessionKey(), encryptedData, iv); } else { phoneNoInfo = WxMaConfiguration .getMaService() .getUserService() .getPhoneNoInfo(session.getSessionKey(), encryptedData, iv); } if (phoneNoInfo == null || StringUtils.isEmpty(phoneNoInfo.getPurePhoneNumber())) { log.error("LoginController --> wxMini() error!", "登录失败! 用户手机号解析失败"); throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_DECRYPT_ERROR, "登录失败! 用户手机号解析失败"); } Map other = new HashMap<>(); other.put("openId", session.getOpenid()); other.put("storeId", body.getLong("storeId")); return ResponseMsgUtil.success(userService.loginAndRegister(LoginPlatform.WXAPPLETS, phoneNoInfo.getPurePhoneNumber(), body.getLong("popularizeUserId"), other, request, response)); } catch (Exception e) { log.error("LoginController --> wxMini() error!", e); return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/union", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "银联授权手机号登录接口") public ResponseData union(@RequestBody JSONObject body,HttpServletRequest request, HttpServletResponse response) { try { if (body == null || StringUtils.isBlank(body.getString("code"))) { log.error("LoginController --> phone() error!", "请求参数校验失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } // 获取应用访问令牌 String backendToken = unionUserConfig.getBackendToken(); // 获取授权访问令牌 JSONObject token = unionUserConfig.getAccessToken(backendToken, body.getString("code")); if (token == null || !token.getString("resp").equals("00")) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, token.getString("msg")); } // 获取用户手机号 JSONObject userMobile = unionUserConfig.getUserMobile(backendToken, token.getJSONObject("params").getString("accessToken"), token.getJSONObject("params").getString("openId")); if (userMobile == null || !userMobile.getString("resp").equals("00")) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, userMobile.getString("msg")); } // 解密,获取手机号 String mobile = UnionUtils.getDecryptedValue(userMobile.getJSONObject("params").getString("mobile"), unionUserConfig.getRsaKey()); Map other = new HashMap<>(); other.put("unionId", token.getJSONObject("params").getString("openId")); other.put("unionUnionId", token.getJSONObject("params").getString("unionId")); return ResponseMsgUtil.success(userService.loginAndRegister(LoginPlatform.UNIONPAY, mobile, body.getLong("popularizeUserId"), other, request, response)); } catch (Exception e) { return ResponseMsgUtil.exception(e); } } @RequestMapping(value = "/out", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "退出登录") public ResponseData out(HttpServletRequest request, HttpServletResponse response) { try { HighUserModel userInfoModel = userCenter.getSessionModel(HighUserModel.class); if (userInfoModel == null) { log.error("CoresController --> outLogin() error!", "用户身份错误或已过期"); throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); } userCenter.remove(request, response); return ResponseMsgUtil.success("退出登录成功"); } catch (Exception e) { log.error("CoresController --> outLogin() error!", e); return ResponseMsgUtil.exception(e); } } } \ No newline at end of file