public object QCTPayCallBack([FromBody] JObject obj)
        {
            var mch_id         = Convert.ToInt32(obj.Property("mch_id"));           //
            var store_id       = obj.Property("store_id").ToString();               //门店
            var out_trade_no   = obj.Property("out_trade_no").ToString();           //单号
            var receipt_amount = Convert.ToDecimal(obj.Property("receipt_amount")); //支付金额
            var pay_status     = obj.Property("pay_status").ToString();             //notpay=支付中;paysuccess=支付成功;payfail=支付失败;paycancel=已撤销;paytimeout=支付

            if (pay_status != "NOTPAY")
            {
                PayNotifyResultService.AddOne(new Logic.Entity.PayNotifyResult()
                {
                    ApiCode = 25, CashFee = receipt_amount, CompanyId = mch_id, CreateDT = DateTime.Now, PaySN = out_trade_no, TradeNo = string.Empty, State = pay_status
                });
            }
            return(new { return_code = "00000", return_msg = "" });
        }
        public int GetStatus(int apiCode, string paySn)
        {
            var entity = PayNotifyResultService.Find(o => o.ApiCode == apiCode && o.PaySN == paySn);

            if (entity == null)
            {
                return(0);
            }
            else if (entity.State == "Success")
            {
                return(1);
            }
            else
            {
                return(-1);
            }
        }
        public ThirdPartyPaymentStatus GetPayStatus()
        {
            var payConfig = BaseGeneralService <Pharos.Logic.Entity.PayConfiguration, EFDbContext> .Find(o => o.CompanyId == CompanyId && o.PayType == 25);

            var ordersn = ShoppingCartFactory.Factory(StoreId, MachineSn, CompanyId, DeviceSn).PayOrderSn;
            var storePaymentAuthorization = BaseGeneralService <Pharos.Logic.Entity.StorePaymentAuthorization, EFDbContext> .Find(o => o.CompanyId == CompanyId && o.PayType == 25 && o.StoreId == StoreId);

            var mic    = int.Parse(payConfig.PaymentMerchantNumber);
            var entity = PayNotifyResultService.Find(o => o.ApiCode == 25 && o.PaySN == ordersn && o.CompanyId == mic);

            if (entity == null)
            {
                return(ThirdPartyPaymentStatus.Unknown);
            }
            else if (entity.State == "PAYSUCCESS")
            {
                return(ThirdPartyPaymentStatus.Complete);
            }
            else
            {
                return(ThirdPartyPaymentStatus.Error);
            }
        }
Exemple #4
0
        /// <summary>
        /// 接口调用请求
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private object PostPay(string url, SortedDictionary <string, object> obj)
        {
            Stream          requestStream  = null;
            StreamReader    sr             = null;
            HttpWebResponse response       = null;
            Stream          responseStream = null;

            try
            {
                StringBuilder signdatasb = new StringBuilder();
                foreach (var item in obj)
                {
                    string key   = item.Key;
                    string value = obj[key] == null ? "" : obj[key].ToString();
                    signdatasb.Append("&").Append(key).Append("=").Append(value);
                }
                byte[] byteRequest = Encoding.UTF8.GetBytes(signdatasb.ToString().Substring(1));

                var httpRequest = (HttpWebRequest)WebRequest.Create(url);

                httpRequest.Method        = "POST";
                httpRequest.ContentType   = "application/x-www-form-urlencoded";
                httpRequest.ContentLength = byteRequest.Length;
                httpRequest.Timeout       = 40000;
                requestStream             = httpRequest.GetRequestStream();
                requestStream.Write(byteRequest, 0, byteRequest.Length);
                requestStream.Close();

                //获取服务端返回
                response = (HttpWebResponse)httpRequest.GetResponse();
                //获取服务端返回数据
                sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                var result = sr.ReadToEnd().Trim();
                sr.Close();
                JsonConvert.DeserializeObject(result);
                var rspObj = JsonConvert.DeserializeObject <JObject>(result);
                if (rspObj.Property("return_code").Value.ToString() == "00000" && rspObj.Property("pay_status").Value.ToString() == "PAYSUCCESS")
                {
                    PayNotifyResultService.AddOne(new Logic.Entity.PayNotifyResult()
                    {
                        ApiCode = 26, CashFee = Convert.ToDecimal(rspObj.Property("receipt_amount").Value.ToString()), CompanyId = Convert.ToInt32(rspObj.Property("mch_id").Value), CreateDT = DateTime.Now, PaySN = rspObj.Property("out_trade_no").Value.ToString(), TradeNo = string.Empty, State = rspObj.Property("pay_status").Value.ToString()
                    });

                    return(rspObj.Property("out_trade_no").Value.ToString());
                    //todo:记录请求成功数据
                }
                else
                {
                    PayNotifyResultService.AddOne(new Logic.Entity.PayNotifyResult()
                    {
                        ApiCode = 26, CashFee = Convert.ToDecimal(rspObj.Property("receipt_amount").Value.ToString()), CompanyId = Convert.ToInt32(rspObj.Property("mch_id").Value), CreateDT = DateTime.Now, PaySN = rspObj.Property("out_trade_no").Value.ToString(), TradeNo = string.Empty, State = rspObj.Property("pay_status").Value.ToString()
                    });

                    throw new PosException("支付请求失败!");
                }
            }
            catch (WebException ex)
            {
                throw new PosException("支付请求失败,网络错误!");
            }
            finally
            {
                if (requestStream != null)
                {
                    requestStream.Close();
                }
                if (sr != null)
                {
                    sr.Close();
                }
                if (response != null)
                {
                    response.Close();
                }
                if (responseStream != null)
                {
                    responseStream.Close();
                }
            }
        }