/// <summary>
        /// 支付,跳转到支付宝收银台
        /// </summary>
        /// <param name="request">支付宝手机网站支付参数</param>
        /// <returns></returns>
        public async Task RedirectAsync(AlipayWapPayRequest request)
        {
            var result = await PayAsync(request);

            var response = Web.Response;
            var config   = await ConfigProvider.GetConfigAsync();

            response.Redirect($"{config.GatewayUrl}?{result}");
        }
        /// <summary>
        /// 获取访问令牌
        /// </summary>
        /// <param name="param">访问令牌参数</param>
        /// <returns></returns>
        public override async Task <AuthorizationResult> GetTokenAsync(AccessTokenParam param)
        {
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config, param);
            var builder = new AuthorizationParameterBuilder();

            ConfigGetToken(builder, param, config);
            return(await RequestResult(config, builder, ParameterParserType.Json, Success));
        }
Esempio n. 3
0
        /// <summary>
        /// 退款
        /// </summary>
        /// <param name="request">退款参数</param>
        public async Task <RefundResult> RefundAsync(WechatRefundRequest request)
        {
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config, request);
            var builder = new WechatpayRefundParameterBuilder(config);

            Config(builder, request);
            return(await RequstResult(config, builder));
        }
Esempio n. 4
0
        /// <summary>
        /// 下载对账单
        /// </summary>
        /// <param name="request">下载对账单参数</param>
        public async Task <WechatpayDownloadBillResult> DownloadAsync(WechatpayDownloadBillRequest request)
        {
            var config = await ConfigProvider.GetConfigAsync(request);

            Validate(config, request);
            var builder = new WechatpayParameterBuilder(config);

            ConfigBuilder(builder, request);
            return(await Requst(config, builder, request));
        }
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="param">授权用户参数</param>
        /// <returns></returns>
        public async Task<GithubAuthorizationUserInfoResult> GetUserInfoAsync(GithubAuthorizationUserRequest param)
        {
            var config = await ConfigProvider.GetConfigAsync();
            Validate(config, param.ToParam());
            var builder = new AuthorizationParameterBuilder();
            builder.GatewayUrl(GetUserInfoUrl)
                .AccessToken(param.AccessToken);

            var result = await RequestResult(config, builder, ParameterParserType.Json,
                (t) => t.HasKey("id"));
            return result.Success ? result.Result.ToObject<GithubAuthorizationUserInfoResult>() : null;
        }
        /// <summary>
        /// 刷新令牌
        /// </summary>
        /// <param name="token">刷新令牌</param>
        /// <returns></returns>
        public override async Task <AuthorizationResult> RefreshTokenAsync(string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                throw new ArgumentNullException(nameof(token));
            }
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config);
            var builder = new AuthorizationParameterBuilder();

            ConfigRefreshToken(builder, token, config);
            return(await RequestResult(config, builder, ParameterParserType.Json, Success));
        }
        /// <summary>
        /// 支付
        /// </summary>
        /// <param name="param">支付参数</param>
        public override async Task <PayResult> PayAsync(PayParam param)
        {
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config, param);
            var builder = new AlipayParameterBuilder(config);

            Config(builder, param);
            var form = GetForm(builder);

            WriteLog(config, builder, form);
            return(new PayResult {
                Result = form
            });
        }
Esempio n. 8
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="param">授权用户参数</param>
        /// <returns></returns>
        public async Task <CodingAuthorizationUserInfoResult> GetUserInfoAsync(CodingAuthorizationUserRequest param)
        {
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config, param.ToParam());
            var builder = new AuthorizationParameterBuilder();

            builder.GatewayUrl(GetUserInfoUrl)
            .AccessToken(param.AccessToken);

            var result = await RequestResult(config, builder, ParameterParserType.Json,
                                             (t) => t.GetValue("code") == "0");

            return(result.Success ? result.GetValue("data").ToObject <CodingAuthorizationUserInfoResult>() : null);
        }
Esempio n. 9
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="param">授权用户参数</param>
        /// <returns></returns>
        public async Task <QQAuthorizationUserInfoResult> GetUserInfoAsync(QQAuthorizationUserRequest param)
        {
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config, param.ToParam());
            var builder = new AuthorizationParameterBuilder();

            builder.GatewayUrl(GetUserInfoUrl)
            .AccessToken(param.AccessToken)
            .Add("oauth_consumer_key", config.AppId)
            .OpenId(param.OpenId);
            var result = await RequestResult(config, builder, ParameterParserType.Json,
                                             (t) => t.GetValue("ret") == "0");

            return(result.Success ? result.Result.ToObject <QQAuthorizationUserInfoResult>() : null);
        }
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="param">授权用户参数</param>
        /// <returns></returns>
        public async Task <WechatAuthorizationUserInfoResult> GetUserInfoAsync(WechatAuthorizationUserRequest param)
        {
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config, param.ToParam());
            var builder = new AuthorizationParameterBuilder();

            builder.GatewayUrl(GetUserInfoUrl)
            .AccessToken(param.AccessToken)
            .OpenId(param.OpenId)
            .Add("lang", param.Lang);

            var result = await RequestResult(config, builder, ParameterParserType.Json,
                                             (t) => t.HasKey("openid"));

            return(result.Success ? result.Result.ToObject <WechatAuthorizationUserInfoResult>() : null);
        }
Esempio n. 11
0
        /// <summary>
        /// 获取用户OpenId
        /// </summary>
        /// <param name="token">授权令牌</param>
        /// <returns></returns>
        public async Task <string> GetOpenIdAsync(string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                throw new ArgumentNullException(nameof(token));
            }
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config);
            var builder = new AuthorizationParameterBuilder();

            builder.GatewayUrl(GetOpenIdUrl)
            .AccessToken(token);
            var result = await RequestResult(config, builder, ParameterParserType.Jsonp, (t) => t.HasKey("openid"));

            if (!config.AppId.Equals(result.GetValue(OAuthConst.ClientId)))
            {
                throw new ArgumentException("客户端ID不一致");
            }
            return(result.GetValue("openid"));
        }
Esempio n. 12
0
        private static async Task MainAsync()
        {
            using (var client = new DiscordSocketClient())
            {
                var config = await ConfigProvider.GetConfigAsync().ConfigureAwait(false);

                if (config == null)
                {
                    LoggingService.LogError("Could not start bot. "
                                            + $"'{ConfigProvider.FilePath()}' does not exist.");
                    return;
                }

                client.Log             += LoggingService.Log;
                client.MessageReceived += MessageHandler.MessageRecieved;

                await client.LoginAsync(Discord.TokenType.Bot, config.Token).ConfigureAwait(false);

                await client.StartAsync().ConfigureAwait(false);

                await Task.Delay(-1);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// 验证签名
        /// </summary>
        public async Task <bool> VerifySign()
        {
            var config = await ConfigProvider.GetConfigAsync(_builder);

            return(SignManagerFactory.Create(config, _builder).Verify(GetSign()));
        }