public object RefundOrder([FromBody] JObject _obj) { var reqParams = new SortedDictionary <string, object>(); reqParams.Add("charset", "utf-8"); reqParams.Add("method", "qct.trade.refund.apply"); reqParams.Add("mch_id", _obj.Property("mch_id", true)); reqParams.Add("store_id", _obj.Property("store_id", true)); reqParams.Add("device_id", _obj.Property("device_id", true)); reqParams.Add("refund_amount", _obj.Property("refund_amount", true)); reqParams.Add("sign_type", "MD5"); reqParams.Add("version", "1.0"); reqParams.Add("out_refund_no", _obj.Property("out_refund_no", true)); reqParams.Add("out_trade_no", _obj.Property("out_trade_no", true)); reqParams.Add("create_date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); reqParams.Add("refund_notify_url", ""); reqParams.Add("refund reason", ""); //签名 String sign = PayHelper.Sign(reqParams, "1A064D83D7D043DB8DE76D4C15694C98"); reqParams.Add("sign", sign); var obj = HttpClient.PayPost("http://test.pay.qcterp.com/api/pay/refund", reqParams); var result = JsonConvert.DeserializeObject <JObject>(obj); if (result.Property("return_code").Value.ToString() == "00000") { return("success"); } else { return(result.Property("return_msg").Value.ToString()); } }
public ActionResult Index() { string privateKey = ConfigurationManager.AppSettings["privateKey"]; PayShowModel payShowModel = new PayShowModel() { tradeNo = Guid.NewGuid().ToString("N") }; Dictionary <string, object> dict = new Dictionary <string, object>(); dict.Add("signType", "RSA"); dict.Add("appId", "qTCH30NzGx4Kws9k"); dict.Add("payMode", "ActiveCode"); dict.Add("tradeType", ConfigurationManager.AppSettings["tradeType"]); dict.Add("merchantSn", ConfigurationManager.AppSettings["merchantSn"]); dict.Add("outTradeNo", payShowModel.tradeNo); dict.Add("totalFee", 1); dict.Add("notifyUrl", "https://uat_activity.niceloo.com/Notify");//HttpUtility.UrlEncode(" dict.Add("attach", "000"); string sign = PayHelper.Sign(dict, privateKey); dict.Add("goodsBody", "商品名称介绍"); dict.Add("goodsDetail", "商品详细介绍"); dict.Add("sign", sign); //发送请求 string result = PayHelper.SendPost("https://open.smart4s.com/Api/Service/Pay/Mode/trade", dict); Response.Write("请求结果:" + result); PayResult payResult = Newtonsoft.Json.JsonConvert.DeserializeObject <PayResult>(result); if (payResult != null && payResult.data != null) { payShowModel.PayImgUrl = PayHelper.GenerateImgCode("", payResult.data.payQRCodeUrl); } return(View(payShowModel)); }
/// <summary> /// 检查交易状态 /// </summary> /// <param name="tradeNo"></param> /// <returns></returns> public ActionResult CheckTrade(string tradeNo) { try { string privateKey = ConfigurationManager.AppSettings["privateKey"]; string sign = ""; Dictionary <string, object> dict = new Dictionary <string, object>(); dict.Add("signType", "RSA"); dict.Add("appId", "qTCH30NzGx4Kws9k"); dict.Add("merchantSn", "TEST0000000001"); dict.Add("outOrderNo", tradeNo); sign = PayHelper.Sign(dict, privateKey); dict.Add("sign", sign); //发送请求 string result = PayHelper.SendPost("https://open.smart4s.com/Api/Service/Pay/Mode/query", dict); LogHelper.WriteInfoLog(result); PayQuery payResult = Newtonsoft.Json.JsonConvert.DeserializeObject <PayQuery>(result); if (payResult != null) { return(Json(new { payResult.errCode, status = payResult.data.tradeStatus, msg = payResult.data.tradeMsg, result })); } else { return(Json(new { errCode = "-1", status = -99, msg = "请求失败", result })); } } catch (Exception ex) { return(Json(new { errCode = "-1", status = -100, msg = "查询异常", result = ex.ToString() })); } }
public object PayMerchScanDyna(AppPayRequest param) { try { int cid = param.CID; var storeId = param.StoreId; string mapcid = string.Empty; //查询门店支付授权 var authorization = GetCompanyPayInfo(cid, storeId, PayConst.QCTAPICODE_A, out mapcid);//26=主扫支付apicode if (!authorization.Successed) { throw new MessageException(authorization.Message); } var payStoreId = authorization.Data.ToString();//中转第三方门店号 //验证用户信息 if (!string.IsNullOrEmpty(param.MemberId)) { var veriMemberIntegral = VeriMemberIntegral(param.MemberId, param.UseIntegral); if (!veriMemberIntegral.Successed) { throw new MessageException(veriMemberIntegral.Message); } } if (param.PayToken.Length == 0 || param.PayToken.Length > 128) { throw new MessageException("扫码二维码有误!"); } string out_trade_no = new AppPayOrderSn(cid, storeId).ToString(); string create_date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); var pay_notify_url = Pharos.Utility.Config.GetAppSettings("qctpaynotifyurl");//回调地址 var goods_name = ""; //var goods_desc = ""; //判断用户积分使用 #region 积分记录 IntegralFlows reduceIntegral = new IntegralFlows() { CompanyId = cid, StoreId = storeId, FlowSN = out_trade_no, Amount = param.TotalAmount, Integral = -param.UseIntegral, DiscountAmount = param.DiscountAmount, CardSN = param.CardSN, Received = param.Received, Remark = "", State = 0, CreateDate = DateTime.Now, MemberId = param.MemberId, Alias = param.Alias }; IntegralFlows addIntegral = new IntegralFlows() { CompanyId = cid, StoreId = storeId, FlowSN = out_trade_no, Amount = param.TotalAmount, Integral = param.GetIntegral, DiscountAmount = param.DiscountAmount, CardSN = param.CardSN, Received = param.Received, Remark = "", State = 0, CreateDate = DateTime.Now, MemberId = param.MemberId, Alias = param.Alias }; IntegralFlowsService.Add(reduceIntegral, false); IntegralFlowsService.Add(addIntegral); #endregion var reqParams = new SortedDictionary <string, object>(); reqParams.Add("charset", PayConst.CHARSET); reqParams.Add("method", PayConst.QCTTRADE_PAY_MERCHSCAN); reqParams.Add("mch_id", mapcid); reqParams.Add("store_id", payStoreId); reqParams.Add("device_id", param.Device_id); reqParams.Add("sign_type", PayConst.SIGNTYPE); reqParams.Add("version", PayConst.VERSION); reqParams.Add("out_trade_no", out_trade_no); reqParams.Add("create_date", create_date); reqParams.Add("total_amount", param.Received); reqParams.Add("buyer_pay_token", param.PayToken); reqParams.Add("pay_notify_url", pay_notify_url); reqParams.Add("buyer_mobile", ""); reqParams.Add("goods_name", goods_name); reqParams.Add("goods_desc", param.Remark); //签名 String sign = PayHelper.Sign(reqParams, authorization.Message); reqParams.Add("sign", sign); var obj = HttpClient.PayPost(Pharos.Utility.Config.GetAppSettings("qctscanpayurl"), reqParams); var result = JsonConvert.DeserializeObject <JObject>(obj); if (result.Property("return_code").Value.ToString() == "00000") { int state = 0; var rstate = result.Property("pay_status", true); switch (rstate) { default: case "NOTPAY": break; case "PAYSUCCESS": state = 1; break; case "PAYFAIL": state = 2; break; case "PAYCANCEL": state = 3; break; case "PAYTIMEOUT": state = 4; break; } AppPaymentRecords record = new AppPaymentRecords() { CompanyId = cid, StoreId = storeId, OrderSN = out_trade_no, TotalAmount = param.TotalAmount, DiscountAmount = param.DiscountAmount, Received = param.Received, ApiCode = PayConst.QCTAPICODE_A, PayChannel = result.Property("pay_channel", true), State = state, CreateDate = DateTime.Now, CreateUser = param.MemberId, ReturnData = obj, Alias = param.Alias, UserCode = param.UserCode, Remark = param.Remark }; AppPaymentRecordsService.Add(record); //成功 if (state == 1) { //更新会员积分信息 var diffIntegral = param.GetIntegral - param.UseIntegral; if (diffIntegral != 0) { UpdateMemberIntegral(param.MemberId, diffIntegral); } return(result.Property("receipt_amount", true)); } else {//状态不成功 return(result.Property("pay_status", true)); } } else { //失败 var errmsg = result.Property("return_msg").Value.ToString(); if (errmsg.Contains("支付渠道数据非法")) { errmsg = "请扫描微信或支付宝付款码!"; } throw new MessageException(errmsg); } } catch (Exception ex) { throw new MessageException(ex.Message); } }
public object PayBuyerScanDyna(AppPayRequest param) { try { int cid = param.CID; var storeId = param.StoreId; string mapcid = string.Empty; //查询门店支付授权 var authorization = GetCompanyPayInfo(cid, storeId, PayConst.QCTAPICODE_P, out mapcid); if (!authorization.Successed) { throw new MessageException(authorization.Message); } var payStoreId = authorization.Data.ToString();//中转第三方门店号 if (!string.IsNullOrEmpty(param.MemberId)) { var veriMemberIntegral = VeriMemberIntegral(param.MemberId, param.UseIntegral); if (!veriMemberIntegral.Successed) { throw new MessageException(veriMemberIntegral.Message); } } string out_trade_no = new AppPayOrderSn(cid, storeId).ToString(); string create_date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); var pay_notify_url = Pharos.Utility.Config.GetAppSettings("qctpaynotifyurl");//回调地址 var goods_name = ""; //var goods_desc = ""; var reqParams = new SortedDictionary <string, object>(); reqParams.Add("charset", PayConst.CHARSET); reqParams.Add("method", PayConst.QCTTRADE_PAY_BUYERSCAN_DYNA); reqParams.Add("mch_id", mapcid); reqParams.Add("store_id", payStoreId); reqParams.Add("device_id", param.Device_id); reqParams.Add("sign_type", PayConst.SIGNTYPE); reqParams.Add("version", PayConst.VERSION); reqParams.Add("out_trade_no", out_trade_no); reqParams.Add("create_date", create_date); reqParams.Add("total_amount", param.Received); reqParams.Add("pay_notify_url", pay_notify_url); reqParams.Add("buyer_mobile", ""); reqParams.Add("goods_name", goods_name); reqParams.Add("goods_desc", param.Remark); //签名 String sign = PayHelper.Sign(reqParams, authorization.Message); reqParams.Add("sign", sign); var obj = HttpClient.PayPost(Pharos.Utility.Config.GetAppSettings("qctpayurl"), reqParams); var result = JsonConvert.DeserializeObject <JObject>(obj); if (result.Property("return_code").Value.ToString() == "00000") { //成功 //支付交易记录 AppPaymentRecords record = new AppPaymentRecords() { CompanyId = cid, StoreId = storeId, OrderSN = out_trade_no, TotalAmount = param.TotalAmount, DiscountAmount = param.DiscountAmount, Received = param.Received, ApiCode = PayConst.QCTAPICODE_P, State = 0, CreateDate = DateTime.Now, CreateUser = param.MemberId, Alias = param.Alias, UserCode = param.UserCode, Remark = param.Remark }; AppPaymentRecordsService.Add(record, false); //积分交易记录 //消耗 IntegralFlows reduceIntegral = new IntegralFlows() { CompanyId = cid, StoreId = storeId, FlowSN = out_trade_no, Amount = param.TotalAmount, Integral = -param.UseIntegral, DiscountAmount = param.DiscountAmount, CardSN = param.CardSN, Received = param.Received, Remark = "", State = 0, CreateDate = DateTime.Now, MemberId = param.MemberId, Alias = param.Alias }; //获取 IntegralFlows addIntegral = new IntegralFlows() { CompanyId = cid, StoreId = storeId, FlowSN = out_trade_no, Amount = param.TotalAmount, Integral = param.GetIntegral, DiscountAmount = param.DiscountAmount, CardSN = param.CardSN, Received = param.Received, Remark = "", State = 0, CreateDate = DateTime.Now, MemberId = param.MemberId, Alias = param.Alias }; //保存积分记录 IntegralFlowsService.Add(reduceIntegral, false); IntegralFlowsService.Add(addIntegral); return(new { OrderSN = out_trade_no, PayUrl = result.Property("pay_token").Value.ToString() }); } else { //失败 var errmsg = result.Property("return_msg").Value.ToString(); throw new MessageException(errmsg); } } catch (MessageException ex) { throw new MessageException(ex.Message); } catch (Exception ex) { throw new MessageException("支付失败,请稍后重试!"); } }
public object TradeNotify([FromBody] JObject obj) { //更新会员积分信息 var charset = obj.Property("charset", true); var cid = Convert.ToInt32(obj.Property("mch_id", true)); // var storeId = obj.Property("store_id", true); //门店 var orderSN = obj.Property("out_trade_no", true); //单号 var amount = obj.Property("receipt_amount", true); //支付金额 var payState = obj.Property("pay_status", true); //notpay=支付中;paysuccess=支付成功;payfail=支付失败;paycancel=已撤销;paytimeout=支付超时 var tradeDate = obj.Property("trade_date", true); //支付时间 var channel = obj.Property("pay_channel", true); //支付渠道 var deviceId = obj.Property("device_id", true); //设备编号 var signType = obj.Property("sign_type", true); var sign = obj.Property("sign", true); var version = obj.Property("version", true); var method = obj.Property("method", true); //验证签名 var reqParams = new SortedDictionary <string, object>(); reqParams.Add("charset", charset); reqParams.Add("method", PayConst.QCTTRADE_NOTIFY_PAY); reqParams.Add("mch_id", cid); reqParams.Add("store_id", storeId); reqParams.Add("device_id", deviceId); reqParams.Add("sign_type", signType); reqParams.Add("version", version); reqParams.Add("out_trade_no", orderSN); reqParams.Add("receipt_amount", amount); reqParams.Add("pay_status", payState); reqParams.Add("pay_channel", channel); reqParams.Add("trade_date", tradeDate); string mapcid = string.Empty; //查询门店支付授权 var authorization = GetCompanyPayInfo(cid, storeId, PayConst.QCTAPICODE_P, out mapcid, true); int _cid = Convert.ToInt32(mapcid); if (!authorization.Successed) { throw new MessageException("门店信息错误"); } var alias = new string[1]; //签名 string localsign = PayHelper.Sign(reqParams, authorization.Message); if (localsign == sign) { if (payState == "PAYSUCCESS") { var localStore = StorePaymentAuthorizationService.Find(o => o.CompanyId == _cid && o.MapPaymentStoreId == storeId && o.PayType == PayConst.QCTAPICODE_P && o.State == 1); if (localStore == null) { throw new MessageException("未找到门店授权信息!"); } //更新支付记录 var data = AppPaymentRecordsService.Find(o => o.CompanyId == _cid && o.StoreId == localStore.StoreId && o.OrderSN == orderSN); if (data != null) { if (data.State == 1) { goto gotoReturn; } data.State = 1; alias[0] = data.Alias; data.PayChannel = channel; data.ReturnData = obj.ToString(); AppPaymentRecordsService.Update(data); } //更新会员信息 var records = IntegralFlowsService.FindList(o => o.FlowSN == orderSN && o.CompanyId == cid); if (records != null) { //更新会员主表信息 var differentIntergral = 0m; foreach (var item in records) { item.State = 1; differentIntergral += item.Integral; } //更新积分交易流水状态 IntegralFlowsService.Update(new IntegralFlows()); if (differentIntergral != 0m) { UpdateMemberIntegral(records.FirstOrDefault().MemberId, differentIntergral); } } } } else { throw new MessageException("签名验证失败!"); } //通知手机 try { var pushData = new object(); if (alias.Length > 0 && payState == "PAYSUCCESS") { pushData = new { platform = "all", audience = new { alias = alias }, message = new { msg_content = JsonConvert.SerializeObject(new { method = "paynotify", data = new { ordersn = orderSN, date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), state = 1, amount = amount, descript = "成功支付!" } }), content_type = "text" } }; } else { pushData = new { platform = "all", audience = new { alias = alias }, message = new { msg_content = JsonConvert.SerializeObject(new { method = "paynotify", data = new { ordersn = orderSN, date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), state = 0, amount = amount, descript = "订单未成功支付!" } }), content_type = "text" } }; } JPushRestClient.Post <dynamic, JObject>(pushData); } catch (Exception) { } gotoReturn: return(new { return_code = "00000", return_msg = "接收成功" }); }