示例#1
0
        /// <summary>
        /// 支付宝查询
        /// </summary>
        /// <param name="query">查询实体</param>
        /// <param name="queryBack">查询返回寮体</param>
        /// <param name="message">错误信息</param>
        /// <returns></returns>
        internal bool Query(QueryOrder query, out QueryOrderBack queryBack, out string message)
        {
            _log.Info("支付宝查询 QueryOrder 开始");
            var queryRequst = new AlipayTradeQueryRequest();

            queryRequst.BizContent = Newtonsoft.Json.JsonConvert.SerializeObject(query, new JsonSerializerSettings()
            {
                DefaultValueHandling = DefaultValueHandling.Ignore
            }).ToLower();
            var queryResponse = client.Execute(queryRequst);

            if (queryResponse.Code == "10000")
            {
                _log.Info("支付宝查询成功!");
                queryBack = new QueryOrderBack()
                {
                    Buyer_Logon_Id        = queryResponse.BuyerLogonId,
                    Buyer_Pay_Amount      = Convert.ToDecimal(queryResponse.BuyerPayAmount),
                    Buyer_User_Id         = queryResponse.BuyerUserId,
                    Code                  = queryResponse.Code,
                    Discount_Goods_Detail = queryResponse.DiscountGoodsDetail,
                    Fund_Bill_List        = GetTradeFundBills(queryResponse.FundBillList),
                    Industry_Sepc_Detail  = queryResponse.IndustrySepcDetail,
                    Invoice_Amount        = Convert.ToDecimal(queryResponse.InvoiceAmount),
                    Msg                 = queryResponse.Msg,
                    Out_Trade_No        = queryResponse.OutTradeNo,
                    Point_Amount        = Convert.ToDecimal(queryResponse.PointAmount),
                    Receipt_Amount      = Convert.ToDecimal(queryResponse.ReceiptAmount),
                    Store_Name          = queryResponse.StoreName,
                    Sub_Code            = queryResponse.SubCode,
                    Sub_Msg             = queryResponse.SubMsg,
                    Total_Amount        = queryResponse.TotalAmount,
                    Trade_No            = queryResponse.TradeNo,
                    Voucher_Detail_List = GetVoucherDetails(queryResponse.VoucherDetailList),
                    Alipay_Store_ID     = queryResponse.AlipayStoreId,
                    Send_Pay_Date       = Convert.ToDateTime(queryResponse.SendPayDate),
                    Store_ID            = queryResponse.StoreId,
                    Terminal_ID         = queryResponse.TerminalId,
                    Trade_Status        = queryResponse.TradeStatus
                };
                message = "";
                return(true);
            }
            else
            {
                queryBack = null;
                message   = $"{ queryResponse.Msg},{queryResponse.SubMsg}";
                _log.Error($"支付宝查询失败:{message}");
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// 查询订单
        /// </summary>
        /// <param name="queryOrder">查询实体</param>
        /// <param name="queryOrderBack">查询返回实体</param>
        /// <param name="message">错误信息</param>
        /// <returns>交易是否成功</returns>
        internal bool QueryOrder(QueryOrder queryOrder, out QueryOrderBack queryOrderBack, out string message)
        {
            _log.Info("查询订单 QueryOrder 开始执行");
            var data = new WxPayData();

            if (string.IsNullOrEmpty(queryOrder.Out_Trade_No))
            {
                message = "商户订单号 不能为空";
                _log.Error(message);
                queryOrderBack = null;
                return(false);
            }
            data.SetValue("out_trade_no", queryOrder.Out_Trade_No);
            //查询订单
            _log.Info("查询订单 WxPayApi.OrderQuery");
            var result = WxPayApi.OrderQuery(data);

            _log.Info("OrderQuery", "OrderQuery process complete, result : " + result.ToXml());
            var return_code = result.GetValue("return_code")?.ToString().ToUpper();
            var result_code = result.GetValue("result_code")?.ToString().ToUpper();

            if (return_code == "SUCCESS" && result_code == "SUCCESS")
            {
                _log.Info("查询订单成功!");
                queryOrderBack = new QueryOrderBack()
                {
                    Result_Code          = result.GetValue("result_code")?.ToString(),
                    Err_Code             = result.GetValue("result_code")?.ToString(),
                    Err_Code_Des         = result.GetValue("result_code")?.ToString(),
                    Trade_Type           = result.GetValue("trade_type")?.ToString(),
                    Trade_State          = result.GetValue("trade_state")?.ToString(),
                    Bank_Type            = result.GetValue("bank_type")?.ToString(),
                    Total_Fee            = Convert.ToInt32(result.GetValue("total_fee")),
                    Settlement_Total_Fee = Convert.ToInt32(result.GetValue("settlement_total_fee")),
                    Fee_Type             = result.GetValue("fee_type")?.ToString(),
                    Cash_Fee             = Convert.ToInt32(result.GetValue("cash_fee")),
                    Cash_Fee_Type        = result.GetValue("cash_fee_type ")?.ToString(),
                    Coupon_Fee           = result.GetValue("coupon_fee") == null ? 0 : Convert.ToInt32(result.GetValue("coupon_fee")),
                    Coupon_Count         = result.GetValue("coupon_count") == null ? 0 : Convert.ToInt32(result.GetValue("coupon_count")),
                    Coupon_Type_Sn       = result.GetValue("coupon_type_$n")?.ToString(),
                    Coupon_Id_Sn         = result.GetValue("coupon_id_$n")?.ToString(),
                    Coupon_Fee_Sn        = result.GetValue("coupon_fee_$n") == null ? 0 : Convert.ToInt32(result.GetValue("coupon_fee_$n")),
                    Transaction_Id       = result.GetValue("transaction_id")?.ToString(),
                    Out_Trade_No         = result.GetValue("err_code_des")?.ToString(),
                    Attach           = result.GetValue("attach")?.ToString(),
                    Time_End         = result.GetValue("time_end")?.ToString(),
                    Trade_State_Desc = result.GetValue("trade_state_desc")?.ToString()
                };
                message = "";
                return(true);
            }
            else
            {
                var return_msg   = result.GetValue("return_msg");
                var err_code_des = result.GetValue("err_code_des");
                message = $"{return_msg},{err_code_des}";
                _log.Error($"查询订单失败:{message}");
                queryOrderBack = null;
                return(false);
            }
        }