Exemplo n.º 1
0
        public WXMPClient CreateWXClient(string appId)
        {
            if (string.IsNullOrEmpty(appId))
            {
                throw new ArgumentNullException(nameof(appId));
            }

            HttpClient client = _clientFactory.CreateClient(appId);

            TicketClient          ticketClient          = new TicketClient(client);
            BasisServiceClient    basisServiceClient    = new BasisServiceClient(client);
            CustomServiceClient   customServiceClient   = new CustomServiceClient(client);
            TemplateServiceClient templateServiceClient = new TemplateServiceClient(client);
            MenuClient            menuClient            = new MenuClient(client);
            UserManagerClient     umClient       = new UserManagerClient(client);
            AccountManagerClient  amClient       = new AccountManagerClient(client);
            MaterialClient        materialClient = new MaterialClient(client);

            var provider = _serviceProvider.GetRequiredService <IClientCertificateProvider>();
            AccessTokenManager tokenManger = new AccessTokenManager(appId, provider);

            return(new WXMPClient(
                       appId,
                       ticketClient,
                       basisServiceClient,
                       customServiceClient,
                       templateServiceClient,
                       menuClient,
                       umClient,
                       amClient,
                       materialClient,
                       tokenManger));
        }
        public override async Task <ClientCertificateToken> GetToken(ClientCertificateInfo clientInfo, IHttpClientFactory clientFactory)
        {
            var httpClient = clientFactory.CreateClient(_appId);

            TicketClient ticketClient = new TicketClient(httpClient);
            var          r            = await ticketClient.GetTicket("jsapi");

            if (r != null && r.ErrCode == 0)
            {
                return(new ClientCertificateToken()
                {
                    access_token = r.Ticket,
                    expires_in = r.Expires,
                    token_type = "ticket"
                });
            }

            return(null);
        }