Search in sources :

Example 1 with AuthWeChatMpRequest

use of me.zhyd.oauth.request.AuthWeChatMpRequest in project wumei-smart by kerwincui.

the class AuthRequestFactoryImpl method getAuthRequest.

/**
 * 获得对于AUthRequest
 *
 * @param source 登录方式
 * @return 对应AuthRequest
 */
@Override
public AuthRequestWrap getAuthRequest(String source) {
    AuthRequestWrap authRequestWrap = new AuthRequestWrap();
    AuthRequest authRequest;
    try {
        SocialPlatformType socialPlatformType = SocialPlatformType.valueOf(source.toUpperCase(Locale.ROOT));
        SocialPlatform socialPlatform = iSocialPlatformService.selectSocialPlatformByPlatform(source);
        authRequestWrap.setSocialPlatform(socialPlatform);
        AuthConfig authConfig = AuthConfig.builder().clientId(socialPlatform.getClientId()).clientSecret(socialPlatform.getSecretKey()).redirectUri(socialPlatform.getRedirectUri()).build();
        switch(socialPlatformType) {
            case QQ:
                {
                    authRequest = new AuthQqRequest(authConfig, authStateRedisCache);
                    break;
                }
            case Wechat:
                {
                    authRequest = new AuthWeChatMpRequest(authConfig, authStateRedisCache);
                    break;
                }
            default:
                {
                    throw new ServiceException("source: " + source + ",暂不支持");
                }
        }
        authRequestWrap.setAuthRequest(authRequest);
        return authRequestWrap;
    } catch (Exception e) {
        throw new ServiceException(e.getMessage());
    }
}
Also used : AuthRequest(me.zhyd.oauth.request.AuthRequest) SocialPlatform(com.ruoyi.iot.domain.SocialPlatform) AuthRequestWrap(com.ruoyi.iot.model.login.AuthRequestWrap) ServiceException(com.ruoyi.common.exception.ServiceException) SocialPlatformType(com.ruoyi.common.enums.SocialPlatformType) AuthQqRequest(me.zhyd.oauth.request.AuthQqRequest) AuthConfig(me.zhyd.oauth.config.AuthConfig) AuthWeChatMpRequest(me.zhyd.oauth.request.AuthWeChatMpRequest) ServiceException(com.ruoyi.common.exception.ServiceException)

Aggregations

SocialPlatformType (com.ruoyi.common.enums.SocialPlatformType)1 ServiceException (com.ruoyi.common.exception.ServiceException)1 SocialPlatform (com.ruoyi.iot.domain.SocialPlatform)1 AuthRequestWrap (com.ruoyi.iot.model.login.AuthRequestWrap)1 AuthConfig (me.zhyd.oauth.config.AuthConfig)1 AuthQqRequest (me.zhyd.oauth.request.AuthQqRequest)1 AuthRequest (me.zhyd.oauth.request.AuthRequest)1 AuthWeChatMpRequest (me.zhyd.oauth.request.AuthWeChatMpRequest)1