Esempio n. 1
0
        public void WeiXinNotify()
        {
            ResultNotify resultNotify = new ResultNotify();
            WxPayData    notifyData   = resultNotify.GetNotifyData();

            LogUtil.Log("微信支付返回接口接收:", notifyData.ToXml());
            if (notifyData.GetValue("return_code") != null && (notifyData.GetValue("return_code").ToString() == "SUCCESS") && notifyData.GetValue("out_trade_no") != null && notifyData.GetValue("transaction_id") != null)
            {
                string           paycode   = notifyData.GetValue("out_trade_no").ToString();
                decimal          fee       = StringUtils.GetDbDecimal(notifyData.GetValue("total_fee")) / 100;
                VWPayOrderEntity payentity = PayOrderBLL.Instance.GetVWPayOrderByPayCode(paycode);
                if (payentity.Id > 0 && payentity.Status == 0)//未支付完成
                {
                    payentity.PayTime      = DateTime.Now;
                    payentity.PayPrice     = fee;
                    payentity.ExternalCode = notifyData.GetValue("transaction_id").ToString();
                    payentity.Status       = 1;
                    //先更新业务网站收款记录
                    if (payentity.SysType == (int)SystemType.B2B || payentity.SysType == (int)SystemType.B2BMobile)
                    {
                        VWOrderEntity _order = OrderBLL.Instance.GetVWOrderByCode(StringUtils.GetDbLong(payentity.SysOrderCode));
                        if (_order.Status == (int)OrderStatus.WaitPay)
                        {
                            if (OrderBLL.Instance.PayFinishedForOrder(StringUtils.GetDbLong(payentity.SysOrderCode), fee) > 0)
                            {
                                ///业务网站状态更新后更新支付总表
                                PayOrderBLL.Instance.RecivedPaySuccess(payentity);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        // GET: Payover
        public ActionResult Index()
        {
            Log.Debug("收到通知:", "收到通知");
            //微信会把付款结果通知到这里
            ResultNotify resultNotify = new ResultNotify(System.Web.HttpContext.Current);
            WxPayData    notifyData   = resultNotify.GetNotifyData();
            //序列化  notifyData
            NotifyModel notify = new NotifyModel();

            notify = JSONHelper.JsonDeserialize <NotifyModel>(notifyData.ToJson());

            //////////这个必须给微信的通知回复收到信息,不然微信会一直发8次 ///////
            WxPayData res = new WxPayData();

            res.SetValue("return_code", "SUCCESS");
            res.SetValue("return_msg", "OK");
            HttpContext.Response.Clear();
            HttpContext.Response.Write(res.ToXml());
            HttpContext.Response.End();
            //////////回复结束//////////////
            Log.Debug("通知结束:", "通知结束");

            if (notify.result_code == "SUCCESS" && notify.return_code == "SUCCESS" && !string.IsNullOrEmpty(notify.out_trade_no) && !string.IsNullOrEmpty(notify.transaction_id))
            {
                //根据后台的充值记录
                // Log.Debug("微信支付结果通知:", "序列化后的openid:" + notify.openid);
                //Log.Debug("微信支付结果通知:", "序列化后的total_fee(该字段返回来的单位是分):" + notify.total_fee);
                //Log.Debug("微信支付结果通知:", "序列化后的out_trade_no:" + notify.out_trade_no);
                //Log.Debug("微信支付结果通知:", "序列化后的transaction_id:" + notify.transaction_id);
                //Log.Debug("微信支付结果通知:", "序列化后的notifyData:" + notifyData.ToJson());

                //OverAddFee(out_trade_no,openid) openid?
                //填写记录
                //using (var balancebLL = new BalanceBLL())
                //{
                //    balancebLL.PayOk(notify.out_trade_no).ConfigureAwait(true);
                //}
            }


            return(View());
        }
        /// <summary>
        /// 支付结果回调地址
        /// </summary>
        /// <returns></returns>
        public string PayNotifyUrl()
        {
            WxPayData resultInfo = new WxPayData();

            try
            {
                ResultNotify resultNotify       = new ResultNotify();
                WxPayData    notifyData         = resultNotify.GetNotifyData(); //获取微信返回的数据
                string       accessToken        = WeChatTools.GetAccessoken();
                var          userInfoStr        = WeChatTools.ConvertToUserIdByOpenid(accessToken, notifyData.GetValue("openid").ToString());
                var          userInfo           = Common.JsonHelper.JsonToModel <U_WechatUserInfo>(userInfoStr);
                var          userid             = userInfo.userid;
                var          personInfoModel    = _wl.GetUserInfo(userid);   //获取人员表信息
                var          paymentHistoryInfo = new Business_PaymentHistory_Information();
                paymentHistoryInfo.PaymentPersonnel = personInfoModel.Vguid; //付款人vguid
                _weChatRevenueLogic.UpdatePaymentHistory(personInfoModel, paymentHistoryInfo, notifyData);

                if (notifyData.GetValue("return_code").ToString() == "SUCCESS" && notifyData.GetValue("result_code").ToString() == "SUCCESS")
                {
                    resultInfo.SetValue("return_code", "SUCCESS");
                    resultInfo.SetValue("return_msg", "OK");
                }
                else
                {
                    resultInfo.SetValue("return_code", notifyData.GetValue("return_code").ToString());
                    resultInfo.SetValue("return_msg", notifyData.GetValue("return_msg").ToString());
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex.ToString());
                resultInfo.SetValue("return_code", "FAIL");
                resultInfo.SetValue("return_msg", "交易失败");
            }
            return(resultInfo.ToXml());
        }