Exemplo n.º 1
0
        /// <summary>
        /// 微信退单
        /// </summary>
        /// <param name="dingdan"></param>
        /// <param name="dto"></param>
        /// <param name="returnMsg"></param>
        /// <returns></returns>
        private bool WeChatRefund(wx_hotel_dingdan dingdan, TuidanDto dto, int wid, out string returnMsg)
        {
            bool result = false;

            returnMsg = null;

            var refundResult = dingdanbll.GetWeChatRefundParams(wid, dingdan.hotelid.Value, dingdan.id, dto.refundCode);

            //使用系统订单号退单
            if (refundResult != null && refundResult.Tables.Count > 0 && refundResult.Tables[0].Rows.Count > 0)
            {
                var orderNumber    = refundResult.Tables[0].Rows[0]["orderNumber"].ToString();
                var transaction_id = refundResult.Tables[0].Rows[0]["transaction_id"].ToString();
                var refundAmount   = Convert.ToInt32(refundResult.Tables[0].Rows[0]["refundAmount"]);
                var payAmount      = Convert.ToInt32(refundResult.Tables[0].Rows[0]["payAmount"]);


                var wxModel = new BLL.wx_userweixin().GetModel(wid);
                var payInfo = new BLL.wx_payment_wxpay().GetModelByWid(wid);

                var requestHandler = new RequestHandler(null);
                requestHandler.SetParameter("out_trade_no", orderNumber);
                //requestHandler.SetParameter("transaction_id", transaction_id);
                requestHandler.SetParameter("out_refund_no", dto.refundCode);
                requestHandler.SetParameter("appid", wxModel.AppId);
                requestHandler.SetParameter("mch_id", payInfo.mch_id);//商户号
                requestHandler.SetParameter("nonce_str", Guid.NewGuid().ToString().Replace("-", ""));

                //退款金额
                if (PayHelper.IsDebug)
                {
                    requestHandler.SetParameter("total_fee", (payAmount).ToString());
                    requestHandler.SetParameter("refund_fee", (refundAmount).ToString());
                }
                else
                {
                    requestHandler.SetParameter("total_fee", (payAmount * 100).ToString());
                    requestHandler.SetParameter("refund_fee", (refundAmount * 100).ToString());
                }

                requestHandler.SetParameter("op_user_id", wxModel.AppId);
                requestHandler.SetParameter("sign", requestHandler.CreateMd5Sign("key", payInfo.paykey));

                var refundInfo          = TenPayV3Helper.Refund(requestHandler.ParseXML(), string.Format(@"{0}{1}", AppDomain.CurrentDomain.BaseDirectory, payInfo.certInfoPath), payInfo.cerInfoPwd);
                var refundOrderResponse = new RefundOrderResponse(refundInfo);

                result    = refundOrderResponse.IsSuccess;
                returnMsg = refundOrderResponse.return_msg;
            }

            return(result);
        }
Exemplo n.º 2
0
        protected void btnAgreeRefund_Click(object sender, EventArgs e)
        {
            try
            {
                var refundBll    = new BLL.wx_diancai_tuidan_manage();
                var refundResult = refundBll.GetWeChatRefundParams(shopid, orderID, refundCode);

                //使用系统订单号退单
                if (refundResult != null && refundResult.Tables.Count > 0 && refundResult.Tables[0].Rows.Count > 0)
                {
                    var orderNumber    = refundResult.Tables[0].Rows[0]["orderNumber"].ToString();
                    var transaction_id = refundResult.Tables[0].Rows[0]["transaction_id"].ToString();
                    var refundAmount   = Convert.ToInt32(refundResult.Tables[0].Rows[0]["refundAmount"]);
                    var payAmount      = Convert.ToInt32(refundResult.Tables[0].Rows[0]["payAmount"]);

                    var shopInfo = new BLL.wx_diancai_shopinfo().GetModel(shopid);
                    var wxModel  = new BLL.wx_userweixin().GetModel((int)shopInfo.wid);
                    var payInfo  = new BLL.wx_payment_wxpay().GetModelByWid((int)shopInfo.wid);

                    var requestHandler = new RequestHandler(null);
                    requestHandler.SetParameter("out_trade_no", orderNumber);
                    //requestHandler.SetParameter("transaction_id", transaction_id);
                    requestHandler.SetParameter("out_refund_no", refundCode);
                    requestHandler.SetParameter("appid", wxModel.AppId);
                    requestHandler.SetParameter("mch_id", payInfo.mch_id);//商户号
                    requestHandler.SetParameter("nonce_str", Guid.NewGuid().ToString().Replace("-", ""));

                    //退款金额
                    if (PayHelper.IsDebug)
                    {
                        requestHandler.SetParameter("total_fee", (payAmount / 100).ToString());
                        requestHandler.SetParameter("refund_fee", (refundAmount / 100).ToString());
                    }
                    else
                    {
                        requestHandler.SetParameter("total_fee", payAmount.ToString());
                        requestHandler.SetParameter("refund_fee", refundAmount.ToString());
                    }

                    requestHandler.SetParameter("op_user_id", wxModel.AppId);
                    requestHandler.SetParameter("sign", requestHandler.CreateMd5Sign("key", payInfo.paykey));

                    var refundInfo          = TenPayV3Helper.Refund(requestHandler.ParseXML(), string.Format(@"{0}{1}", AppDomain.CurrentDomain.BaseDirectory, payInfo.certInfoPath), payInfo.cerInfoPwd);
                    var refundOrderResponse = new RefundOrderResponse(refundInfo);
                    if (refundOrderResponse.IsSuccess)
                    {
                        new BLL.wx_diancai_tuidan_manage().RefundComplete(refundCode, this.txtRefundReason.Value.Trim());
                        Response.Redirect("diancai_dingdanRefund_manage.aspx");
                    }
                    else
                    {
                        Response.Write(refundOrderResponse.return_msg);
                        List();
                    }
                }
            }
            catch (Exception exception)
            {
                Response.Write(exception.Message);
                Response.Write(exception.StackTrace);
                List();
            }
        }