200 lines
10 KiB
C#
200 lines
10 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Web;
|
|
using WebService.SDK.PayCommon;
|
|
|
|
namespace WebService.SDK.IRichPay
|
|
{
|
|
public class IRichPayAPI
|
|
{
|
|
/// <summary>
|
|
/// 联动优势被扫交易接口
|
|
/// </summary>
|
|
/// <param name="payConfig">接口配置</param>
|
|
/// <param name="merchantInfo">平台商户信息</param>
|
|
/// <param name="authCode">用户付款授权码</param>
|
|
/// <param name="merchantOrderCode">商户交易订单号</param>
|
|
/// <param name="payAmount">交易金额(元)</param>
|
|
/// <returns></returns>
|
|
public static Model.IRichPayResultModel BeScanPay(IRichPayConfig payConfig,
|
|
MobilePayConfig.PayMerchant merchantInfo, string authCode,
|
|
string merchantOrderCode, string payAmount)
|
|
{
|
|
if (payConfig == null)
|
|
{
|
|
return default(Model.IRichPayResultModel);
|
|
}
|
|
if (merchantInfo == null || string.IsNullOrWhiteSpace(merchantInfo.MerchantCode))
|
|
{
|
|
return default(Model.IRichPayResultModel);
|
|
}
|
|
if (!decimal.TryParse(payAmount, out decimal _PayAmount) || _PayAmount <= 0)
|
|
{
|
|
return default(Model.IRichPayResultModel);
|
|
}
|
|
Dictionary<string, string> _ApiDictionary = new Dictionary<string, string>
|
|
{
|
|
{ "orgcode", payConfig.Organization },//联动优势平台机构号
|
|
{ "usercode", payConfig.PlatformAPPID },//联动优势平台UserCode
|
|
{ "merchantcode", merchantInfo.MerchantCode },//联动优势平台商户号
|
|
{ "timespan", DateTime.Now.ToString("yyyyMMddHHmmss") },//时间戳
|
|
{ "money", _PayAmount.ToString() }, //交易金额
|
|
{ "orderid", merchantOrderCode },//商户订单号
|
|
{ "authcode", authCode }//用户付款授权码
|
|
};
|
|
_ApiDictionary.Add("sign", ApiParamSign(_ApiDictionary, payConfig.PlatformKey));
|
|
LogHelper.WriteReceiveLog("支付反扫-传第三方参数:" +
|
|
_ApiDictionary.Select(pair => pair.Key + "=" + pair.Value).
|
|
DefaultIfEmpty("").Aggregate((a, b) => a + "&" + b));
|
|
return JsonConvert.DeserializeObject<Model.IRichPayResultModel>(CommonHelper.HttpUrlPost(
|
|
_ApiDictionary.Select(pair => pair.Key + "=" + pair.Value).
|
|
DefaultIfEmpty("").Aggregate((a, b) => a + "&" + b), payConfig.BeScanURL,
|
|
"application/x-www-form-urlencoded", payConfig.PlatformTimeout));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 联动优势交易查询接口
|
|
/// </summary>
|
|
/// <param name="payConfig">接口配置</param>
|
|
/// <param name="merchantInfo">平台商户信息</param>
|
|
/// <param name="merchantOrderCode">商户交易订单号</param>
|
|
/// <param name="platformOrderCode">平台交易订单号</param>
|
|
/// <param name="payAmount">交易金额</param>
|
|
/// <returns></returns>
|
|
public static Model.IRichPayResultModel QueryPay(IRichPayConfig payConfig,
|
|
MobilePayConfig.PayMerchant merchantInfo, string merchantOrderCode,
|
|
string platformOrderCode, string payAmount)
|
|
{
|
|
if (payConfig == null)
|
|
{
|
|
return default(Model.IRichPayResultModel);
|
|
}
|
|
if (merchantInfo == null || string.IsNullOrWhiteSpace(merchantInfo.MerchantCode))
|
|
{
|
|
return default(Model.IRichPayResultModel);
|
|
}
|
|
Dictionary<string, string> _ApiDictionary = new Dictionary<string, string>
|
|
{
|
|
{ "orgcode", payConfig.Organization },//联动优势平台机构号
|
|
{ "usercode", payConfig.PlatformAPPID },//联动优势平台UserCode
|
|
{ "timespan", DateTime.Now.ToString("yyyyMMddHHmmss") },//时间戳
|
|
{ "orderid", merchantOrderCode },//商户订单号
|
|
};
|
|
|
|
_ApiDictionary.Add("sign", ApiParamSign(_ApiDictionary, payConfig.PlatformKey));
|
|
LogHelper.WriteReceiveLog("支付查询-传第三方参数:" +
|
|
_ApiDictionary.Select(pair => pair.Key + "=" + pair.Value).
|
|
DefaultIfEmpty("").Aggregate((a, b) => a + "&" + b));
|
|
|
|
return JsonConvert.DeserializeObject<Model.IRichPayResultModel>(CommonHelper.HttpUrlPost(
|
|
_ApiDictionary.Select(pair => pair.Key + "=" + pair.Value).
|
|
DefaultIfEmpty("").Aggregate((a, b) => a + "&" + b), payConfig.QueryURL,
|
|
"application/x-www-form-urlencoded", payConfig.PlatformTimeout));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 联动优势交易撤销(退款)接口
|
|
/// </summary>
|
|
/// <param name="payConfig">接口配置</param>
|
|
/// <param name="merchantInfo">平台商户信息</param>
|
|
/// <param name="platformOrderCode">平台交易订单号</param>
|
|
/// <param name="merchantOrderCode">商户交易订单号</param>
|
|
/// <param name="refundOrderCode">退款订单号</param>
|
|
/// <param name="payAmount">退款金额</param>
|
|
/// <returns></returns>
|
|
public static Model.IRichPayResultModel PayRefund(IRichPayConfig payConfig,
|
|
MobilePayConfig.PayMerchant merchantInfo, string platformOrderCode,
|
|
string merchantOrderCode, string refundOrderCode, string payAmount)
|
|
{
|
|
if (payConfig == null)
|
|
{
|
|
return default(Model.IRichPayResultModel);
|
|
}
|
|
if (merchantInfo == null || string.IsNullOrWhiteSpace(merchantInfo.MerchantCode))
|
|
{
|
|
return default(Model.IRichPayResultModel);
|
|
}
|
|
if (!decimal.TryParse(payAmount, out decimal _PayAmount) || _PayAmount <= 0)
|
|
{
|
|
return default(Model.IRichPayResultModel);
|
|
}
|
|
Dictionary<string, string> _ApiDictionary = new Dictionary<string, string>
|
|
{
|
|
{ "orgcode", payConfig.Organization },//联动优势平台机构号
|
|
{ "usercode", payConfig.PlatformAPPID },//联动优势平台UserCode
|
|
{ "merchantcode", merchantInfo.MerchantCode },//联动优势平台商户号
|
|
{ "timespan", DateTime.Now.ToString("yyyyMMddHHmmss") },//时间戳
|
|
{ "orderid", merchantOrderCode },//原商户订单号
|
|
{ "money", _PayAmount.ToString() } //交易金额
|
|
};
|
|
|
|
_ApiDictionary.Add("sign", ApiParamSign(_ApiDictionary, payConfig.PlatformKey));
|
|
LogHelper.WriteReceiveLog("支付退款-传第三方参数:" +
|
|
_ApiDictionary.Select(pair => pair.Key + "=" + pair.Value).
|
|
DefaultIfEmpty("").Aggregate((a, b) => a + "&" + b));
|
|
|
|
return JsonConvert.DeserializeObject<Model.IRichPayResultModel>(CommonHelper.HttpUrlPost(
|
|
_ApiDictionary.Select(pair => pair.Key + "=" + pair.Value).
|
|
DefaultIfEmpty("").Aggregate((a, b) => a + "&" + b), payConfig.PayRefundURL,
|
|
"application/x-www-form-urlencoded", payConfig.PlatformTimeout));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 联动优势交易撤销查询接口
|
|
/// </summary>
|
|
/// <param name="payConfig">接口配置</param>
|
|
/// <param name="merchantInfo">平台商户信息</param>
|
|
/// <param name="merchantOrderCode">商户交易订单号</param>
|
|
/// <param name="platformOrderCode">平台交易订单号</param>
|
|
/// <param name="payAmount">交易金额</param>
|
|
public static Model.IRichPayResultModel PayQueryRefund(IRichPayConfig payConfig,
|
|
MobilePayConfig.PayMerchant merchantInfo, string merchantOrderCode,
|
|
string platformOrderCode, string payAmount)
|
|
{
|
|
if (payConfig == null)
|
|
{
|
|
return default(Model.IRichPayResultModel);
|
|
}
|
|
if (merchantInfo == null || string.IsNullOrWhiteSpace(merchantInfo.MerchantCode))
|
|
{
|
|
return default(Model.IRichPayResultModel);
|
|
}
|
|
Dictionary<string, string> _ApiDictionary = new Dictionary<string, string>
|
|
{
|
|
{ "orgcode", payConfig.Organization },//联动优势平台机构号
|
|
{ "usercode", payConfig.PlatformAPPID },//联动优势平台UserCode
|
|
{ "timespan", DateTime.Now.ToString("yyyyMMddHHmmss") },//时间戳
|
|
{ "orderid", merchantOrderCode },//商户订单号
|
|
};
|
|
|
|
_ApiDictionary.Add("sign", ApiParamSign(_ApiDictionary, payConfig.PlatformKey));
|
|
LogHelper.WriteReceiveLog("交易撤销查询-传第三方参数:" +
|
|
_ApiDictionary.Select(pair => pair.Key + "=" + pair.Value).
|
|
DefaultIfEmpty("").Aggregate((a, b) => a + "&" + b));
|
|
|
|
return JsonConvert.DeserializeObject<Model.IRichPayResultModel>(CommonHelper.HttpUrlPost(
|
|
_ApiDictionary.Select(pair => pair.Key + "=" + pair.Value).
|
|
DefaultIfEmpty("").Aggregate((a, b) => a + "&" + b), payConfig.PayQueryRefundURL,
|
|
"application/x-www-form-urlencoded", payConfig.PlatformTimeout));
|
|
}
|
|
/// <summary>
|
|
/// 联动优势支付平台参数签名
|
|
/// </summary>
|
|
/// <param name="signParm">待签名参数集</param>
|
|
/// <param name="MD5Key">签名密钥</param>
|
|
/// <returns></returns>
|
|
public static string ApiParamSign(Dictionary<string, string> signParm, string MD5Key)
|
|
{
|
|
return BitConverter.ToString(MD5.Create().ComputeHash(
|
|
Encoding.UTF8.GetBytes(BitConverter.ToString(MD5.Create().ComputeHash(
|
|
Encoding.UTF8.GetBytes(MD5Key))).Replace("-", "").ToUpper() +
|
|
new Dictionary<string, string>(signParm).OrderBy(p => p.Key)
|
|
.Select(pair => pair.Key + "=" + HttpUtility.UrlEncode(pair.Value)).DefaultIfEmpty("")
|
|
.Aggregate((a, b) => a + "&" + b)))).Replace("-", "").ToUpper();
|
|
}
|
|
}
|
|
} |