feat 获取OpenId演示界面, 优化认证授权地址配置

This commit is contained in:
DaxPay
2024-06-21 18:02:54 +08:00
parent f56e088bfe
commit 975ceb213d
19 changed files with 109 additions and 28 deletions

View File

@@ -35,7 +35,7 @@ import java.util.Objects;
public class AliPayConfig extends MpBaseEntity implements EntityBaseFunction<AliPayConfigDto> {
/** 支付宝商户appId */
@DbColumn(comment = "支付宝商户appId")
@DbColumn(comment = "支付宝商户appId", length = 50)
private String appId;
/** 是否启用, 只影响支付和退款操作 */
@@ -72,6 +72,10 @@ public class AliPayConfig extends MpBaseEntity implements EntityBaseFunction<Ali
@DbColumn(comment = "支付网关地址", length = 200)
private String serverUrl;
/** 授权回调地址 */
@DbColumn(comment = "授权回调地址", length = 200)
private String redirectUrl;
/**
* 认证类型 证书/公钥
* @see AliPayCode#AUTH_TYPE_KEY

View File

@@ -36,11 +36,11 @@ import java.util.Objects;
public class WeChatPayConfig extends MpBaseEntity implements EntityBaseFunction<WeChatPayConfigDto> {
/** 微信商户Id */
@DbColumn(comment = "微信商户号")
@DbColumn(comment = "微信商户号", length = 50)
private String wxMchId;
/** 微信应用appId */
@DbColumn(comment = "微信应用appId")
@DbColumn(comment = "微信应用appId", length = 50)
private String wxAppId;
/** 是否启用 */
@@ -52,7 +52,7 @@ public class WeChatPayConfig extends MpBaseEntity implements EntityBaseFunction<
private Boolean allocation;
/** 支付限额 */
@DbColumn(comment = "支付限额")
@DbColumn(comment = "支付限额", length = 8)
private Integer limitAmount;
/**
@@ -73,6 +73,10 @@ public class WeChatPayConfig extends MpBaseEntity implements EntityBaseFunction<
@DbColumn(comment = "同步通知路径")
private String returnUrl;
/** 授权回调地址 */
@DbColumn(comment = "授权回调地址", length = 200)
private String redirectUrl;
/**
* 接口版本, 使用v2还是v3接口
* @see WeChatPayCode#API_V2

View File

@@ -45,16 +45,22 @@ public class AliPayAuthService {
PlatformConfig platformConfig = platformsConfigService.getConfig();
AliPayConfig aliPayConfig = aliPayConfigService.getConfig();
String code = RandomUtil.randomString(10);
// 默认读取通道配置
String serverUrl = aliPayConfig.getRedirectUrl();
// 如果未配置, 读取平台配置
if (StrUtil.isBlank(serverUrl)) {
serverUrl = platformConfig.getWebsiteUrl();
}
// 构建出授权成功后重定向页面链接
String redirectUrl = StrUtil.format("{}/callback/pay/alipay/auth/{}", platformConfig.getWebsiteUrl(), code);
String redirectUrl = StrUtil.format("{}/unipay/callback/alipay/auth/{}", platformConfig.getWebsiteUrl(), code);
// 构造出授权页地址
String url = StrUtil.format("{}/h5/alipayAuth.html?appId={}&redirectUrl={}",
String authUrl = StrUtil.format("{}/h5/alipayAuth.html?appId={}&redirectUrl={}",
platformConfig.getWebsiteUrl(), aliPayConfig.getAppId(), redirectUrl);
// 写入Redis, 五分钟有效期
redisClient.setWithTimeout(OPEN_ID_KEY_PREFIX + code, "", 5*60*1000L);
return new AuthUrlResult()
.setCode(code)
.setAuthUrl(url);
.setAuthUrl(authUrl);
}
/**

View File

@@ -69,10 +69,17 @@ public class WeChatAuthService {
* 生成一个用于微信授权页面的链接和code标识
*/
public AuthUrlResult generateAuthUrl() {
PlatformConfig config = platformsConfigService.getConfig();
PlatformConfig platformConfig = platformsConfigService.getConfig();
WeChatPayConfig weChatPayConfig = weChatPayConfigService.getConfig();
String code = RandomUtil.randomString(10);
// 默认读取通道配置
String serverUrl = weChatPayConfig.getRedirectUrl();
// 如果未配置, 读取平台配置
if (StrUtil.isBlank(serverUrl)) {
serverUrl = platformConfig.getWebsiteUrl();
}
// 构建出授权后重定向页面链接
String redirectUrl = StrUtil.format("{}/callback/pay/wechat/auth/{}", config.getWebsiteUrl(), code);
String redirectUrl = StrUtil.format("{}/unipay/callback/wechat/auth/{}", serverUrl, code);
WxAuthUrlResult result = this.getWxAuthUrl(new WxAuthUrlParam().setUrl(redirectUrl));
// 写入Redis, 五分钟有效期

View File

@@ -86,7 +86,7 @@ public class AllocOrder extends MpBaseEntity implements EntityBaseFunction<Alloc
/**
* 总分账金额
*/
@DbColumn(comment = "总分账金额", length = 15, isNull = false)
@DbColumn(comment = "总分账金额", length = 8, isNull = false)
private Integer amount;
/**

View File

@@ -48,7 +48,7 @@ public class AllocOrderDetail extends MpBaseEntity implements EntityBaseFunction
private Integer rate;
/** 分账金额 */
@DbColumn(comment = "分账金额", length = 15, isNull = false)
@DbColumn(comment = "分账金额", length = 8, isNull = false)
private Integer amount;
/**

View File

@@ -79,11 +79,11 @@ public class PayOrder extends MpBaseEntity implements EntityBaseFunction<PayOrde
private String method;
/** 金额 */
@DbColumn(comment = "金额", length = 15, isNull = false)
@DbColumn(comment = "金额", length = 8, isNull = false)
private Integer amount;
/** 可退款余额 */
@DbColumn(comment = "可退款余额", length = 15, isNull = false)
@DbColumn(comment = "可退款余额", length = 8, isNull = false)
private Integer refundableBalance;
/**

View File

@@ -37,7 +37,7 @@ public class ReconcileOutTrade extends MpCreateEntity implements EntityBaseFunct
private String title;
/** 交易金额 */
@DbColumn(comment = "交易金额", length = 15, isNull = false)
@DbColumn(comment = "交易金额", length = 8, isNull = false)
private Integer amount;
/**

View File

@@ -80,11 +80,11 @@ public class RefundOrder extends MpBaseEntity implements EntityBaseFunction<Refu
private String channel;
/** 订单金额 */
@DbColumn(comment = "订单金额", length = 15, isNull = false)
@DbColumn(comment = "订单金额", length = 8, isNull = false)
private Integer orderAmount;
/** 退款金额 */
@DbColumn(comment = "退款金额", length = 15, isNull = false)
@DbColumn(comment = "退款金额", length = 8, isNull = false)
private Integer amount;
/** 退款原因 */

View File

@@ -55,7 +55,7 @@ public class TransferOrder extends MpBaseEntity implements EntityBaseFunction<Tr
private String channel;
/** 转账金额 */
@DbColumn(comment = "转账金额", length = 15, isNull = false)
@DbColumn(comment = "转账金额", length = 8, isNull = false)
private Integer amount;
/** 标题 */

View File

@@ -31,7 +31,7 @@ public class TradeFlowRecord extends MpCreateEntity implements EntityBaseFunctio
private String title;
/** 金额 */
@DbColumn(comment = "金额", length = 15, isNull = false)
@DbColumn(comment = "金额", length = 8, isNull = false)
private Integer amount;
/**

View File

@@ -35,12 +35,15 @@ public class AliPayConfigDto extends BaseDto implements Serializable {
@Schema(description = "支付限额")
private Integer limitAmount;
@Schema(description = "服务器异步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数必须外网可以正常访问")
@Schema(description = "服务器异步通知页面路径")
private String notifyUrl;
@Schema(description = "页面跳转同步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数必须外网可以正常访问 商户可以自定义同步跳转地址")
@Schema(description = "页面跳转同步通知页面路径")
private String returnUrl;
@Schema(description = "授权回调地址")
private String redirectUrl;
@Schema(description = "请求网关地址")
private String serverUrl;

View File

@@ -43,6 +43,9 @@ public class WeChatPayConfigDto extends BaseDto implements Serializable {
@Schema(description = "同步跳转地址")
private String returnUrl;
@Schema(description = "授权回调地址")
private String redirectUrl;
/** 接口版本, 使用v2还是v3接口 */
@Schema(description = "接口版本")
private String apiVersion;

View File

@@ -5,13 +5,13 @@ import lombok.Data;
import lombok.experimental.Accessors;
/**
* 微信获取OpenId授权链接和查询标识返回类
* 获取OpenId授权链接和查询标识返回类
* @author xxm
* @since 2024/6/15
*/
@Data
@Accessors(chain = true)
@Schema(title = "微信授权链接和查询标识返回类")
@Schema(title = "授权链接和查询标识返回类")
public class AuthUrlResult {
/** 授权访问链接 */

View File

@@ -27,12 +27,15 @@ public class AliPayConfigParam {
@Schema(description = "支付限额")
private Integer limitAmount;
@Schema(description = "服务器异步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数必须外网可以正常访问")
@Schema(description = "服务器异步通知页面路径")
private String notifyUrl;
@Schema(description = "页面跳转同步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数必须外网可以正常访问 商户可以自定义同步跳转地址")
@Schema(description = "页面跳转同步通知页面路径")
private String returnUrl;
@Schema(description = "授权回调地址")
private String redirectUrl;
@Schema(description = "请求网关地址")
private String serverUrl;

View File

@@ -41,6 +41,9 @@ public class WeChatPayConfigParam {
@Schema(description = "同步通知地址")
private String returnUrl;
@Schema(description = "授权回调地址")
private String redirectUrl;
/** 接口版本, 使用v2还是v3接口 */
@Schema(description = "接口版本")
private String apiVersion;