parent
df9f40ade3
commit
b694076f45
|
|
@ -41,11 +41,11 @@ public class WxMnpConfiguration {
|
|||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public WxMaService wxMnpService() {
|
||||
Map<String, String> config = this.getChannelConfig("mp_channel");
|
||||
Map<String, String> config = this.getChannelConfig("mnp_setting");
|
||||
|
||||
WxMaDefaultConfigImpl wxConfig = new WxMaDefaultConfigImpl();
|
||||
wxConfig.setAppid(config.getOrDefault("appId", ""));
|
||||
wxConfig.setSecret(config.getOrDefault("appSecret", ""));
|
||||
wxConfig.setAppid(config.getOrDefault("app_id", ""));
|
||||
wxConfig.setSecret(config.getOrDefault("app_secret", ""));
|
||||
|
||||
WxMaService wxService = new WxMaServiceImpl();
|
||||
wxService.setWxMaConfig(wxConfig);
|
||||
|
|
|
|||
|
|
@ -46,8 +46,8 @@ public class WxPayConfiguration {
|
|||
.last("limit 1"));
|
||||
|
||||
Config systemConfig = systemConfigMapper.selectOne(new QueryWrapper<Config>()
|
||||
.eq("type", "mp_channel")
|
||||
.eq("name", "appId")
|
||||
.eq("type", "mnp_setting")
|
||||
.eq("name", "app_id")
|
||||
.last("limit 1"));
|
||||
|
||||
String paramJson = StringUtils.isNull(config.getConfig()) ? "{}" : config.getConfig().toString();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
package com.mdd.common.entity.user;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ApiModel("用户会话实体")
|
||||
public class UserSession implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value="id", type= IdType.AUTO)
|
||||
@ApiModelProperty("ID")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private Integer userId;
|
||||
|
||||
@ApiModelProperty("客户端类型:1-微信小程序;2-微信公众号;3-手机H5;4-电脑PC;5-苹果APP;6-安卓APP")
|
||||
private Integer terminal;
|
||||
|
||||
@ApiModelProperty("令牌")
|
||||
private String token;
|
||||
|
||||
@ApiModelProperty("创建时间")
|
||||
private Long updateTime;
|
||||
|
||||
@ApiModelProperty("更新时间")
|
||||
private Long expireTime;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.mdd.common.mapper.user;
|
||||
|
||||
import com.mdd.common.core.basics.IBaseMapper;
|
||||
import com.mdd.common.entity.user.UserAuth;
|
||||
import com.mdd.common.entity.user.UserSession;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 用户授权Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserSessionMapper extends IBaseMapper<UserSession> {
|
||||
}
|
||||
|
|
@ -48,11 +48,11 @@ public class WxMnpDriver {
|
|||
* @return WxMaService
|
||||
*/
|
||||
public static WxMaService mnp() {
|
||||
Map<String, String> config = ConfigUtils.get("mp_channel");
|
||||
Map<String, String> config = ConfigUtils.get("mnp_setting");
|
||||
|
||||
WxMaDefaultConfigImpl wxConfig = new WxMaDefaultConfigImpl();
|
||||
wxConfig.setAppid(config.getOrDefault("appId", ""));
|
||||
wxConfig.setSecret(config.getOrDefault("appSecret", ""));
|
||||
wxConfig.setAppid(config.getOrDefault("app_id", ""));
|
||||
wxConfig.setSecret(config.getOrDefault("app_secret", ""));
|
||||
wxMaService.setWxMaConfig(wxConfig);
|
||||
|
||||
return wxMaService;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import com.mdd.common.mapper.setting.DevPayConfigMapper;
|
|||
import com.mdd.common.plugin.wechat.request.PaymentRequestV3;
|
||||
import com.mdd.common.plugin.wechat.request.RefundRequestV3;
|
||||
import com.mdd.common.util.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -31,6 +32,7 @@ public class WxPayDriver {
|
|||
private static DevPayConfigMapper devPayConfigMapper;
|
||||
|
||||
private static WxPayService wxPayService;
|
||||
private static WxPayService wxPayMnpService;
|
||||
|
||||
/**
|
||||
* 注入支付配置依赖
|
||||
|
|
@ -48,6 +50,11 @@ public class WxPayDriver {
|
|||
WxPayDriver.wxPayService = wxPayService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setWxPayMnpService(WxPayService wxPayMnpService) {
|
||||
WxPayDriver.wxPayMnpService = wxPayMnpService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信统一下单
|
||||
*
|
||||
|
|
@ -100,6 +107,12 @@ public class WxPayDriver {
|
|||
wxPayUnifiedOrderV3Request.setSceneInfo(sceneInfo);
|
||||
}
|
||||
|
||||
// PC平台
|
||||
if (terminal == ClientEnum.PC.getCode()) {
|
||||
payer.setOpenid(null);
|
||||
tradeTypeEnum = TradeTypeEnum.NATIVE;
|
||||
}
|
||||
|
||||
// 发起订单
|
||||
WxPayService wxPayService = WxPayDriver.handler(terminal);
|
||||
wxPayUnifiedOrderV3Request.setPayer(payer);
|
||||
|
|
@ -141,12 +154,13 @@ public class WxPayDriver {
|
|||
* @return WxPayService
|
||||
*/
|
||||
public static WxPayService handler(Integer terminal) {
|
||||
if (ClientEnum.OA.getCode() == terminal) {
|
||||
resetConfig("oa");
|
||||
} else {
|
||||
if (ClientEnum.MNP.getCode() == terminal) {
|
||||
resetConfig("mnp");
|
||||
return wxPayMnpService;
|
||||
} else {
|
||||
resetConfig("oa");
|
||||
return wxPayService;
|
||||
}
|
||||
return wxPayService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -160,7 +174,6 @@ public class WxPayDriver {
|
|||
new QueryWrapper<DevPayConfig>()
|
||||
.eq("pay_way", 2)
|
||||
.last("limit 1"));
|
||||
|
||||
String scene = type.equals("oa") ? "oa_setting" : "mnp_setting";
|
||||
String appId = ConfigUtils.get(scene, "app_id", "");
|
||||
|
||||
|
|
@ -177,7 +190,12 @@ public class WxPayDriver {
|
|||
payConfig.setPrivateKeyContent(privateKey);
|
||||
payConfig.setPrivateCertContent(privateCert);
|
||||
payConfig.setUseSandboxEnv(false);
|
||||
wxPayService.setConfig(payConfig);
|
||||
|
||||
if (!type.equals("oa")) {
|
||||
wxPayMnpService.setConfig(payConfig);
|
||||
} else {
|
||||
wxPayService.setConfig(payConfig);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,14 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.entity.user.User;
|
||||
import com.mdd.common.entity.user.UserSession;
|
||||
import com.mdd.common.enums.ClientEnum;
|
||||
import com.mdd.common.enums.ErrorEnum;
|
||||
import com.mdd.common.exception.LoginException;
|
||||
import com.mdd.common.mapper.user.UserMapper;
|
||||
import com.mdd.common.mapper.user.UserSessionMapper;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import com.mdd.common.util.YmlUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -30,6 +33,8 @@ public class LikeFrontInterceptor implements HandlerInterceptor {
|
|||
|
||||
@Resource
|
||||
UserMapper userMapper;
|
||||
@Resource
|
||||
UserSessionMapper userSessionMapper;
|
||||
|
||||
/**
|
||||
* 前置处理器
|
||||
|
|
@ -54,7 +59,18 @@ public class LikeFrontInterceptor implements HandlerInterceptor {
|
|||
|
||||
// 记录当前平台
|
||||
String terminal = request.getHeader("terminal");
|
||||
LikeFrontThreadLocal.put("terminal", StringUtils.isEmpty(terminal) ? ClientEnum.H5.getCode() : terminal);
|
||||
String token = request.getHeader(YmlUtils.get("sa-token.token-name"));
|
||||
if (StringUtils.isEmpty(terminal)) {
|
||||
//userSessionMapper.
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
LikeFrontThreadLocal.put("terminal", ClientEnum.PC.getCode());
|
||||
} else {
|
||||
UserSession userSession = userSessionMapper.selectOne(new QueryWrapper<UserSession>().eq("token", token).gt("expire_time", System.currentTimeMillis() / 1000).orderByDesc("id").last("limit 1"));
|
||||
LikeFrontThreadLocal.put("terminal", StringUtils.isNull(userSession) ? ClientEnum.H5.getCode() : userSession.getTerminal());
|
||||
}
|
||||
} else {
|
||||
LikeFrontThreadLocal.put("terminal", terminal);
|
||||
}
|
||||
|
||||
// 登录权限校验
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.mdd.front.controller;
|
|||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.aop.NotPower;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.enums.ClientEnum;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import com.mdd.front.LikeFrontThreadLocal;
|
||||
import com.mdd.front.service.ILoginService;
|
||||
import com.mdd.front.service.IUserService;
|
||||
|
|
@ -38,6 +40,9 @@ public class LoginController {
|
|||
@ApiOperation(value="注册账号")
|
||||
public AjaxResult<Object> register(@Validated @RequestBody RegisterValidate registerValidate) {
|
||||
Integer terminal = LikeFrontThreadLocal.getTerminal();
|
||||
if (StringUtils.isNull(registerValidate.getTerminal())) {
|
||||
terminal = LikeFrontThreadLocal.getTerminal();
|
||||
}
|
||||
String account = registerValidate.getAccount();
|
||||
String password = registerValidate.getPassword();
|
||||
|
||||
|
|
@ -49,7 +54,9 @@ public class LoginController {
|
|||
@PostMapping("/account")
|
||||
@ApiOperation(value="账号登录")
|
||||
public AjaxResult<LoginTokenVo> account(@Validated @RequestBody LoginPwdValidate loginPwdValidate) {
|
||||
loginPwdValidate.setTerminal(LikeFrontThreadLocal.getTerminal());
|
||||
if (StringUtils.isNull(loginPwdValidate.getTerminal())) {
|
||||
loginPwdValidate.setTerminal(LikeFrontThreadLocal.getTerminal());
|
||||
}
|
||||
LoginTokenVo vo = iLoginService.accountLogin(loginPwdValidate);
|
||||
return AjaxResult.success(vo);
|
||||
}
|
||||
|
|
@ -71,6 +78,7 @@ public class LoginController {
|
|||
@ApiOperation(value="微信登录")
|
||||
public AjaxResult<LoginTokenVo> mnpLogin(@Validated @RequestBody LoginCodeValidate loginCodeValidate) {
|
||||
Integer terminal = LikeFrontThreadLocal.getTerminal();
|
||||
|
||||
String code = loginCodeValidate.getCode();
|
||||
|
||||
LoginTokenVo vo = iLoginService.mnpLogin(code, terminal);
|
||||
|
|
@ -81,9 +89,11 @@ public class LoginController {
|
|||
@PostMapping("/oaLogin")
|
||||
@ApiOperation(value="公众号登录")
|
||||
public AjaxResult<LoginTokenVo> oaLogin(@Validated @RequestBody LoginCodeValidate loginCodeValidate) {
|
||||
Integer terminal = LikeFrontThreadLocal.getTerminal();
|
||||
Integer terminal = ClientEnum.OA.getCode();
|
||||
String code = loginCodeValidate.getCode();
|
||||
|
||||
if (StringUtils.isNull(loginCodeValidate.getTerminal())) {
|
||||
terminal = LikeFrontThreadLocal.getTerminal();
|
||||
}
|
||||
LoginTokenVo vo = iLoginService.officeLogin(code, terminal);
|
||||
return AjaxResult.success(vo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,6 @@ public class PayController {
|
|||
if (payStatus != 0) {
|
||||
throw new OperateException("订单已支付");
|
||||
}
|
||||
|
||||
// 发起支付
|
||||
Object result = iPayService.prepay(requestObj, terminal);
|
||||
return AjaxResult.success(result);
|
||||
|
|
|
|||
|
|
@ -8,11 +8,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.mdd.common.entity.user.User;
|
||||
import com.mdd.common.entity.user.UserAuth;
|
||||
import com.mdd.common.entity.user.UserSession;
|
||||
import com.mdd.common.enums.LoginEnum;
|
||||
import com.mdd.common.enums.NoticeEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.user.UserAuthMapper;
|
||||
import com.mdd.common.mapper.user.UserMapper;
|
||||
import com.mdd.common.mapper.user.UserSessionMapper;
|
||||
import com.mdd.common.plugin.notice.NoticeCheck;
|
||||
import com.mdd.common.plugin.wechat.WxMnpDriver;
|
||||
import com.mdd.common.util.*;
|
||||
|
|
@ -49,6 +51,8 @@ public class LoginServiceImpl implements ILoginService {
|
|||
|
||||
@Resource
|
||||
UserAuthMapper userAuthMapper;
|
||||
@Resource
|
||||
UserSessionMapper userSessionMapper;
|
||||
|
||||
/**
|
||||
* 注册账号
|
||||
|
|
@ -444,6 +448,18 @@ public class LoginServiceImpl implements ILoginService {
|
|||
vo.setIsBindMobile(!StringUtils.isEmpty(mobile));
|
||||
vo.setToken(StpUtil.getTokenValue());
|
||||
vo.setIsNew(isNew);
|
||||
|
||||
//保存登录信息到session
|
||||
userSessionMapper.delete(new QueryWrapper<UserSession>().eq("user_id", userId).eq("terminal", terminal));
|
||||
|
||||
UserSession userSession = new UserSession();
|
||||
userSession.setUserId(userId);
|
||||
userSession.setToken(StpUtil.getTokenValue());
|
||||
userSession.setTerminal(terminal);
|
||||
userSession.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
userSession.setExpireTime(System.currentTimeMillis() / 1000 + Long.valueOf(YmlUtils.get("sa-token.timeout")));
|
||||
userSessionMapper.insert(userSession);
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -191,14 +191,21 @@ public class PayServiceImpl implements IPayService {
|
|||
requestV3.setOrderAmount(params.getOrderAmount());
|
||||
requestV3.setDescription(params.getDescription());
|
||||
Object result = WxPayDriver.unifiedOrder(requestV3);
|
||||
System.out.println(terminal);
|
||||
if (terminal == ClientEnum.H5.getCode()) {
|
||||
Assert.notNull(params.getRedirect(), "redirectUrl参数缺失");
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
JSONObject ret = new JSONObject();
|
||||
String h5Url = result.toString();
|
||||
map.put("url", h5Url);
|
||||
return map;
|
||||
System.out.println("aaaaaaaaaa");
|
||||
ret.put("config", WxPayDriver.unifiedOrder(requestV3));
|
||||
ret.put("pay_way", 2);
|
||||
return ret;
|
||||
}
|
||||
return WxPayDriver.unifiedOrder(requestV3);
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("config", WxPayDriver.unifiedOrder(requestV3));
|
||||
ret.put("pay_way", 2);
|
||||
return ret;
|
||||
//return WxPayDriver.unifiedOrder(requestV3);
|
||||
case 3: //支付宝
|
||||
return this.createAliH5Order(params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -296,11 +296,11 @@ public class UserServiceImpl implements IUserService {
|
|||
*/
|
||||
@Override
|
||||
public void mnpMobile(String code) {
|
||||
Map<String, String> config = ConfigUtils.get("mp_channel");
|
||||
Map<String, String> config = ConfigUtils.get("mnp_setting");
|
||||
WxMaService wxMaService = new WxMaServiceImpl();
|
||||
WxMaDefaultConfigImpl wxConfig = new WxMaDefaultConfigImpl();
|
||||
wxConfig.setSecret(config.getOrDefault("appSecret", ""));
|
||||
wxConfig.setAppid(config.getOrDefault("appId", ""));
|
||||
wxConfig.setSecret(config.getOrDefault("app_secret", ""));
|
||||
wxConfig.setAppid(config.getOrDefault("app_id", ""));
|
||||
wxMaService.setWxMaConfig(wxConfig);
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -14,4 +14,7 @@ public class LoginCodeValidate {
|
|||
@ApiModelProperty(value = "微信code", required = true)
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty(value = "终端")
|
||||
private Integer terminal;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,4 +29,6 @@ public class RegisterValidate implements Serializable {
|
|||
@ApiModelProperty(value = "登录密码", required = true)
|
||||
private String password;
|
||||
|
||||
@ApiModelProperty(value = "终端")
|
||||
private Integer terminal;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -814,7 +814,7 @@ CREATE TABLE `la_user_session` (
|
|||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int(11) NOT NULL COMMENT '用户id',
|
||||
`terminal` tinyint(1) NOT NULL DEFAULT '1' COMMENT '客户端类型:1-微信小程序;2-微信公众号;3-手机H5;4-电脑PC;5-苹果APP;6-安卓APP',
|
||||
`token` varchar(32) NOT NULL COMMENT '令牌',
|
||||
`token` varchar(191) NOT NULL COMMENT '令牌',
|
||||
`update_time` int(10) DEFAULT NULL COMMENT '更新时间',
|
||||
`expire_time` int(10) NOT NULL COMMENT '到期时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
|
|
|
|||
Loading…
Reference in New Issue