public static async Task <WechatPaymentDataResultModel> GetPaymentInfo(string appIp, string notifyUrl, string publicAccountAppId, int feeInPennies, WechatTradeType tradeType, string transactionId, string desc, string merchantId, string openId, string merchantKey) { var nonce = Guid.NewGuid().ToString().Replace("-", ""); var sign = WechatMd5SignGenerator.GetPaymentInfoMd5Hash(merchantId, publicAccountAppId, nonce, desc, transactionId, feeInPennies, appIp, notifyUrl, tradeType.ToString(), openId, merchantKey); var paymentRequestModel = new WechatPaymentRequestModel { AppIp = appIp, Description = desc, MerchantId = merchantId, Nonce = nonce, NotifyUrl = notifyUrl, PublicAccountAppId = publicAccountAppId, TotalFee = feeInPennies, TradeType = tradeType.ToString(), TransactionId = transactionId, Sign = sign, UserOpenId = openId }; var response = await PostAsync <WechatPaymentRequestModel, WechatPaymentDataResultModel>("pay/unifiedorder", paymentRequestModel); var success = string.Equals(response.ResultCode, WechatPayStatus.SUCCESS.ToString()) && string.Equals(response.ReturnCode, WechatPayStatus.SUCCESS.ToString()); if (!success) { LoggingQueue.Add(new LogMessage { LogLevel = LogLevel.Log, Message = $"Wechat refund status: TransactionId: {transactionId}, ReturnCode: {response.ReturnCode}, ResultCode: {response.ResultCode}" }); } return(response); }
public static async Task <bool> CheckIfPaymentIsPaidAsync(string transactionId, string appId, string merchantId, string merchantKey) { var nonce = Guid.NewGuid().ToString().Replace("-", ""); var sign = WechatMd5SignGenerator.GetMd5Hash(appId, merchantId, nonce, transactionId, merchantKey); var verification = new WechatPaymentVerificationModel { AppId = appId, MerchantId = merchantId, Nonce = nonce, Sign = sign, TransactionId = transactionId }; var response = await PostAsync <WechatPaymentVerificationModel, WechatPaymentVerificationResultModel>("pay/orderquery", verification); var paid = string.Equals(response.ResultCode, WechatPayStatus.SUCCESS.ToString()) && string.Equals(response.ReturnCode, WechatPayStatus.SUCCESS.ToString()) && string.Equals(response.TradeState, WechatTradeState.SUCCESS.ToString()) && string.Equals(transactionId, response.TransactionId); if (!paid) { LoggingQueue.Add(new LogMessage { LogLevel = LogLevel.Log, Message = $"Wechat paid status: TransactionId: {transactionId}, ReturnCode: {response.ReturnCode}, ResultCode: {response.ResultCode}" }); } return(paid); }
protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var guid = Guid.NewGuid(); LoggingQueue.Add(new LogMessage { LogLevel = LogLevel.Log, Message = $"Request coming in with Guid: {guid.ToString()}", TimeStamp = DateTimeExtensions.BeiJingNow(), RequestUrl = request.RequestUri.ToString(), PayLoad = request.RequestUri.ToString().Contains("image") ? "" : request.Content?.ReadAsStringAsync().Result ?? "" }); var response = await base.SendAsync(request, cancellationToken); LoggingQueue.Add(new LogMessage { LogLevel = LogLevel.Log, Message = $"Request going out with Guid: {guid.ToString()}", TimeStamp = DateTimeExtensions.BeiJingNow(), RequestUrl = request.RequestUri.ToString(), PayLoad = response.Content?.ReadAsStringAsync().Result ?? "" }); return(response); }
public void CheckError() { if (ErrorCode == 0) { return; } LoggingQueue.Add(new LogMessage { Message = "WechatError", PayLoad = ErrorMessage }); throw new ApiException(ApiErrorCode.WechatError, ErrorMessage); }
public override void Handle(ExceptionHandlerContext context) { base.Handle(context); var exception = context.Exception; ErrorModel errorModel; if (exception is ApiException) { var apiException = exception as ApiException; errorModel = GetErrorModel(apiException); } else { errorModel = new ErrorModel { ErrorCode = ApiErrorCode.Unknown, Message = ApiErrorCode.Unknown.ToString() }; } var message = exception is ApiException ? errorModel.Message : exception.Message; Exception innerEx = exception.InnerException; while (innerEx?.InnerException != null) { innerEx = innerEx.InnerException; } LoggingQueue.Add(new LogMessage { LogLevel = LogLevel.Error, Message = $"Error: Message: { message } Stacktrace: {exception.StackTrace} InnerException: {innerEx?.Message} InnerExceptionStackTrace: {innerEx?.StackTrace}", RequestUrl = context.Request.RequestUri.ToString(), TimeStamp = DateTimeExtensions.BeiJingNow(), PayLoad = context.Request.Content?.ReadAsStringAsync().Result ?? "" }); context.Result = new ResponseMessageResult(context.Request.CreateResponse(HttpStatusCode.OK, errorModel)); }