feat:【SocialClient】 支付宝小程序登录补充
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -27,9 +27,12 @@ public class SocialClientRespVO {
|
||||
@Schema(description = "客户端密钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "peter")
|
||||
private String clientSecret;
|
||||
|
||||
@Schema(description = "授权方的网页应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000045")
|
||||
@Schema(description = "授权方的网页应用编号", example = "2000045")
|
||||
private String agentId;
|
||||
|
||||
@Schema(description = "publicKey 公钥", example = "2000045")
|
||||
private String publicKey;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer status;
|
||||
|
||||
|
||||
@@ -45,6 +45,9 @@ public class SocialClientSaveReqVO {
|
||||
@Schema(description = "授权方的网页应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000045")
|
||||
private String agentId;
|
||||
|
||||
@Schema(description = "publicKey 公钥", example = "2000045")
|
||||
private String publicKey;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(CommonStatusEnum.class)
|
||||
@@ -58,4 +61,12 @@ public class SocialClientSaveReqVO {
|
||||
|| !StrUtil.isEmpty(agentId);
|
||||
}
|
||||
|
||||
@AssertTrue(message = "publicKey 不能为空")
|
||||
@JsonIgnore
|
||||
public boolean isPublicKeyValid() {
|
||||
// 如果是支付宝,必须填写 publicKey 属性
|
||||
return !Objects.equals(socialType, SocialTypeEnum.ALIPAY_MINI_PROGRAM.getType())
|
||||
|| !StrUtil.isEmpty(publicKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,4 +73,12 @@ public class SocialClientDO extends TenantBaseDO {
|
||||
*/
|
||||
private String agentId;
|
||||
|
||||
/**
|
||||
* publicKey 公钥
|
||||
*
|
||||
* 目前只有部分“社交类型”在使用:
|
||||
* 1. 支付宝:支付宝公钥
|
||||
*/
|
||||
private String publicKey;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -52,6 +51,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,
|
||||
@@ -206,6 +206,10 @@ public class SocialClientServiceImpl implements SocialClientService {
|
||||
newAuthConfig.setAgentId(client.getAgentId());
|
||||
}
|
||||
// 2.3 设置会 request 里,进行后续使用
|
||||
if (SocialTypeEnum.ALIPAY_MINI_PROGRAM.getType().equals(socialType)) {
|
||||
// 特殊:如果是支付宝的小程序,多了 publicKey 属性,可见 AuthConfig 里的 alipayPublicKey 字段说明
|
||||
return new AuthAlipayRequest(newAuthConfig, client.getPublicKey());
|
||||
}
|
||||
ReflectUtil.setFieldValue(request, "config", newAuthConfig);
|
||||
}
|
||||
return request;
|
||||
|
||||
@@ -180,6 +180,12 @@ 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
|
||||
ignore-check-state: true
|
||||
cache:
|
||||
type: REDIS
|
||||
prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE::
|
||||
|
||||
@@ -209,6 +209,12 @@ 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
|
||||
ignore-check-state: true
|
||||
cache:
|
||||
type: REDIS
|
||||
prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE::
|
||||
|
||||
Reference in New Issue
Block a user