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

@@ -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);
}