예제 #1
0
        public async Task <ActionResult> AuthAsync()
        {
            if (_memoryCache.TryGetValue(nameof(ComponentVerifyTicketNotifyModel), out ComponentVerifyTicketNotifyModel componentVerifyTicketNotifyModel))
            {
                if (!_memoryCache.TryGetValue(nameof(ApiComponentTokenResponse), out ApiComponentTokenResponse apiComponentTokenResponse))
                {
                    apiComponentTokenResponse = await _component.ApiComponentToken(new ApiComponentTokenRequest()
                    {
                        ComponentAppId        = _optionsSnapshotOfWeChatComponentOptions.Value?.AppId,
                        ComponentAppSecret    = _optionsSnapshotOfWeChatComponentOptions.Value?.AppSecret,
                        ComponentVerifyTicket = componentVerifyTicketNotifyModel.ComponentVerifyTicket
                    });

                    _memoryCache.Set(nameof(ApiComponentTokenResponse), apiComponentTokenResponse);
                }
                ApiCreatePreAuthCodeResponse result = await _component.ApiCreatePreAuthCode(apiComponentTokenResponse.ComponentAccessToken, new ApiCreatePreAuthCodeRequest()
                {
                    ComponentAppId = _optionsSnapshotOfWeChatComponentOptions.Value?.AppId
                });

                string redirectUrl = "http://dev.thirdparty.wechatmp.dt128.com/ComponentAuth/AuthRedirect";
                string authUrl     = result.CreateBindComponentAuthUrl(_optionsSnapshotOfWeChatComponentOptions.Value?.AppId, EnumBindComponentAuthType.QRCode, redirectUrl);
                return(Redirect(authUrl));
            }
            return(RedirectToAction(nameof(AuthView)));
        }