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 = "" }); }
/// <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(); } } }