Example #1
0
        public async Task <Unit> Handle(AuthorizationCallbackCommand request, CancellationToken cancellationToken)
        {
            var authorizationInfo =
                await _thirdPartyOauthService.GetAuthorizationInformationAsync(
                    new GetAuthorizationInformationInput(request.AuthCode));

            var authorizerInfo =
                await _thirdPartyOauthService.GetAuthorizerInfoAsync(
                    new GetAuthorizerInfoInput(authorizationInfo.AuthorizationInfo.AuthorizerAppId));

            //小程序授权先不做
            if (authorizerInfo.AuthorizerInfo.MiniProgramInfo != null)
            {
                return(Unit.Value);
            }

            var officialAccount = new OfficialAccounts(authorizerInfo.AuthorizationInfo.AuthorizerAppId, authorizerInfo.AuthorizerInfo.UserName)
            {
                NickName        = authorizerInfo.AuthorizerInfo.NickName,
                HeadImg         = authorizerInfo.AuthorizerInfo.HeadImg,
                ServiceTypeInfo = (EnumOfficialAccountsServiceType)authorizerInfo.AuthorizerInfo.ServiceTypeInfo.Id,
                VerifyTypeInfo  = (EnumOfficialAccountsVerifyType)authorizerInfo.AuthorizerInfo.VerifyTypeInfo.Id,
                Idc             = authorizerInfo.AuthorizerInfo.Idc,
                PrincipalName   = authorizerInfo.AuthorizerInfo.PrincipalName,
                QrCodeUrl       = authorizerInfo.AuthorizerInfo.QrCodeUrl,
                Alias           = authorizerInfo.AuthorizerInfo.Alias,
                Signature       = authorizerInfo.AuthorizerInfo.Signature,
                RefreshToken    = authorizerInfo.AuthorizationInfo.AuthorizerRefreshToken
            };

            await _officialAccountRepository.AddAsync(officialAccount, cancellationToken);

            await _officialAccountRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
 /// <summary>
 /// 公众号找不到
 /// </summary>
 /// <param name="guardClause"></param>
 /// <param name="officialAccountsId"></param>
 /// <param name="officialAccounts"></param>
 /// <param name="errorSource"></param>
 public static void NotFoundOfficialAccounts(this IGuardClause guardClause, Guid officialAccountsId, OfficialAccounts officialAccounts, string errorSource = null)
 {
     if (officialAccounts.IsNull())
     {
         throw new WeChatAdApterException($"{officialAccountsId}不存在", errorSource);
     }
 }