430 lines
20 KiB
C#
430 lines
20 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Security.Cryptography;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using SuperMap.RealEstate.ServiceModel;
|
||
using SuperMap.RealEstate.ExchangeData.Business;
|
||
using SuperMap.RealEstate.HighWay.SellData.Business;
|
||
using Newtonsoft.Json.Linq;
|
||
using Newtonsoft.Json;
|
||
using HZQR.Common;
|
||
|
||
namespace ServerPartTransmission.Method
|
||
{
|
||
/// <summary>
|
||
/// 移动支付相关方法
|
||
/// </summary>
|
||
public class MobilePayHelper
|
||
{
|
||
#region 方法 -> 银行到账归口查询
|
||
/// <summary>
|
||
/// 银行到账归口查询
|
||
/// </summary>
|
||
/// <param name="_Transaction">事务管理器</param>
|
||
/// <param name="starTime">查询开始日期</param>
|
||
/// <param name="endTime">查询结束日期</param>
|
||
/// <param name="dtBusinessShopCode">门店商户编码集合</param>
|
||
/// <returns></returns>
|
||
public static List<Model.TradeStatisticsData> GetTradeStatistics(Transaction _Transaction,
|
||
string starTime, string endTime, DataTable dtBusinessShopCode)
|
||
{
|
||
List<Model.TradeStatisticsData> TradeStatisticsDataList = new List<Model.TradeStatisticsData>();
|
||
try
|
||
{
|
||
Model.StatisticsData statisticsResult = new Model.StatisticsData();
|
||
|
||
foreach (DataRow item in dtBusinessShopCode.Rows)
|
||
{
|
||
string sqlWhere = string.Empty;
|
||
string busi_id = item["BUSINESS_CODE"].ToString().Trim(); //商户编码
|
||
string key = item["BUSINESS_KEY"].ToString().Trim(); //商户秘钥
|
||
string appid = item["BUSINESS_APPID"].ToString().Trim(); //APPID(嗨客)
|
||
string operators = item["PAYMENT_CHANNEL"].ToString(); //支付通道
|
||
|
||
try
|
||
{
|
||
switch (operators)
|
||
{
|
||
case "1005"://客无忧
|
||
if (busi_id.Replace(",", ",").Contains(","))
|
||
{
|
||
foreach (string _s_busi_id in busi_id.Replace(",", ",").Split(','))
|
||
{
|
||
statisticsResult = GetKWYStatistics(starTime, endTime, _s_busi_id.Trim(), statisticsResult);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
statisticsResult = GetKWYStatistics(starTime, endTime, busi_id, statisticsResult);
|
||
}
|
||
break;
|
||
case "1007"://银联支付
|
||
statisticsResult = GetYLStatistics(statisticsResult, starTime, endTime, busi_id, key);
|
||
break;
|
||
case "1009":
|
||
statisticsResult = GetJHStatistics(_Transaction, statisticsResult, starTime,
|
||
endTime, item["SERVERPART_CODE"].ToString(), item["SERVERPARTSHOP_CODE"].ToString());
|
||
break;
|
||
case "1011":
|
||
statisticsResult = GetGHStatistics(_Transaction, statisticsResult, starTime,
|
||
endTime, item["SERVERPART_CODE"].ToString(), item["SERVERPARTSHOP_CODE"].ToString());
|
||
break;
|
||
case "1012"://嗨客移动支付
|
||
//初始化支付参数
|
||
Model.UphicooConfig _PayConfig = new Model.UphicooConfig(appid, key, busi_id);
|
||
statisticsResult = GetHKStatistics(busi_id, _PayConfig, statisticsResult, starTime, endTime);
|
||
break;
|
||
}
|
||
}
|
||
catch (Exception exception)
|
||
{
|
||
//记录日志
|
||
LogUtil.WriteLog(exception);
|
||
}
|
||
}
|
||
|
||
if (statisticsResult.list != null)
|
||
{
|
||
TradeStatisticsDataList = statisticsResult.list;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
//记录日志
|
||
LogUtil.WriteLog(ex);
|
||
}
|
||
|
||
return TradeStatisticsDataList;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 客无忧交易统计接口
|
||
/// <summary>
|
||
/// 客无忧交易统计接口
|
||
/// </summary>
|
||
/// <param name="starTime">查询开始日期</param>
|
||
/// <param name="endTime">查询结束日期</param>
|
||
/// <param name="busi_id">商户编码</param>
|
||
/// <param name="statisticsResult">交易结果数据集</param>
|
||
/// <returns></returns>
|
||
public static Model.StatisticsData GetKWYStatistics(string starTime, string endTime,
|
||
string busi_id, Model.StatisticsData statisticsResult)
|
||
{
|
||
string beginDate = Convert.ToDateTime(starTime).ToString("yyyy-MM-dd");
|
||
string endDate = Convert.ToDateTime(endTime).ToString("yyyy-MM-dd");
|
||
SortedDictionary<string, string> _SortedDictionary = new SortedDictionary<string, string>
|
||
{
|
||
{ "openid", "1z7n0lp0nsi8o0dd5o74lgrhs1575k" },//客无忧与平台对接的openid jajonaujrocjajheangyunhaohpeng
|
||
{ "bind_code",busi_id},//商户编号
|
||
{ "nonce_str", "0" },
|
||
{ "time_stamp", Convert.ToInt32((DateTime.Now -
|
||
new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds).ToString() },//时间戳
|
||
{ "date",beginDate+ "," +endDate}
|
||
};
|
||
string _SignstringTemp = "";
|
||
foreach (var keyValue in _SortedDictionary)
|
||
{
|
||
_SignstringTemp += (_SignstringTemp == "" ? "" : "&") + keyValue.Key + "=" + keyValue.Value;
|
||
}
|
||
string _Signstring = _SignstringTemp + "&sign=" + Common.MD5Util.GetMD5(
|
||
_SignstringTemp + "&key=w0j23q2m69po13syyd6pj6a11o64f2r13bj").ToUpper();
|
||
string requestUrl = Common.AppSettings.url_kwy;
|
||
string orderStatList = Common.HttpUtil.HttpUrlPost(_Signstring, requestUrl + "orderStatList");
|
||
Model.KwyStatResult kwyResult = JsonConvert.DeserializeObject<Model.KwyStatResult>(orderStatList);
|
||
if (kwyResult.result.return_code == "SUCCESS")
|
||
{
|
||
if (kwyResult.list != null)
|
||
{
|
||
kwyResult.list.ForEach(o =>
|
||
{
|
||
o.busi_id = busi_id;
|
||
o.account_amount = o.amount - o.fee;
|
||
});
|
||
//若原单据已退款,返回结果为退款,因此要去除掉交易退款的单据
|
||
for (int i = kwyResult.list.Count - 1; i >= 0; i--)
|
||
{
|
||
Model.TradeStatisticsData o = kwyResult.list[i];
|
||
if (o.amount <= 0)
|
||
{
|
||
kwyResult.list.Remove(o);
|
||
}
|
||
}
|
||
if (statisticsResult.list == null)
|
||
{
|
||
statisticsResult.list = kwyResult.list;
|
||
}
|
||
else
|
||
{
|
||
if (kwyResult.list != null)
|
||
{
|
||
statisticsResult.list = statisticsResult.list.Concat(kwyResult.list).ToList();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return statisticsResult;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 银联支付交易统计接口
|
||
/// <summary>
|
||
/// 银联支付交易统计接口
|
||
/// </summary>
|
||
/// <param name="starTime">查询开始日期</param>
|
||
/// <param name="endTime">查询结束日期</param>
|
||
/// <param name="busi_id">商户编码</param>
|
||
/// <param name="key">商户秘钥</param>
|
||
/// <param name="statisticsResult">交易结果数据集</param>
|
||
/// <returns></returns>
|
||
public static Model.StatisticsData GetYLStatistics(Model.StatisticsData statisticsResult,
|
||
string starTime, string endTime, string busi_id, string key)
|
||
{
|
||
string beginDate = Convert.ToDateTime(starTime).ToString("yyyyMMddHHmmss");
|
||
string endDate = Convert.ToDateTime(endTime).AddDays(1).ToString("yyyyMMddHHmmss");
|
||
SortedDictionary<string, string> _SortedDictionary = new SortedDictionary<string, string>
|
||
{
|
||
{ "busi_id", busi_id},
|
||
{ "beginDate", beginDate },
|
||
{ "endDate", endDate }
|
||
};
|
||
|
||
string stringSignTemp = string.Empty; //签名字符串
|
||
foreach (var item in _SortedDictionary)
|
||
{
|
||
stringSignTemp = stringSignTemp + (stringSignTemp == "" ? "" : "&") + item.Key + "=" + item.Value;
|
||
}
|
||
string _BaseUrl = Common.AppSettings.url_yl;//请求地址
|
||
|
||
string MD5String = Common.MD5Util.GetMD5(stringSignTemp + "&key=" + key).ToUpper();
|
||
string RequestUrl = _BaseUrl + "/queryStatisticsOrder";
|
||
// string format = "application/json;charset=UTF-8";
|
||
|
||
Model.StatisticsResult ylResult = new Model.StatisticsResult();
|
||
try
|
||
{
|
||
ylResult = JsonConvert.DeserializeObject<Model.StatisticsResult>(
|
||
Common.HttpUtil.HttpUrlPost(stringSignTemp + "&sign=" + MD5String, RequestUrl));//设置请求最大耗时15秒
|
||
}
|
||
catch { }
|
||
|
||
if (ylResult.result != null && ylResult.result.return_code == "SUCCESS")
|
||
{
|
||
if (ylResult.data != null)
|
||
{
|
||
//因接口按支付方式统计,这里调整为按天统计
|
||
ylResult.data = ylResult.data
|
||
.GroupBy(o => new
|
||
{
|
||
o.date
|
||
})
|
||
.Select(o => new Model.TradeStatisticsData
|
||
{
|
||
date = o.Key.date,
|
||
amount = o.Sum(x => x.amount / 100),
|
||
account_amount = o.Sum(x => x.amount / 100 - x.fee)
|
||
}).ToList();
|
||
if (statisticsResult.list == null)
|
||
{
|
||
statisticsResult.list = ylResult.data;
|
||
}
|
||
else
|
||
{
|
||
if (ylResult.data != null)
|
||
{
|
||
statisticsResult.list = statisticsResult.list.Concat(ylResult.data).ToList();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return statisticsResult;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 建行支付交易统计
|
||
/// <summary>
|
||
/// 建行支付交易统计
|
||
/// </summary>
|
||
/// <param name="_Transaction">事务管理器</param>
|
||
/// <param name="statisticsResult">交易结果数据集</param>
|
||
/// <param name="starTime">查询开始日期</param>
|
||
/// <param name="endTime">查询结束日期</param>
|
||
/// <param name="Serverpart_Code">服务区编码</param>
|
||
/// <param name="ShopCode">门店编码</param>
|
||
/// <returns></returns>
|
||
public static Model.StatisticsData GetJHStatistics(Transaction _Transaction, Model.StatisticsData statisticsResult,
|
||
string starTime, string endTime, string Serverpart_Code, string ShopCode)
|
||
{
|
||
DataTable _DataTable = new CCBCDAILYCOLLECT(_Transaction).ExecuteDataTable($@"
|
||
SELECT * FROM HIGHWAY_SELLDATA.T_CCBCDAILYCOLLECT
|
||
WHERE SERVERPARTCODE = '{Serverpart_Code}' AND SHOPCODE = '{ShopCode}' AND
|
||
STATISTICS_DATE BETWEEN TO_DATE('{starTime}','YYYY/MM/DD') AND TO_DATE('{endTime}','YYYY/MM/DD') + 1");
|
||
|
||
foreach (DataRow _DataRow in _DataTable.Rows)
|
||
{
|
||
Model.TradeStatisticsData tradeStatisticsDatas = new Model.TradeStatisticsData();
|
||
tradeStatisticsDatas.date = _DataRow["STATISTICS_DATE"].TryParseToDateTime().Value.ToString("yyyy-MM-dd");
|
||
tradeStatisticsDatas.amount = _DataRow["TRADEAMOUNT"].TryParseToDecimal();
|
||
tradeStatisticsDatas.fee = _DataRow["SERVICECHARGE"].TryParseToDecimal();
|
||
tradeStatisticsDatas.account_amount = _DataRow["SETTLEMENTAMOUNT"].TryParseToDecimal();
|
||
tradeStatisticsDatas.operators_name = "建行";
|
||
|
||
if (statisticsResult.list == null)
|
||
{
|
||
statisticsResult.list = new List<Model.TradeStatisticsData>() { tradeStatisticsDatas };
|
||
}
|
||
else
|
||
{
|
||
statisticsResult.list.Add(tradeStatisticsDatas);
|
||
}
|
||
}
|
||
|
||
return statisticsResult;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 工行支付交易统计
|
||
/// <summary>
|
||
/// 工行支付交易统计
|
||
/// </summary>
|
||
/// <param name="_Transaction">事务管理器</param>
|
||
/// <param name="statisticsResult">交易结果数据集</param>
|
||
/// <param name="starTime">查询开始日期</param>
|
||
/// <param name="endTime">查询结束日期</param>
|
||
/// <param name="Serverpart_Code">服务区编码</param>
|
||
/// <param name="ShopCode">门店编码</param>
|
||
/// <returns></returns>
|
||
public static Model.StatisticsData GetGHStatistics(Transaction _Transaction, Model.StatisticsData statisticsResult,
|
||
string starTime, string endTime, string Serverpart_Code, string ShopCode)
|
||
{
|
||
starTime = DateTime.Parse(starTime).ToString("yyyyMMdd");
|
||
endTime = DateTime.Parse(endTime).ToString("yyyyMMdd");
|
||
DataTable _DataTable = new CONFIGURATION(_Transaction).ExecuteDataTable($@"
|
||
SELECT * FROM HIGHWAY_SELLDATA.T_ICBCDAILYCOLLECT WHERE SERVERPARTCODE = '{Serverpart_Code}'
|
||
AND SHOPCODE = '{ShopCode}' AND STATISTICS_DATE BETWEEN {starTime} AND {endTime}");
|
||
|
||
foreach (DataRow _DataRow in _DataTable.Rows)
|
||
{
|
||
Model.TradeStatisticsData tradeStatisticsDatas = new Model.TradeStatisticsData();
|
||
tradeStatisticsDatas.date = _DataRow["STATISTICS_DATE"].ToString();
|
||
tradeStatisticsDatas.amount = _DataRow["TRADEAMOUNT"].TryParseToDecimal();
|
||
tradeStatisticsDatas.fee = _DataRow["SERVICECHARGE"].TryParseToDecimal();
|
||
tradeStatisticsDatas.account_amount = _DataRow["SETTLEMENTAMOUNT"].TryParseToDecimal();
|
||
tradeStatisticsDatas.operators_name = "工行";
|
||
|
||
if (statisticsResult.list == null)
|
||
{
|
||
statisticsResult.list = new List<Model.TradeStatisticsData>() { tradeStatisticsDatas };
|
||
}
|
||
else
|
||
{
|
||
statisticsResult.list.Add(tradeStatisticsDatas);
|
||
}
|
||
}
|
||
|
||
return statisticsResult;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 嗨客支付交易统计接口
|
||
/// <summary>
|
||
/// 嗨客支付交易统计接口
|
||
/// </summary>
|
||
/// <param name="busi_id">商户编码</param>
|
||
/// <param name="payConfig">嗨客参数配置对象</param>
|
||
/// <param name="statisticsResult">交易结果数据集</param>
|
||
/// <param name="starTime">查询开始日期</param>
|
||
/// <param name="endTime">查询结束日期</param>
|
||
/// <returns></returns>
|
||
public static Model.StatisticsData GetHKStatistics(string busi_id, Model.UphicooConfig payConfig,
|
||
Model.StatisticsData statisticsResult, string starTime, string endTime)
|
||
{
|
||
string beginDate = Convert.ToDateTime(starTime).ToString("yyyyMMddHHmmss");
|
||
string endDate = Convert.ToDateTime(endTime).AddDays(1).AddSeconds(-1).ToString("yyyyMMddHHmmss");
|
||
Dictionary<string, string> _paramDictionary = new Dictionary<string, string>
|
||
{
|
||
{ "appid",payConfig.PlatformAPPID},
|
||
{ "timestamp",CommonHelper.ConvertDataTimeLong(DateTime.Now).ToString()},
|
||
{ "merchant_num",busi_id},
|
||
{ "begin_date",beginDate },
|
||
{ "end_date",endDate },
|
||
{ "state","1" }
|
||
};
|
||
|
||
_paramDictionary.Add("sign", ApiParamSign(_paramDictionary, payConfig.PlatformKey));
|
||
|
||
string _BaseUrl = Common.AppSettings.url_hksta;//请求地址
|
||
string postResult = Common.HttpUtil.HttpUrlPost(JsonConvert.SerializeObject(_paramDictionary), _BaseUrl, "application/json");
|
||
JObject jobjectResult = JObject.Parse(postResult);
|
||
JObject jobjectChild = new JObject();
|
||
jobjectChild.Add("return_code", jobjectResult["code"]);
|
||
jobjectChild.Add("return_msg", jobjectResult["message"]);
|
||
jobjectResult.Add("result", jobjectChild);
|
||
jobjectResult["data"] = jobjectResult["data"]["list"];
|
||
|
||
Model.StatisticsResult hkResult = new Model.StatisticsResult();
|
||
|
||
try
|
||
{
|
||
hkResult = JsonConvert.DeserializeObject<Model.StatisticsResult>(JsonConvert.SerializeObject(jobjectResult));
|
||
}
|
||
catch (Exception) { }
|
||
|
||
if (hkResult.result != null && hkResult.result.return_code == "000000")
|
||
{
|
||
if (hkResult.data != null)
|
||
{
|
||
//因接口按支付方式统计,这里调整为按天统计
|
||
hkResult.data = hkResult.data
|
||
.GroupBy(o => new
|
||
{
|
||
o.date
|
||
})
|
||
.Select(o => new Model.TradeStatisticsData
|
||
{
|
||
date = o.Key.date,
|
||
amount = o.Sum(x => x.amount / 100),
|
||
account_amount = o.Sum(x => x.amount / 100 - x.fee)
|
||
}).ToList();
|
||
if (statisticsResult.list == null)
|
||
{
|
||
statisticsResult.list = hkResult.data;
|
||
}
|
||
else
|
||
{
|
||
if (hkResult.data != null)
|
||
{
|
||
statisticsResult.list = statisticsResult.list.Concat(hkResult.data).ToList();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return statisticsResult;
|
||
}
|
||
|
||
#region 方法 -> 嗨客支付平台参数签名
|
||
/// <summary>
|
||
/// 嗨客支付平台参数签名
|
||
/// </summary>
|
||
/// <param name="signParm">待签名参数集</param>
|
||
/// <param name="MD5Key">签名密钥</param>
|
||
/// <returns></returns>
|
||
public static string ApiParamSign(Dictionary<string, string> signParm, string MD5Key)
|
||
{
|
||
string _strSign = "";
|
||
foreach (var keyValuePair in signParm.OrderBy(p => p.Key))
|
||
{
|
||
_strSign += (string.IsNullOrWhiteSpace(_strSign) ? "" : "&") + keyValuePair.Key + "=" + keyValuePair.Value;
|
||
}
|
||
return BitConverter.ToString(MD5.Create().ComputeHash(
|
||
Encoding.UTF8.GetBytes(_strSign + "&key=" + MD5Key))).Replace("-", "").ToLower();
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
}
|
||
}
|