示例#1
0
        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);
        }
示例#2
0
        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);
        }