Esempio n. 1
0
        /// <summary>
        /// 获取AliPay的支付跳转URL
        /// </summary>
        /// <param name="pRequest"></param>
        /// <returns></returns>
        public static AliPayWapQueryOrderResponse GetQueryTradeResponse(AliPayWapTokenRequest pRequest, AliPayChannel pChannel)
        {
            AliPayWapQueryOrderResponse orderresponse = new AliPayWapQueryOrderResponse();
            var str = BaseGeteway.GetResponseStr(pRequest, Geteway);

            if (!string.IsNullOrEmpty(pChannel.RSA_PublicKey))
            {
                var token = Res_dataDecrypt(str, pChannel, pRequest.InputCharset);
            }
            TokenResponse response = new TokenResponse();
            var           tempdic  = AliPayFunction.ParseResponse(str, pRequest.SecID, pChannel.RSA_PrivateKey, pRequest.InputCharset);

            response.Load(tempdic);
            orderresponse.TokenResponse = response;
            AliPayWapQueryTradeRequest tradeRequeset = new AliPayWapQueryTradeRequest(pChannel)
            {
                RequestToken = response.Token
            };

            orderresponse.RedirectURL = CreateUrl(tradeRequeset);
            orderresponse.IsSucess    = !string.IsNullOrEmpty(response.ResData);
            if (!orderresponse.IsSucess)
            {
                orderresponse.Message = response.ResError;
            }
            return(orderresponse);
        }
        public async Task <IActionResult> SignInByPhoneAsync(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "sign-in-by-phone")] HttpRequest req,
            ILogger log)
        {
            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();

            var signInByPhoneRequest = JsonConvert.DeserializeObject <SignInByPhoneRequest>(requestBody);

            var invalidParameters = new SignInByPhoneRequest();

            Phone    phone    = null;
            Password password = null;

            try
            {
                phone = signInByPhoneRequest.Phone;
            }
            catch (ParameterException e)
            {
                invalidParameters.Phone = e.Message;
            }

            try
            {
                password = signInByPhoneRequest.Password;
            }
            catch (ParameterException e)
            {
                invalidParameters.Password = e.Message;
            }

            if (phone == null ||
                password == null)
            {
                return(new BadRequestObjectResult(
                           new ErrorParametersResponse
                {
                    InvalidParametersObject = invalidParameters
                }));
            }

            try
            {
                var token = await _signInUseCase.SignInByPhone(
                    phone : phone,
                    password : password);

                return(new OkObjectResult(TokenResponse.Load(token)));
            }
            catch (UnauthorizedException)
            {
                return(new UnauthorizedResult());
            }
            catch (DomainException e)
            {
                return(new BadRequestObjectResult(
                           ErrorResponse.BadRequest(
                               message: e.Message
                               )));
            }
        }