mirror of
https://gitee.com/likeadmin/likeadmin_java.git
synced 2026-06-20 09:12:55 +08:00
feat 适配微信支付模块
feat 登录增加终端保存到session表的方法
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user