feat:【SocialClient】 支付宝小程序登录补充

This commit is contained in:
yunlongn 2025-11-27 12:01:55 +08:00
parent c92fa0685c
commit f83ca8ea4d
14 changed files with 66 additions and 9 deletions

View File

@ -4179,7 +4179,8 @@ CREATE TABLE system_social_client
social_type smallint NOT NULL,
user_type smallint NOT NULL,
client_id varchar(255) NOT NULL,
client_secret varchar(255) NOT NULL,
client_secret varchar(2048) NOT NULL,
public_key varchar(2048) DEFAULT NULL NULL,
agent_id varchar(255) DEFAULT NULL NULL,
status smallint NOT NULL,
creator varchar(64) DEFAULT '' NULL,
@ -4195,6 +4196,7 @@ COMMENT ON COLUMN system_social_client.name IS '应用名';
COMMENT ON COLUMN system_social_client.social_type IS '社交平台的类型';
COMMENT ON COLUMN system_social_client.user_type IS '用户类型';
COMMENT ON COLUMN system_social_client.client_id IS '客户端编号';
COMMENT ON COLUMN system_social_client.public_key IS 'publicKey公钥';
COMMENT ON COLUMN system_social_client.client_secret IS '客户端密钥';
COMMENT ON COLUMN system_social_client.agent_id IS '代理编号';
COMMENT ON COLUMN system_social_client.status IS '状态';

View File

@ -4461,7 +4461,8 @@ CREATE TABLE system_social_client
social_type int2 NOT NULL,
user_type int2 NOT NULL,
client_id varchar(255) NOT NULL,
client_secret varchar(255) NOT NULL,
client_secret varchar(2048) NOT NULL,
public_key varchar(2048) NULL DEFAULT NULL,
agent_id varchar(255) NULL DEFAULT NULL,
status int2 NOT NULL,
creator varchar(64) NULL DEFAULT '',
@ -4481,6 +4482,7 @@ COMMENT ON COLUMN system_social_client.social_type IS '社交平台的类型';
COMMENT ON COLUMN system_social_client.user_type IS '用户类型';
COMMENT ON COLUMN system_social_client.client_id IS '客户端编号';
COMMENT ON COLUMN system_social_client.client_secret IS '客户端密钥';
COMMENT ON COLUMN system_social_client.public_key IS 'publicKey公钥';
COMMENT ON COLUMN system_social_client.agent_id IS '代理编号';
COMMENT ON COLUMN system_social_client.status IS '状态';
COMMENT ON COLUMN system_social_client.creator IS '创建者';

View File

@ -3502,7 +3502,8 @@ CREATE TABLE `system_social_client` (
`social_type` tinyint NOT NULL COMMENT '社交平台的类型',
`user_type` tinyint NOT NULL COMMENT '用户类型',
`client_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '客户端编号',
`client_secret` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '客户端密钥',
`client_secret` varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '客户端密钥',
`public_key` varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT 'publicKey公钥',
`agent_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '代理编号',
`status` tinyint NOT NULL COMMENT '状态',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',

View File

@ -4461,7 +4461,8 @@ CREATE TABLE system_social_client
social_type int2 NOT NULL,
user_type int2 NOT NULL,
client_id varchar(255) NOT NULL,
client_secret varchar(255) NOT NULL,
client_secret varchar(2048) NOT NULL,
public_key varchar(2048) NULL DEFAULT NULL,
agent_id varchar(255) NULL DEFAULT NULL,
status int2 NOT NULL,
creator varchar(64) NULL DEFAULT '',
@ -4481,6 +4482,7 @@ COMMENT ON COLUMN system_social_client.social_type IS '社交平台的类型';
COMMENT ON COLUMN system_social_client.user_type IS '用户类型';
COMMENT ON COLUMN system_social_client.client_id IS '客户端编号';
COMMENT ON COLUMN system_social_client.client_secret IS '客户端密钥';
COMMENT ON COLUMN system_social_client.public_key IS 'publicKey公钥';
COMMENT ON COLUMN system_social_client.agent_id IS '代理编号';
COMMENT ON COLUMN system_social_client.status IS '状态';
COMMENT ON COLUMN system_social_client.creator IS '创建者';

View File

@ -4355,7 +4355,8 @@ CREATE TABLE system_social_client
social_type smallint NOT NULL,
user_type smallint NOT NULL,
client_id varchar2(255) NULL,
client_secret varchar2(255) NULL,
client_secret varchar2(2048) NULL,
public_key varchar2(2048) DEFAULT NULL NULL,
agent_id varchar2(255) DEFAULT NULL NULL,
status smallint NOT NULL,
creator varchar2(64) DEFAULT '' NULL,
@ -4375,6 +4376,7 @@ COMMENT ON COLUMN system_social_client.social_type IS '社交平台的类型';
COMMENT ON COLUMN system_social_client.user_type IS '用户类型';
COMMENT ON COLUMN system_social_client.client_id IS '客户端编号';
COMMENT ON COLUMN system_social_client.client_secret IS '客户端密钥';
COMMENT ON COLUMN system_social_client.public_key IS 'publicKey公钥';
COMMENT ON COLUMN system_social_client.agent_id IS '代理编号';
COMMENT ON COLUMN system_social_client.status IS '状态';
COMMENT ON COLUMN system_social_client.creator IS '创建者';

View File

@ -4461,7 +4461,8 @@ CREATE TABLE system_social_client
social_type int2 NOT NULL,
user_type int2 NOT NULL,
client_id varchar(255) NOT NULL,
client_secret varchar(255) NOT NULL,
client_secret varchar(2048) NOT NULL,
public_key varchar(2048) NULL DEFAULT NULL,
agent_id varchar(255) NULL DEFAULT NULL,
status int2 NOT NULL,
creator varchar(64) NULL DEFAULT '',
@ -4481,6 +4482,7 @@ COMMENT ON COLUMN system_social_client.social_type IS '社交平台的类型';
COMMENT ON COLUMN system_social_client.user_type IS '用户类型';
COMMENT ON COLUMN system_social_client.client_id IS '客户端编号';
COMMENT ON COLUMN system_social_client.client_secret IS '客户端密钥';
COMMENT ON COLUMN system_social_client.public_key IS 'publicKey公钥';
COMMENT ON COLUMN system_social_client.agent_id IS '代理编号';
COMMENT ON COLUMN system_social_client.status IS '状态';
COMMENT ON COLUMN system_social_client.creator IS '创建者';

View File

@ -10433,7 +10433,8 @@ CREATE TABLE system_social_client
social_type tinyint NOT NULL,
user_type tinyint NOT NULL,
client_id nvarchar(255) NOT NULL,
client_secret nvarchar(255) NOT NULL,
client_secret nvarchar(2048) NOT NULL,
public_key nvarchar(2048) DEFAULT NULL NULL,
agent_id nvarchar(255) DEFAULT NULL NULL,
status tinyint NOT NULL,
creator nvarchar(64) DEFAULT '' NULL,
@ -10487,6 +10488,13 @@ EXEC sp_addextendedproperty
'COLUMN', N'client_secret'
GO
EXEC sp_addextendedproperty
'MS_Description', N'publicKey公钥',
'SCHEMA', N'dbo',
'TABLE', N'system_social_client',
'COLUMN', N'public_key'
GO
EXEC sp_addextendedproperty
'MS_Description', N'代理编号',
'SCHEMA', N'dbo',

View File

@ -27,6 +27,9 @@ public class SocialClientRespVO {
@Schema(description = "客户端密钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "peter")
private String clientSecret;
@Schema(description = "publicKey公钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000045")
private String publicKey;
@Schema(description = "授权方的网页应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000045")
private String agentId;

View File

@ -41,6 +41,9 @@ public class SocialClientSaveReqVO {
@Schema(description = "客户端密钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "peter")
@NotNull(message = "客户端密钥不能为空")
private String clientSecret;
@Schema(description = "publicKey公钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000045")
private String publicKey;
@Schema(description = "授权方的网页应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000045")
private String agentId;

View File

@ -64,6 +64,14 @@ public class SocialClientDO extends TenantBaseDO {
* 客户端 Secret
*/
private String clientSecret;
/**
* publicKey公钥
*
* 目前只有部分社交类型在使用
* 1. 支付宝支付宝公钥
*/
private String publicKey;
/**
* 代理编号

View File

@ -53,6 +53,12 @@ public enum SocialTypeEnum implements ArrayValuable<Integer> {
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html">接入文档</a>
*/
WECHAT_MINI_PROGRAM(34, "WECHAT_MINI_PROGRAM"),
/**
* 支付宝小程序
*
* @see <a href="https://opendocs.alipay.com/mini/05dxgc?pathHash=1a3ecb13">接入文档</a>
*/
ALIPAY_MINI_PROGRAM(40, "ALIPAY"),
;
public static final Integer[] ARRAYS = Arrays.stream(values()).map(SocialTypeEnum::getType).toArray(Integer[]::new);

View File

@ -11,7 +11,6 @@ import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.DesensitizedUtil;
import cn.hutool.core.util.ObjUtil;
@ -51,6 +50,7 @@ import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.request.AuthAlipayRequest;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.utils.AuthStateUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -169,7 +169,7 @@ public class SocialClientServiceImpl implements SocialClientService {
public AuthUser getAuthUser(Integer socialType, Integer userType, String code, String state) {
// 构建请求
AuthRequest authRequest = buildAuthRequest(socialType, userType);
AuthCallback authCallback = AuthCallback.builder().code(code).state(state).build();
AuthCallback authCallback = AuthCallback.builder().code(code).auth_code(code).state(state).build();
// 执行请求
AuthResponse<?> authResponse = authRequest.login(authCallback);
log.info("[getAuthUser][请求社交平台 type({}) request({}) response({})]", socialType,
@ -205,6 +205,10 @@ public class SocialClientServiceImpl implements SocialClientService {
if (client.getAgentId() != null) { // 如果有 agentId 则修改 agentId
newAuthConfig.setAgentId(client.getAgentId());
}
// 如果是阿里的小程序
if (SocialTypeEnum.ALIPAY_MINI_PROGRAM.getType().equals(socialType)) {
return new AuthAlipayRequest(newAuthConfig, client.getPublicKey());
}
// 2.3 设置会 request 进行后续使用
ReflectUtil.setFieldValue(request, "config", newAuthConfig);
}

View File

@ -197,6 +197,13 @@ justauth:
client-id: ${wx.mp.app-id}
client-secret: ${wx.mp.secret}
ignore-check-redirect-uri: true
ALIPAY: # 支付宝小程序
client-id: xx
client-secret: xx
alipay-public-key: xx
ignore-check-redirect-uri: true
redirect-uri: http://yunai.natapp1.cc
ignore-check-state: true
cache:
type: REDIS
prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE::

View File

@ -262,6 +262,13 @@ justauth:
client-id: ${wx.mp.app-id}
client-secret: ${wx.mp.secret}
ignore-check-redirect-uri: true
ALIPAY: # 支付宝小程序
client-id: xx
client-secret: xx
alipay-public-key: xx
ignore-check-redirect-uri: true
redirect-uri: http://yunai.natapp1.cc
ignore-check-state: true
cache:
type: REDIS
prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE::