Example #1
0
        public void WxRefundNotify()
        {
            WxPayData res = new WxPayData();

            try
            {
                Notify    notify     = new Notify(this);
                WxPayData notifyData = notify.GetRefundNotifyData();
                if (!notifyData.IsSet("return_code") || notifyData.GetValue("return_code").ToString() != "SUCCESS")
                {
                    goto TheEnd;
                }

                // 回调通知成功,取得密文
                var reqCiphertext = notifyData.GetValue("req_info").ToString();
                // 解密
                var key       = MD5Helper.ToMd5Bit32(PayConfig.WxKey());
                var clearText = MD5Helper.AESDecrypt(reqCiphertext, key);

                //转换数据格式
                WxPayData reqCipherData = new WxPayData();
                try { reqCipherData.FromXml(clearText, false); }
                catch (WxPayException) { }

                var refundStatus   = reqCipherData.GetValue("refund_status").ToString();
                var otherRefundNum = reqCipherData.GetValue("out_refund_no").ToString();
                var refundNo       = reqCipherData.GetValue("out_trade_no").ToString();

                if (refundStatus.ToUpper() == "SUCCESS")
                {
                    // 修改订单状态
                    ResultModel <Bis_Record> result = new RecordService().ModifyOrderStatusRefund(refundNo, otherRefundNum);
                    if (result.status > 0)
                    {
                        if (result.data != null)
                        {
                            // 修改退款单状态
                            new RefundService().UpdateRefundStatus(result.data.RecordID, otherRefundNum, Order_Status.Refunded);
                            // 退款成功,修改订单状态成功之后
                            // 推送微信通知消息
                            SendMsgRefund(result.data);
                        }
                        res.SetValue("return_code", "SUCCESS");
                        res.SetValue("return_msg", "OK");
                        Response.Write(res.ToXml());
                        Response.End();
                        return;
                    }
                }

TheEnd:
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "FAIL");
                Response.Write(res.ToXml());
                Response.End();
            }
            catch (Exception ex)
            {
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "FAIL");
                Response.Write(res.ToXml());
                Response.End();
                MYLog.Error("退款回调", ex.ToString());
            }
        }