844 lines
41 KiB
C#
844 lines
41 KiB
C#
using Aop.Api.Util;
|
||
using CRM.Core.BLL;
|
||
using CRM.Core.BLL.Application.Pay;
|
||
using CRM.Core.BLL.Base;
|
||
using CRM.Core.BLL.EventBus.EventHandlers;
|
||
using CRM.Core.BLL.Isvr;
|
||
using CRM.Core.BLL.Util;
|
||
using CRM.Core.BLL.Wx;
|
||
using CRM.Core.Common.EventBus;
|
||
using CRM.Core.DTO.Ord;
|
||
using CRM.Core.Model.Entity;
|
||
using CRM.Core.Model.Enum;
|
||
using CRM.Core.Model.Map;
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.Specialized;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Linq.Expressions;
|
||
using System.ServiceModel;
|
||
using System.Web;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.Common.WxPay;
|
||
|
||
namespace ZXDService
|
||
{
|
||
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“OrderPayService”。
|
||
// 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 OrderPayService.svc 或 OrderPayService.svc.cs,然后开始调试。
|
||
public class OrderPayService : IOrderPayService
|
||
{
|
||
private readonly Bas_CompanyVirtual_BL _company = new Bas_CompanyVirtual_BL();
|
||
private string clientKey = WX.CRM.Common.Utility.GetSettingByKey("CRMClientKey");
|
||
ISVR_INTERFACECALLLOG_BL logHelper = new ISVR_INTERFACECALLLOG_BL();
|
||
SecurityHelper sHelper = new SecurityHelper();
|
||
WX_SZZYORDER_BL orderBL = new WX_SZZYORDER_BL();
|
||
WX_SzzyOrderPay_BL orderPayBL = new WX_SzzyOrderPay_BL();
|
||
WX_SzzyOrderDeposit_BL _deposit = new WX_SzzyOrderDeposit_BL();
|
||
CACHE_BL cache_BL = new CACHE_BL();
|
||
private PayServices _payService = new PayServices();
|
||
|
||
public OrderPayService()
|
||
{
|
||
EventBus.Instance.Subscribe(new PayInfoEventHandler());
|
||
EventBus.Instance.Subscribe(new SendPayMessageEventHandler());
|
||
EventBus.Instance.Subscribe(new PayOrderEventHandler());
|
||
EventBus.Instance.Subscribe(new DepositOrderEventHandler());
|
||
|
||
EventBus.Instance.Subscribe(new OpenOrderEventHandler());
|
||
EventBus.Instance.Subscribe(new SupplyOrderEventHandler());
|
||
EventBus.Instance.Subscribe(new RefundOrderEventHandler());
|
||
EventBus.Instance.Subscribe(new UpGradeOrderEventHandler());
|
||
EventBus.Instance.Subscribe(new DepositUseOrderEventHandler());
|
||
EventBus.Instance.Subscribe(new DepositRefundOrderEventHandler());
|
||
EventBus.Instance.Subscribe(new FinishRefundContractEventHandler());
|
||
EventBus.Instance.Subscribe(new DeleteRefundOrderEventHandler());
|
||
EventBus.Instance.Subscribe(new CloseFreeOrderEventHandler());
|
||
EventBus.Instance.Subscribe(new HandGiftEventHandler());
|
||
EventBus.Instance.Subscribe(new PayRejectEventHandler());
|
||
EventBus.Instance.Subscribe(new DepositRejectEventHandler());
|
||
EventBus.Instance.Subscribe(new DepositDeleteEventHandler());
|
||
EventBus.Instance.Subscribe(new OrderAndPayInfoEventHandler());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 在线下单情况,订单走补单接口,支付完成后走本接口
|
||
/// </summary>
|
||
/// <param name="content"></param>
|
||
/// <param name="clientid"></param>
|
||
/// <param name="sign"></param>
|
||
/// <returns></returns>
|
||
public Stream SyncPayInfo(string content, string clientid, string sign)
|
||
{
|
||
LogHelper.Info("cntent:" + content + ",clientid:" + clientid + ",sign:" + sign);
|
||
string retMsg = string.Empty;
|
||
//string url = Utility.GetClassAndMethodName(1);
|
||
//var content2 = content;
|
||
|
||
//logHelper.AddCallLog(content, clientid, sign, url);
|
||
|
||
//验证是否非法请求
|
||
if (!sHelper.CheckClientValid(clientid, content, sign))
|
||
{
|
||
|
||
retMsg = Utility.ObjectToJson(new { result = false, retcode = (int)EnumInterfaceErrcode.非法请求 });
|
||
//retMsg = sHelper.encyptData(clientid, retMsg);
|
||
LogHelper.Info("非法请求content:" + content + ",clientid=" + clientid + ",sign=" + sign);
|
||
return Utility.GetStream(sHelper.encyptData(clientKey, retMsg));
|
||
}
|
||
#region 参数解析阶段
|
||
|
||
LogHelper.Info("开始解密");//解密后的内容
|
||
|
||
SyncOrderPayInfoDto syncOrderPayInfo = null;
|
||
|
||
try
|
||
{
|
||
LogHelper.Info("xx:" + content);
|
||
content = sHelper.decyptData(clientid, content); //解密操作
|
||
LogHelper.Info("内容:" + content);//解密后的内容
|
||
|
||
syncOrderPayInfo = Utility.JSONToObject<SyncOrderPayInfoDto>(content);
|
||
|
||
|
||
if (string.IsNullOrEmpty(syncOrderPayInfo.ApplyOrderId))
|
||
{
|
||
retMsg = Utility.ObjectToJson(new { result = false, retcode = (int)EnumInterfaceErrcode.参数错误 });
|
||
//retMsg = sHelper.encyptData(clientid, retMsg);
|
||
return Utility.GetStream(sHelper.encyptData(clientid, retMsg));
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
retMsg = Utility.ObjectToJson(new { result = false, retcode = (int)EnumInterfaceErrcode.参数错误 });
|
||
LogHelper.Error(string.Concat("当前请求Url:", "|" + content + "|", ex.ToString()));
|
||
return Utility.GetStream(sHelper.encyptData(clientid, retMsg));
|
||
|
||
}
|
||
#endregion
|
||
|
||
|
||
try
|
||
{
|
||
decimal syncOrderId = Convert.ToDecimal(syncOrderPayInfo.ApplyOrderId);
|
||
var order = orderBL.Get(m => m.SZZYORDERID == syncOrderId);
|
||
if (order == null)
|
||
{
|
||
retMsg = Utility.ObjectToJson(new { result = false, retcode = (int)EnumInterfaceErrcode.找不到订单 });
|
||
LogHelper.Info(string.Format("线上订单:{0},本地不存在", syncOrderPayInfo.ApplyOrderId));
|
||
return Utility.GetStream(sHelper.encyptData(clientid, retMsg));
|
||
}
|
||
var orderId = Convert.ToInt32(order.ORDERID);
|
||
var payInfo = orderPayBL.Get(m => m.orderid == orderId && m.payno == syncOrderPayInfo.PayNo && m.paytype == syncOrderPayInfo.PayType);
|
||
if (payInfo != null)
|
||
{
|
||
retMsg = Utility.ObjectToJson(new { result = false, retcode = (int)EnumInterfaceErrcode.订单已开通 });
|
||
LogHelper.Info(string.Format("线上订单:{0},支付流水:{1},支付类型:{2}已经存在", syncOrderPayInfo.ApplyOrderId, syncOrderPayInfo.PayNo, syncOrderPayInfo.PayType.ToString()));
|
||
return Utility.GetStream(sHelper.encyptData(clientid, retMsg));
|
||
}
|
||
else
|
||
{
|
||
//payInfo = new WX_SzzyOrderPay();
|
||
//payInfo.orderid = orderId;
|
||
//payInfo.needpay = order.NEEDPAY.Value;
|
||
//payInfo.payprice = syncOrderPayInfo.PayPrice; //支付成功后,这里的金额单位是元
|
||
//payInfo.payno = syncOrderPayInfo.PayNo;
|
||
//payInfo.paytype = syncOrderPayInfo.PayType;
|
||
//var payTypeName = cache_BL.GetList_Parameter(ParameterGroup.OrderPayType).FirstOrDefault(p => p.PARAVALUE == syncOrderPayInfo.PayType.ToString()).PARANAME;
|
||
//payInfo.paytypename = payTypeName;
|
||
//payInfo.remark = syncOrderPayInfo.PayMark;
|
||
//payInfo.ctime = DateTime.Now;
|
||
//payInfo.paydate = DateTime.Now.Date;
|
||
//payInfo.payname = "在线支付";
|
||
//payInfo.companycode = order.companycode;
|
||
//payInfo.auditstatus = 1; //表示已经确认
|
||
//payInfo.audittime = payInfo.ctime;
|
||
//payInfo.channel = order.CHANNEL;
|
||
//payInfo.checkpaytime = DateTime.Now;
|
||
|
||
////写入支付记录表
|
||
//int result = orderPayBL.Add(payInfo);
|
||
//if (result == 1)
|
||
//{
|
||
// //更新订单支付信息
|
||
// order.ARRIVALPAY = syncOrderPayInfo.PayPrice;
|
||
// order.FINALPAY = syncOrderPayInfo.PayPrice;
|
||
// order.ARRIVALTIME = payInfo.paydate;
|
||
// order.ORDERSTATUS = "200";
|
||
// order.ORDERSTATUSNAME = "已支付";
|
||
// orderBL.Update(order);
|
||
|
||
// //推送支付事件
|
||
// EventBus.Instance.Publish(new PayInfoEvent(Convert.ToInt32(order.ORDERID), "200", "已支付", order.NEEDPAY.Value, payInfo.paydate.Value, order.companycode, syncOrderPayInfo.PayNo, syncOrderPayInfo.PayType, payTypeName, syncOrderPayInfo.PayMark, payInfo.payprice, payInfo.ctime, payInfo.payname));
|
||
|
||
// ////推送收款短信给订单审核人
|
||
// //var onlinePayReceiveMobile = ConfigurationManager.AppSettings["OnlinePayReceiveMobile"];
|
||
// //var resList = new List<string>();
|
||
// //if (!string.IsNullOrWhiteSpace(onlinePayReceiveMobile))
|
||
// //{
|
||
// // resList = onlinePayReceiveMobile.Split(',').ToList();
|
||
// //}
|
||
// //foreach (var resId in resList)
|
||
// //{
|
||
// // EventBus.Instance.Publish(new SendPayMessageEvent(payInfo.payprice, resId, payTypeName, 10000));
|
||
// //}
|
||
// ////推送短信结束
|
||
|
||
// LogHelper.Info(string.Format("处理成功!订单:{0},本地订单号:{1}", syncOrderPayInfo.ApplyOrderId, order.ORDERID.ToString()));
|
||
// return Utility.GetStream(sHelper.encyptData(clientid, Utility.ObjectToJson(new { result = true, retcode = 10000 })));
|
||
//}
|
||
//else
|
||
//{
|
||
// return Utility.GetStream(sHelper.encyptData(clientid, Utility.ObjectToJson(new { result = false, retcode = (int)EnumInterfaceErrcode.系统错误 })));
|
||
//}
|
||
|
||
var paylist = new List<PayInfoDto>() {
|
||
new PayInfoDto(){
|
||
resid = order.RESID,
|
||
paytype = syncOrderPayInfo.PayType,
|
||
paytypename =cache_BL.GetList_Parameter(ParameterGroup.OrderPayType).FirstOrDefault(p => p.PARAVALUE == syncOrderPayInfo.PayType.ToString()).PARANAME,
|
||
paydate =DateTime.Now.Date,
|
||
payname = "在线支付",
|
||
remark = syncOrderPayInfo.PayMark,
|
||
payno = syncOrderPayInfo.PayNo,
|
||
isuse = 0,
|
||
companycode = order.companycode,
|
||
tradeno = null,
|
||
creator = null,
|
||
creatorname = null,
|
||
checkpaytime=DateTime.Now,
|
||
payprice=syncOrderPayInfo.PayPrice
|
||
}
|
||
};
|
||
var orderuselist = new List<OrderuseDto>() {
|
||
new OrderuseDto() { orderid = Convert.ToInt32(order.ORDERID), needpay = order.NEEDPAY.Value, arrivalpay = 0 }
|
||
};
|
||
var dto2 = new CRM.Core.DTO.Ord.PayDto2
|
||
{
|
||
orderuselist = orderuselist,
|
||
resid = order.RESID,
|
||
//depprice = depprice,
|
||
paylist = paylist
|
||
};
|
||
LogHelper.Info("dto2:" + dto2.ToJson());
|
||
var ret2 = _payService.Add(dto2, 2);
|
||
if (ret2.result)
|
||
{
|
||
LogHelper.Info("写入支付记录和更新订单状态执行数据库操作成功!");
|
||
|
||
//支付信息写入成功之后自动调用审核
|
||
var depositInfoList = ret2.retmsg;
|
||
foreach (var deposit in depositInfoList)
|
||
{
|
||
try
|
||
{
|
||
var depositModel = _deposit.Get(p => p.id == deposit.id);
|
||
if (depositModel != null)
|
||
{
|
||
_deposit.Audit(depositModel, 0, string.Empty);
|
||
}
|
||
}
|
||
catch (Exception exx)
|
||
{
|
||
LogHelper.Error(exx);
|
||
}
|
||
|
||
}
|
||
}
|
||
return Utility.GetStream(Utility.ObjectToJson(new { state = 0, message = "同步成功" }));
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
retMsg = Utility.ObjectToJson(new { result = false, retcode = (int)EnumInterfaceErrcode.系统错误 });
|
||
LogHelper.Error(string.Concat("执行支付信息入库错误:", ex.ToString()));
|
||
return Utility.GetStream(sHelper.encyptData(clientid, retMsg));
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 支付宝回调
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
public Stream AliPayNotify(Stream input)
|
||
{
|
||
LogHelper.Info("===========entry===========");
|
||
Dictionary<string, string> sArray = GetRequestPost(input);
|
||
if (sArray.Count != 0)
|
||
{
|
||
//LogHelper.Info("sArray:" + sArray.ToJson());
|
||
|
||
var tradeNo = sArray["out_trade_no"];
|
||
LogHelper.Info("traodeNo:" + tradeNo);
|
||
var aliPayId = tradeNo.Substring(1, 16);
|
||
LogHelper.Info("aliPayId:" + aliPayId);
|
||
var trade_status = sArray["trade_status"];
|
||
var payNo = sArray["trade_no"];
|
||
var payDate = sArray["gmt_payment"];
|
||
var appId = sArray["app_id"];
|
||
var payPrice = sArray["total_amount"];
|
||
var aliPayPublicKey = AliPayConfig.alipay_public_key(aliPayId);
|
||
//LogHelper.Info("PublicKey:" + aliPayPublicKey);
|
||
bool flag = AlipaySignature.RSACheckV1(sArray, aliPayPublicKey, AliPayConfig.charset, "RSA2", false);
|
||
if (flag)
|
||
{
|
||
//交易状态
|
||
//判断该笔订单是否在商户网站中已经做过处理
|
||
//如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
|
||
//请务必判断请求时的total_amount与通知时获取的total_fee为一致的
|
||
//如果有做过处理,不执行商户的业务程序
|
||
|
||
//注意:
|
||
//退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
|
||
|
||
//1、商户需要验证该通知数据中的 out_trade_no 是否为商户系统中创建的订单号;
|
||
|
||
//2、判断 total_amount 是否确实为该订单的实际金额(即商户订单创建时的金额);
|
||
|
||
//3、校验通知中的 seller_id(或者 seller_email ) 是否为 out_trade_no 这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id / seller_email);
|
||
|
||
//4、验证 app_id 是否为该商户本身。上述 1、2、3、4有任何一个验证不通过,则表明本次通知是异常通知,务必忽略。在上述验证通过后商户必须根据支付宝不同类型的业务通知,正确的进行不同的业务处理,并且过滤重复的通知结果数据。在支付宝的业务通知中,只有交易通知状态为 TRADE_SUCCESS 或 TRADE_FINISHED 时,支付宝才会认定为买家付款成功。
|
||
|
||
if (trade_status == "TRADE_SUCCESS" || trade_status == "TRADE_FINISHED")
|
||
{
|
||
if (tradeNo.StartsWith("D"))
|
||
{
|
||
//订金以D开头
|
||
var deposit = _deposit.Get(p => p.tradeno == tradeNo && p.auditstatus == 0);
|
||
if (deposit != null)
|
||
{
|
||
if (deposit.payprice == decimal.Parse(payPrice))
|
||
{
|
||
if (aliPayId == appId)
|
||
{
|
||
deposit.payno = payNo;
|
||
deposit.paydate = DateTime.Parse(DateTime.Parse(payDate).ToString("yyyy-MM-dd"));
|
||
deposit.audittime = DateTime.Parse(payDate);
|
||
deposit.checkpaytime = DateTime.Parse(payDate);
|
||
|
||
LogHelper.Info("depositInfo:" + deposit.ToJson());
|
||
|
||
//_deposit.Audit(deposit, 0, string.Empty);
|
||
_deposit.Audit(deposit, 0, string.Empty, 2);//走自动审核流程
|
||
return Utility.GetStream("success");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//正常订单以P开头(弃用)
|
||
//var orderPay = orderPayBL.Get(p => p.tradeno == tradeNo && p.auditstatus == 0);
|
||
//if (orderPay != null)
|
||
//{
|
||
// if (orderPay.payprice == decimal.Parse(payPrice))
|
||
// {
|
||
// if (aliPayId == appId)
|
||
// {
|
||
// orderPay.payno = payNo;
|
||
// orderPay.paydate = DateTime.Parse(DateTime.Parse(payDate).ToString("yyyy-MM-dd"));
|
||
// orderPay.audittime = DateTime.Parse(payDate);
|
||
// LogHelper.Info("orderPayInfo:" + orderPay.ToJson());
|
||
|
||
// var order = orderBL.Get(p => p.ORDERID == orderPay.orderid);
|
||
|
||
// //orderPayBL.Audit(orderPay, order, 0, string.Empty);
|
||
// _deposit.Audit(deposit, 0, string.Empty, 2);//走自动审核流程
|
||
// return Utility.GetStream("success");
|
||
// }
|
||
// }
|
||
//}
|
||
//正常订单以P开头(但是目前都走订金方式)
|
||
var deposit = _deposit.Get(p => p.tradeno == tradeNo && p.auditstatus == 0);
|
||
if (deposit != null)
|
||
{
|
||
if (deposit.payprice == decimal.Parse(payPrice))
|
||
{
|
||
if (aliPayId == appId)
|
||
{
|
||
deposit.payno = payNo;
|
||
deposit.paydate = DateTime.Parse(DateTime.Parse(payDate).ToString("yyyy-MM-dd"));
|
||
deposit.audittime = DateTime.Parse(payDate);
|
||
deposit.checkpaytime = DateTime.Parse(payDate);
|
||
LogHelper.Info("depositInfo:" + deposit.ToJson());
|
||
|
||
//_deposit.Audit(deposit, 0, string.Empty);
|
||
_deposit.Audit(deposit, 0, string.Empty, 2);//走自动审核流程
|
||
return Utility.GetStream("success");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//交易状态没成功
|
||
return Utility.GetStream("failure");
|
||
}
|
||
|
||
LogHelper.Info("true");
|
||
}
|
||
else
|
||
{
|
||
LogHelper.Info("false");
|
||
}
|
||
}
|
||
return Utility.GetStream("failure");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 微信回调
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public Stream WxPayNotify()
|
||
{
|
||
string msg = OperationContext.Current.RequestContext.RequestMessage.ToString();
|
||
LogHelper.Info("Receive data from WeChat : " + msg);
|
||
WxPayData notifyData = GetWxNotifyData(msg);
|
||
//检查支付结果中transaction_id是否存在
|
||
if (!notifyData.IsSet("transaction_id"))
|
||
{
|
||
//若transaction_id不存在,则立即返回结果给微信支付后台
|
||
WxPayData res = new WxPayData();
|
||
res.SetValue("return_code", "FAIL");
|
||
res.SetValue("return_msg", "支付结果中微信订单号不存在");
|
||
LogHelper.Error("The Pay result is error : " + res.ToXml());
|
||
return Utility.GetStream(res.ToXml());
|
||
//return res.ToXml();
|
||
}
|
||
|
||
string transaction_id = notifyData.GetValue("transaction_id").ToString();
|
||
|
||
//查询订单,判断订单真实性
|
||
if (!QueryOrder(transaction_id, notifyData.GetValue("mch_id").ToString()))
|
||
{
|
||
//若订单查询失败,则立即返回结果给微信支付后台
|
||
WxPayData res = new WxPayData();
|
||
res.SetValue("return_code", "FAIL");
|
||
res.SetValue("return_msg", "订单查询失败");
|
||
LogHelper.Error("Order query failure : " + res.ToXml());
|
||
return Utility.GetStream(res.ToXml());
|
||
//return res.ToXml();
|
||
}
|
||
//查询订单成功
|
||
else
|
||
{
|
||
var tradeNo = notifyData.GetValue("out_trade_no").ToString();
|
||
var endTime = notifyData.GetValue("time_end").ToString();
|
||
var paydate = DateTime.ParseExact(endTime, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
|
||
|
||
if (tradeNo.StartsWith("D"))
|
||
{
|
||
//订金以D开头
|
||
var deposit = _deposit.Get(p => p.tradeno == tradeNo && p.auditstatus == 0);
|
||
if (deposit != null)
|
||
{
|
||
deposit.payno = transaction_id;
|
||
deposit.paydate = DateTime.Parse(paydate.ToString("yyyy-MM-dd"));
|
||
deposit.checkpaytime = paydate;
|
||
LogHelper.Info("depositInfo:" + deposit.ToJson());
|
||
|
||
_deposit.Audit(deposit, 0, string.Empty, 2);//走自动审核流程
|
||
}
|
||
}
|
||
else
|
||
{
|
||
////正常订单以P开头
|
||
//var orderPay = orderPayBL.Get(p => p.tradeno == tradeNo && p.auditstatus == 0);
|
||
//if (orderPay != null)
|
||
//{
|
||
// //orderPay.payno = transaction_id;
|
||
// //orderPay.paydate = DateTime.Parse(paydate.ToString("yyyy-MM-dd"));
|
||
// LogHelper.Info("orderPayInfo:" + orderPay.ToJson());
|
||
// //var order = orderBL.Get(p => p.ORDERID == orderPay.orderid);
|
||
// //orderPayBL.Audit(orderPay, order, 0, string.Empty);//废弃
|
||
// var deposit = _deposit.Get(p => p.tradeno == tradeNo && p.auditstatus == 0);//也是走自动审核
|
||
// deposit.paydate = DateTime.Parse(paydate.ToString("yyyy-MM-dd"));
|
||
// deposit.payno = transaction_id;
|
||
// retMsg ret = _deposit.Audit(deposit, 0, string.Empty, 2);
|
||
//}
|
||
//else
|
||
//{
|
||
// LogHelper.Info("未查找到数据:" + tradeNo);
|
||
//}
|
||
var deposit = _deposit.Get(p => p.tradeno == tradeNo && p.auditstatus == 0);
|
||
if (deposit != null)
|
||
{
|
||
deposit.payno = transaction_id;
|
||
deposit.paydate = DateTime.Parse(paydate.ToString("yyyy-MM-dd"));
|
||
deposit.checkpaytime = paydate;
|
||
LogHelper.Info("depositInfo:" + deposit.ToJson());
|
||
|
||
_deposit.Audit(deposit, 0, string.Empty, 2);//走自动审核流程
|
||
}
|
||
}
|
||
|
||
WxPayData res = new WxPayData();
|
||
res.SetValue("return_code", "SUCCESS");
|
||
res.SetValue("return_msg", "OK");
|
||
LogHelper.Info("order query success : " + res.ToXml());
|
||
return Utility.GetStream(res.ToXml());
|
||
//return res.ToXml();
|
||
}
|
||
|
||
}
|
||
|
||
public Dictionary<string, string> GetRequestPost(Stream input)
|
||
{
|
||
int i = 0;
|
||
Dictionary<string, string> sArray = new Dictionary<string, string>();
|
||
|
||
StreamReader sr = new StreamReader(input);
|
||
string s = sr.ReadToEnd();
|
||
sr.Dispose();
|
||
LogHelper.Info(string.Format("流输入值:{0}", s));
|
||
NameValueCollection coll = HttpUtility.ParseQueryString(HttpUtility.UrlDecode(s));
|
||
//NameValueCollection coll;
|
||
//coll = System.Web.HttpContext.Current.Request.Form;
|
||
String[] requestItem = coll.AllKeys;
|
||
for (i = 0; i < requestItem.Length; i++)
|
||
{
|
||
var key = requestItem[i];
|
||
//RSA加密算法,urldecode后会把'+'变成空格
|
||
if (key == "sign")
|
||
{
|
||
sArray.Add(key, coll.Get(key).Replace(' ', '+'));
|
||
}
|
||
else
|
||
{
|
||
sArray.Add(key, coll.Get(key));
|
||
}
|
||
LogHelper.Info(string.Format("{0}|||{1}", key, sArray[key]));
|
||
}
|
||
return sArray;
|
||
}
|
||
|
||
public WxPayData GetWxNotifyData(string msg)
|
||
{
|
||
//接收从微信后台POST过来的数据
|
||
/*Stream s = input;
|
||
int count = 0;
|
||
byte[] buffer = new byte[1024];
|
||
StringBuilder builder = new StringBuilder();
|
||
while ((count = s.Read(buffer, 0, 1024)) > 0)
|
||
{
|
||
builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
|
||
}
|
||
s.Flush();
|
||
s.Close();
|
||
s.Dispose();*/
|
||
|
||
//StreamReader sr = new StreamReader(input);
|
||
//string builder = sr.ReadToEnd();
|
||
//sr.Close();
|
||
//sr.Dispose();
|
||
|
||
|
||
|
||
//转换数据格式并验证签名
|
||
WxPayData data = new WxPayData();
|
||
try
|
||
{
|
||
data.FromXml(msg, "");
|
||
}
|
||
catch (WxPayException ex)
|
||
{
|
||
//若签名错误,则立即返回结果给微信支付后台
|
||
WxPayData res = new WxPayData();
|
||
res.SetValue("return_code", "FAIL");
|
||
res.SetValue("return_msg", ex.Message);
|
||
LogHelper.Error("Sign check error : " + res.ToXml());
|
||
HttpContext.Current.Response.Write(res.ToXml());
|
||
HttpContext.Current.Response.End();
|
||
//return Utility.GetStream(res.ToXml());
|
||
}
|
||
|
||
LogHelper.Info("Check sign success");
|
||
return data;
|
||
}
|
||
|
||
//查询订单
|
||
private bool QueryOrder(string transaction_id, string mch_id)
|
||
{
|
||
WxPayData req = new WxPayData();
|
||
req.SetValue("transaction_id", transaction_id);
|
||
WxPayData res = WxPayApi.OrderQuery(req, mch_id);
|
||
if (res.GetValue("return_code").ToString() == "SUCCESS" &&
|
||
res.GetValue("result_code").ToString() == "SUCCESS")
|
||
{
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public JsonResult<List<DepositInfoDto>> Add(string content, string clientid, string sign)
|
||
{
|
||
try
|
||
{
|
||
if (!sHelper.CheckClientValid(clientid, content, sign))//签名认证
|
||
{
|
||
return new JsonResult<List<DepositInfoDto>>() { result = false, retcode = (int)EnumInterfaceErrcode.非法请求, retmsg = null };
|
||
}
|
||
content = sHelper.decyptData(clientid, content); //解密操作
|
||
//LogHelper.Info("content:" + content);
|
||
//var dto = Utility.JSONToObject<CRM.Core.DTO.Ord.PayDto>(content);
|
||
var dto = JsonConvert.DeserializeObject<CRM.Core.DTO.Ord.PayDto2>(content);
|
||
|
||
LogHelper.Info("payadd:" + dto.ToJson());
|
||
|
||
var res = _payService.Add(dto);
|
||
|
||
return new JsonResult<List<DepositInfoDto>>() { result = res.result, retcode = (int)EnumInterfaceErrcode.调用成功, retmsg = res.retmsg };
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex.ToString());
|
||
return new JsonResult<List<DepositInfoDto>>() { result = false, retcode = (int)EnumInterfaceErrcode.系统错误, retmsg = null };
|
||
}
|
||
|
||
}
|
||
|
||
public JsonResult<List<DepositInfoDto>> Use(string content, string clientid, string sign)
|
||
{
|
||
try
|
||
{
|
||
|
||
if (!sHelper.CheckClientValid(clientid, content, sign))//签名认证
|
||
{
|
||
return new JsonResult<List<DepositInfoDto>>() { result = false, retcode = (int)EnumInterfaceErrcode.非法请求, retmsg = null };
|
||
}
|
||
content = sHelper.decyptData(clientid, content); //解密操作
|
||
|
||
var dto = Utility.JSONToObject<CRM.Core.DTO.Ord.PayUseDto>(content);
|
||
LogHelper.Info("payuse:" + dto.ToJson());
|
||
|
||
var res = _payService.Use(dto);
|
||
|
||
return new JsonResult<List<DepositInfoDto>>() { result = res.result, retcode = (int)EnumInterfaceErrcode.调用成功, retmsg = res.retmsg };
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex.ToString());
|
||
return new JsonResult<List<DepositInfoDto>>() { result = false, retcode = (int)EnumInterfaceErrcode.系统错误, retmsg = null };
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 查找客户可用金额
|
||
/// </summary>
|
||
/// <param name="content"></param>
|
||
/// <param name="clientid"></param>
|
||
/// <param name="sign"></param>
|
||
/// <returns></returns>
|
||
public JsonResult<LastPriceRspDto> LastpriceGet(string content, string clientid, string sign)
|
||
{
|
||
try
|
||
{
|
||
if (!sHelper.CheckClientValid(clientid, content, sign))//签名认证
|
||
{
|
||
return new JsonResult<LastPriceRspDto>() { result = false, retcode = (int)EnumInterfaceErrcode.非法请求, retmsg = null };
|
||
}
|
||
content = sHelper.decyptData(clientid, content); //解密操作
|
||
var dto = Utility.JSONToObject<CRM.Core.DTO.Ord.LastPriceReqDto>(content);
|
||
if (dto.channel == 0 || string.IsNullOrEmpty(dto.resid))
|
||
{
|
||
return new JsonResult<LastPriceRspDto>() { result = false, retcode = (int)EnumInterfaceErrcode.参数错误, retmsg = null };
|
||
}
|
||
|
||
LastPriceRspDto responseModel = new LastPriceRspDto()
|
||
{
|
||
resid = dto.resid,
|
||
lastprice = 0,
|
||
useprice = 0
|
||
};
|
||
//CompanyVirlual channelInfo = _company.GetChannel(dto.channel);
|
||
List<CompanyVirlual> channelInfoList = _company.GetChannelList(dto.channel);
|
||
if (channelInfoList == null || channelInfoList.Count() == 0)
|
||
{
|
||
return new JsonResult<LastPriceRspDto>() { result = false, retcode = (int)EnumInterfaceErrcode.参数错误, retmsg = null };
|
||
}
|
||
WX_SzzyOrderDeposit_BL _orderDeposit = new WX_SzzyOrderDeposit_BL();
|
||
var where = PredicateExtensionses.True<WX_SzzyOrderDeposit>();
|
||
where = where.And(m => m.resid == dto.resid && (m.isdelete == 0 || m.isdelete == null) && m.auditstatus == 1);
|
||
|
||
var predicates = new List<Expression<Func<WX_SzzyOrderDeposit, bool>>>();
|
||
foreach (var channelInfo in channelInfoList)
|
||
{
|
||
foreach (var item in channelInfo.channels)
|
||
{
|
||
predicates.Add(m => m.channel >= item.minChannel && m.channel <= item.maxChannel);
|
||
}
|
||
}
|
||
where = where.AndListOr(predicates.ToArray());
|
||
var orderDepList = _orderDeposit.GetList(where).ToList();
|
||
if (orderDepList != null && orderDepList.Count() > 0)
|
||
{
|
||
responseModel.lastprice = orderDepList.Sum(m => m.lastprice) ?? 0;
|
||
responseModel.useprice = orderDepList.Sum(m => m.useprice) ?? 0;
|
||
}
|
||
if (responseModel.lastprice < 0)
|
||
{
|
||
responseModel.lastprice = 0;
|
||
}
|
||
if (responseModel.useprice < 0)
|
||
{
|
||
responseModel.useprice = 0;
|
||
}
|
||
return new JsonResult<LastPriceRspDto>() { result = true, retcode = (int)EnumInterfaceErrcode.调用成功, retmsg = responseModel };
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex.ToString());
|
||
return new JsonResult<LastPriceRspDto>() { result = false, retcode = (int)EnumInterfaceErrcode.系统错误, retmsg = null };
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 订金列表
|
||
/// </summary>
|
||
/// <param name="content"></param>
|
||
/// <param name="clientid"></param>
|
||
/// <param name="sign"></param>
|
||
/// <returns></returns>
|
||
public ListResult<OrderPayListRspDto, OrderPayListSumRspInfo> OrderPayListGet(string content, string clientid, string sign)
|
||
{
|
||
try
|
||
{
|
||
if (!sHelper.CheckClientValid(clientid, content, sign))//签名认证
|
||
{
|
||
return new ListResult<OrderPayListRspDto, OrderPayListSumRspInfo> { result = false, retcode = (int)EnumInterfaceErrcode.非法请求, retmsg = "非法请求" };
|
||
}
|
||
content = sHelper.decyptData(clientid, content); //解密操作
|
||
var dto = Utility.JSONToObject<CRM.Core.DTO.Ord.OrderPayListReqDto>(content);
|
||
if (dto.channel == 0)
|
||
{
|
||
return new ListResult<OrderPayListRspDto, OrderPayListSumRspInfo> { result = false, retcode = (int)EnumInterfaceErrcode.参数错误, retmsg = "参数错误" };
|
||
}
|
||
//CompanyVirlual channelInfo = _company.GetChannel(dto.channel);
|
||
List<CompanyVirlual> channelInfoList = _company.GetChannelList(dto.channel);
|
||
if (channelInfoList == null || channelInfoList.Count() == 0)
|
||
{
|
||
return new ListResult<OrderPayListRspDto, OrderPayListSumRspInfo> { result = false, retcode = (int)EnumInterfaceErrcode.参数错误, retmsg = "参数错误" };
|
||
}
|
||
WX_SzzyOrderDeposit_BL _orderDeposit = new WX_SzzyOrderDeposit_BL();
|
||
var where = PredicateExtensionses.True<WX_SzzyOrderDeposit>();
|
||
where = where.And(m => (m.isdelete == 0 || m.isdelete == null));// 查询需要查出除了删除的所有状态数据
|
||
if (dto.id.HasValue)
|
||
{
|
||
where = where.And(m => m.id == dto.id.Value);
|
||
}
|
||
if (dto.auditstatus.HasValue)
|
||
{
|
||
where = where.And(m => m.auditstatus == dto.auditstatus.Value);
|
||
}
|
||
if (dto.audittimeStime.HasValue)
|
||
{
|
||
where = where.And(m => m.audittime >= dto.audittimeStime.Value);
|
||
}
|
||
if (dto.audittimeEtime.HasValue)
|
||
{
|
||
dto.audittimeEtime = dto.audittimeEtime.Value.AddDays(1);
|
||
where = where.And(m => m.audittime <= dto.audittimeEtime.Value);
|
||
}
|
||
|
||
if (dto.paydateStime.HasValue)
|
||
{
|
||
where = where.And(m => m.paydate >= dto.paydateStime.Value);
|
||
}
|
||
if (dto.paydateEtime.HasValue)
|
||
{
|
||
dto.paydateEtime = dto.paydateEtime.Value.AddDays(1);
|
||
where = where.And(m => m.paydate <= dto.paydateEtime.Value);
|
||
}
|
||
if (!string.IsNullOrEmpty(dto.payno))
|
||
{
|
||
dto.payno = dto.payno.Trim();
|
||
where = where.And(m => m.payno == dto.payno);
|
||
}
|
||
|
||
if (dto.paytype.HasValue)
|
||
{
|
||
where = where.And(m => m.paytype == dto.paytype.Value);
|
||
}
|
||
if (!string.IsNullOrEmpty(dto.resid))
|
||
{
|
||
dto.resid = dto.resid.Trim();
|
||
where = where.And(m => m.resid == dto.resid);
|
||
}
|
||
|
||
var predicates = new List<Expression<Func<WX_SzzyOrderDeposit, bool>>>();
|
||
foreach (var channelInfo in channelInfoList)
|
||
{
|
||
foreach (var item in channelInfo.channels)
|
||
{
|
||
predicates.Add(m => m.channel >= item.minChannel && m.channel <= item.maxChannel);
|
||
}
|
||
}
|
||
where = where.AndListOr(predicates.ToArray());
|
||
|
||
//Laypage laypage = new Laypage()
|
||
//{
|
||
// count = dto.laypage.count,
|
||
// limit = dto.laypage.limit,
|
||
// order = dto.laypage.order,
|
||
// page = dto.laypage.page,
|
||
// sort = dto.laypage.sort
|
||
//};
|
||
OrderPayListSumRspInfo info = new OrderPayListSumRspInfo() { lastpriceSum = _orderDeposit.Sum(where, m => m.lastprice), paypriceSum = _orderDeposit.Sum(where, m => m.payprice) };
|
||
|
||
var quer = _orderDeposit.GetList(where, m => m.ctime, dto.laypage);
|
||
var nlist = quer.ToList();
|
||
var newObjects = nlist.Select(m => Mapper.T1MapToT2<WX_SzzyOrderDeposit, OrderPayListRspDto>(m)).ToList();
|
||
return new ListResult<OrderPayListRspDto, OrderPayListSumRspInfo>() { result = true, retcode = (int)EnumInterfaceErrcode.调用成功, retmsg = "succss", infolist = newObjects, pageinfo = dto.laypage, sumInfo = info };
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex.ToString());
|
||
return new ListResult<OrderPayListRspDto, OrderPayListSumRspInfo>() { result = false, retcode = (int)EnumInterfaceErrcode.系统错误, retmsg = "succss" };
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// pay列表获取
|
||
/// </summary>
|
||
/// <param name="content"></param>
|
||
/// <param name="clientid"></param>
|
||
/// <param name="sign"></param>
|
||
/// <returns></returns>
|
||
public ListResult<OrderPayUseListRspDto, OrderPayUseListSumRspInfo> OrderPayUseListGet(string content, string clientid, string sign)
|
||
{
|
||
try
|
||
{
|
||
if (!sHelper.CheckClientValid(clientid, content, sign))//签名认证
|
||
{
|
||
return new ListResult<OrderPayUseListRspDto, OrderPayUseListSumRspInfo> { result = false, retcode = (int)EnumInterfaceErrcode.非法请求, retmsg = "非法请求" };
|
||
}
|
||
content = sHelper.decyptData(clientid, content); //解密操作
|
||
var dto = Utility.JSONToObject<CRM.Core.DTO.Ord.OrderPayUseListReqDto>(content);
|
||
if (dto.channel == 0)
|
||
{
|
||
return new ListResult<OrderPayUseListRspDto, OrderPayUseListSumRspInfo> { result = false, retcode = (int)EnumInterfaceErrcode.参数错误, retmsg = "参数错误" };
|
||
}
|
||
WX_SzzyOrderPay_BL _orderpay = new WX_SzzyOrderPay_BL();
|
||
OrderPayUseListSumRspInfo info = new OrderPayUseListSumRspInfo() { usePriceSum = 0 };
|
||
List<OrderPayUseListRspDto> nlist = _orderpay.OrderPayUseListGet(dto, ref info);
|
||
return new ListResult<OrderPayUseListRspDto, OrderPayUseListSumRspInfo>() { result = true, retcode = (int)EnumInterfaceErrcode.调用成功, retmsg = "succss", infolist = nlist, pageinfo = dto.laypage, sumInfo = info };
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex.ToString());
|
||
return new ListResult<OrderPayUseListRspDto, OrderPayUseListSumRspInfo>() { result = false, retcode = (int)EnumInterfaceErrcode.系统错误, retmsg = "succss" };
|
||
}
|
||
}
|
||
}
|
||
}
|