/// <summary> /// 查询退款状态 /// </summary> /// <param name="context"></param> /// <returns></returns> private string GetWeixinRefundInfo(HttpContext context) { string orderDetailId = context.Request["order_detail_id"]; if (string.IsNullOrEmpty(orderDetailId)) { resp.errcode = 1; resp.errmsg = "order_detail_id 参数不能为空"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } WXMallRefund model = bllMall.GetRefundInfoByOrderDetailId(int.Parse(orderDetailId)); ZentCloud.BLLJIMP.Model.PayConfig payConfig = bllPay.GetPayConfig(); string msg = ""; bool isSuccess = bllPay.QueryWeixinRefund(model.OrderDetailId.ToString(), model.WeiXinRefundId, payConfig.WXAppId, payConfig.WXMCH_ID, payConfig.WXPartnerKey, out msg); if (isSuccess) { return(ZentCloud.Common.JSONHelper.ObjectToJson(new { errcode = 0, refund_status = msg, })); } else { return(ZentCloud.Common.JSONHelper.ObjectToJson(new { errcode = 1, refund_status = msg, })); } }
/// <summary> /// 查询付款状态 /// </summary> /// <param name="context"></param> /// <returns></returns> private string GetWeixinTransferInfo(HttpContext context) { string orderDetailId = context.Request["order_detail_id"]; if (string.IsNullOrEmpty(orderDetailId)) { resp.errcode = 1; resp.errmsg = "order_detail_id 参数不能为空"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } WXMallRefund model = bllMall.GetRefundInfoByOrderDetailId(int.Parse(orderDetailId)); ZentCloud.BLLJIMP.Model.PayConfig payConfig = bllPay.GetPayConfig(); bool isSuccess = bllPay.GetWeixinTransferInfo(model.OrderId, payConfig.WXAppId, payConfig.WXMCH_ID, payConfig.WXPartnerKey); return(ZentCloud.Common.JSONHelper.ObjectToJson(new { errcode = 0, is_pay_success = isSuccess, })); }
public void ProcessRequest(HttpContext context) { string userId = context.Request["user_id"]; string amountStr = context.Request["amount"]; string orderSn = context.Request["order_sn"]; if (string.IsNullOrEmpty(userId) && string.IsNullOrEmpty(orderSn)) { resp.code = (int)APIErrCode.PrimaryKeyIncomplete; resp.msg = "user_id,order_sn 不能同时为空"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if ((!string.IsNullOrEmpty(userId)) && (!string.IsNullOrEmpty(orderSn))) { resp.code = (int)APIErrCode.PrimaryKeyIncomplete; resp.msg = "user_id,order_sn 不能同时传入"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (string.IsNullOrEmpty(amountStr)) { resp.code = (int)APIErrCode.PrimaryKeyIncomplete; resp.msg = "amount 参数必传"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } decimal amount = 0; if (!decimal.TryParse(amountStr, out amount)) { resp.code = (int)APIErrCode.OperateFail; resp.msg = "amount 参数错误"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (amount <= 0) { resp.code = (int)APIErrCode.OperateFail; resp.msg = "amount 需大于0"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } UserInfo userInfo = new UserInfo(); WXMallOrderInfo orderInfo = null; if (string.IsNullOrEmpty(userId) && (!string.IsNullOrEmpty(orderSn)))//给指定订单号打款 { orderInfo = bllMall.GetOrderInfoByOutOrderId(orderSn); if (orderInfo == null) { resp.code = (int)APIErrCode.OperateFail; resp.msg = "订单号不存在"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (amount > orderInfo.TotalAmount) { resp.code = (int)APIErrCode.OperateFail; resp.msg = "amount 不能大于订单总金额" + orderInfo.TotalAmount + "元"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } userInfo = bllUser.GetUserInfo(orderInfo.OrderUserID); } else if ((!string.IsNullOrEmpty(userId)) && (string.IsNullOrEmpty(orderSn)))//给指定用户打款 { userInfo = bllUser.GetUserInfo(userId); } if (userInfo == null)//指定用户不存在 { resp.code = (int)APIErrCode.OperateFail; resp.msg = "指定的用户不存在"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (string.IsNullOrEmpty(userInfo.WXOpenId)) { resp.code = (int)APIErrCode.OperateFail; resp.msg = "用户微信 OpenId不存在"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } ZentCloud.BLLJIMP.Model.PayConfig payConfig = bllPay.GetPayConfig(); if (payConfig == null) { resp.code = (int)APIErrCode.OperateFail; resp.msg = "未配置支付信息"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } if (string.IsNullOrEmpty(payConfig.WXAppId) || string.IsNullOrEmpty(payConfig.WXMCH_ID) || string.IsNullOrEmpty(payConfig.WXPartnerKey)) { resp.code = (int)APIErrCode.OperateFail; resp.msg = "支付配置信息不完整"; context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); return; } Log(string.Format("准备打款:订单号{0}金额{1}", orderInfo.OutOrderId, amountStr)); string msg = ""; string weiXinRefundId = "";//微信退款单号 string refundNumber = orderInfo.OutOrderId + System.Math.Round(bllMall.GetTimeStamp(DateTime.Now), 0).ToString(); bool isSuccess = bllPay.WeixinRefund(orderInfo.OrderID, refundNumber, orderInfo.TotalAmount, amount, payConfig.WXAppId, payConfig.WXMCH_ID, payConfig.WXPartnerKey, out msg, out weiXinRefundId); if ((!string.IsNullOrEmpty(msg)) && (msg.Contains("请使用可用余额退款"))) { isSuccess = bllPay.WeixinRefundYuEr(orderInfo.OrderID, refundNumber, orderInfo.TotalAmount, amount, payConfig.WXAppId, payConfig.WXMCH_ID, payConfig.WXPartnerKey, out msg, out weiXinRefundId); } if (isSuccess) { resp.status = true; resp.msg = "ok"; if (orderInfo != null) { if (orderInfo.Status == "待退押金中") { orderInfo.Ex10 = ""; orderInfo.Status = "交易成功"; } else { orderInfo.Status = "已取消"; } if (orderInfo.IsRefund == 1) { orderInfo.Status = "已取消"; orderInfo.IsRefund = 0; orderInfo.Ex11 = ""; } orderInfo.Ex8 = ""; orderInfo.Ex9 = ""; orderInfo.LastUpdateTime = DateTime.Now; orderInfo.Ex17 = weiXinRefundId; if (!bllMall.Update(orderInfo)) { var orderUserInfo = bllUser.GetUserInfo(orderInfo.OrderUserID); if (orderUserInfo != null) { string title = "您收到打款"; string content = string.Format("金额:{0}\\n备注:{1}", amount, orderInfo.Ex14); bllWeixin.SendTemplateMessageNotifyComm(orderUserInfo, title, content); } resp.msg = "更新订单状态失败"; Log(string.Format("更新订单状态失败:订单号{0}金额{1}", orderInfo.OutOrderId, amountStr)); } Log(string.Format("打款成功:订单号{0}金额{1}", orderInfo.OutOrderId, amountStr)); } } else { resp.code = (int)APIErrCode.OperateFail; resp.msg = msg; Log(string.Format("打款失败:订单号{0}金额{1}信息{2}", orderInfo.OutOrderId, amountStr, msg)); } context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); }
/// <summary> ///打款 /// </summary> /// <param name="context"></param> /// <returns></returns> private string Transfers(HttpContext context) { int successCount = 0; string orderIds = context.Request["order_ids"];//订单 orderIds = orderIds.TrimEnd(','); ZentCloud.BLLJIMP.Model.PayConfig payConfig = bllPay.GetPayConfig(); #region 团购-要先给团员退款 if (orderIds.Split(',').Count() == 1) { var order = bllMall.GetOrderInfo(orderIds.Split(',')[0]); if (order.OrderType == 2 && (string.IsNullOrEmpty(order.GroupBuyParentOrderId))) { //团长订单不能先退款,先退完团员才能退团长 if (bllMall.GetCount <WXMallOrderInfo>(string.Format(" GroupBuyParentOrderId='{0}' And PaymentStatus=1 And (Ex1 IS NULL Or Ex1 ='') And TotalAmount>0", order.OrderID)) > 0) { resp.errcode = 1; resp.errmsg = "请先给团员订单退款,然后给团长订单退款"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } } } #endregion foreach (string orderId in orderIds.Split(',')) { var orderInfo = bllMall.GetOrderInfo(orderId); if (orderInfo.WebsiteOwner != bllMall.WebsiteOwner) { continue; } if (orderInfo.TotalAmount > 0) { string msg = ""; #region 微信退款 if (orderInfo.PaymentType == 2) { string weixinRefundId = ""; if (bllPay.WeixinRefund(orderInfo.OrderID, orderInfo.OrderID, orderInfo.TotalAmount, orderInfo.TotalAmount, payConfig.WXAppId, payConfig.WXMCH_ID, payConfig.WXPartnerKey, out msg, out weixinRefundId, bllMall.WebsiteOwner)) { successCount++; orderInfo.Ex1 = weixinRefundId; orderInfo.Ex2 = msg; bllMall.Update(orderInfo); } else { if ((!string.IsNullOrEmpty(msg)) && (msg.Contains("请使用可用余额退款")))//尝试使用余额退款 { if (bllPay.WeixinRefundYuEr(orderInfo.OrderID, orderInfo.OrderID, orderInfo.TotalAmount, orderInfo.TotalAmount, payConfig.WXAppId, payConfig.WXMCH_ID, payConfig.WXPartnerKey, out msg, out weixinRefundId, bllMall.WebsiteOwner)) { successCount++; orderInfo.Ex1 = weixinRefundId; orderInfo.Ex2 = msg; bllMall.Update(orderInfo); } else { resp.errcode = 1; resp.errmsg = msg; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } } else { resp.errcode = 1; resp.errmsg = msg; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } } } #endregion #region 支付宝退款 else if (orderInfo.PaymentType == 1) { string batchNo = DateTime.Now.ToString("yyyyMMdd") + ((int)(bllMall.GetTimeStamp(DateTime.Now) / 1000)).ToString(); string notifyUrl = string.Format("http://{0}/Alipay/NotifyRefund.aspx", context.Request.Url.Host); string remark = string.Format("订单号{0}", orderInfo.OrderID); //支付宝支付的退款 bool isSuccess = bllPay.AlipayRefund(orderInfo.PayTranNo, batchNo, orderInfo.TotalAmount, notifyUrl, out msg, remark); if (!isSuccess) { resp.errcode = 1; resp.errmsg = msg; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } } #endregion else if (orderInfo.PaymentType == 3) { if (!bllPay.JDPayRefund(orderInfo.OrderID, orderInfo.OrderID, orderInfo.TotalAmount, "", "", out msg)) { resp.errcode = 1; resp.errmsg = msg; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } } } } return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); }
protected void Page_Load(object sender, EventArgs e) { model = bll.Get <ZentCloud.BLLJIMP.Model.PayConfig>(string.Format(" WebsiteOwner='{0}'", bll.WebsiteOwner)); }