190 lines
8.6 KiB
C#
190 lines
8.6 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace WebService.SDK.PayCommon
|
|
{
|
|
public class FFDZPayHelper
|
|
{
|
|
|
|
#region 商家扫用户支付二维码
|
|
/// <summary>
|
|
/// 交易支付接口测试
|
|
/// 商家扫用户支付二维码
|
|
/// 传入参数
|
|
/// </summary>
|
|
/// <param name="auth_code">用户付款授权码</param>
|
|
/// <param name="out_trade_no">商户订单号</param>
|
|
/// <param name="pay_subject">商品描述</param>
|
|
/// <param name="total_fee">交易金额</param>
|
|
/// <param name="MerchantInfo">商户信息(商户号,秘钥)</param>
|
|
/// <param name="notify_url">通知回调地址</param>
|
|
/// <returns></returns>
|
|
public static string MerchantScan(string auth_code, string out_trade_no, string pay_subject, string total_fee,
|
|
MobilePayConfig.PayMerchant MerchantInfo, string notify_url)
|
|
{
|
|
string ResString = "";
|
|
if (string.IsNullOrEmpty(MerchantInfo.MerchantCode) || string.IsNullOrEmpty(MerchantInfo.MerchantKey))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
long timestamp = CommonHelper.ConvertDataTimeLong(DateTime.Now);
|
|
string MD5String = "", PostStr = "";
|
|
SortedDictionary<string, string> _ApiDictionary = new SortedDictionary<string, string>
|
|
{
|
|
{ "auth_code", auth_code },//支付用户动态码
|
|
{ "busi_id", MerchantInfo.MerchantCode },//商户编号
|
|
{ "channel_type", "0" }, //支付渠道
|
|
{ "fee_type", "CNY" },//币种。默认CNY
|
|
{ "out_trade_no", out_trade_no },//交易上行流水号
|
|
{ "pay_subject", pay_subject },//支付描述信息
|
|
{ "total_fee", total_fee }//交易金额
|
|
};
|
|
PostStr = JsonConvert.SerializeObject(_ApiDictionary);
|
|
MD5String = CommonHelper.GetMD5(timestamp + MerchantInfo.MerchantKey + PostStr) + ":" + timestamp;//创建签名
|
|
LogHelper.WriteReceiveLog(MD5String);
|
|
//以上参数进行签名
|
|
ResString = CommonHelper.HttpUrlPost(PostStr, MobilePayConfig.FFDZPay.BASE_URL + "/order?sign=" + MD5String, "application/json;charset=UTF-8", 5);
|
|
|
|
return ResString;
|
|
}
|
|
#endregion
|
|
|
|
#region 订单查询
|
|
/// <summary>
|
|
/// 交易结果查询
|
|
/// </summary>
|
|
/// <param name="out_trade_no">商户订单号</param>
|
|
/// <param name="trade_no">交易下行流水号</param>
|
|
/// <param name="MerchantInfo">商户信息(商户号,秘钥)</param>
|
|
/// <returns></returns>
|
|
public static string TradeQuery(string out_trade_no, string trade_no, MobilePayConfig.PayMerchant MerchantInfo)
|
|
{
|
|
string ResString = "";
|
|
if (MerchantInfo == null || MerchantInfo.MerchantCode == null || MerchantInfo.MerchantKey == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
long timestamp = CommonHelper.ConvertDataTimeLong(DateTime.Now);
|
|
string MD5String = "", PostStr = "";
|
|
|
|
SortedDictionary<string, string> _ApiDictionary = new SortedDictionary<string, string>();
|
|
_ApiDictionary.Add("busi_id", MerchantInfo.MerchantCode);//商户编号
|
|
if (!string.IsNullOrEmpty(out_trade_no))
|
|
{
|
|
_ApiDictionary.Add("out_trade_no", out_trade_no);//交易上行流水号
|
|
}
|
|
if (!string.IsNullOrEmpty(trade_no))
|
|
{
|
|
_ApiDictionary.Add("trade_no", trade_no);//交易下行流水号
|
|
}
|
|
|
|
PostStr = JsonConvert.SerializeObject(_ApiDictionary);
|
|
MD5String = CommonHelper.GetMD5(timestamp + MerchantInfo.MerchantKey + PostStr) + ":" + timestamp;//创建签名
|
|
//以上参数进行签名
|
|
ResString = CommonHelper.HttpUrlPost(PostStr, MobilePayConfig.FFDZPay.BASE_URL + "/query?sign=" + MD5String, "application/json;charset=UTF-8");
|
|
|
|
return ResString;
|
|
}
|
|
#endregion
|
|
|
|
#region 订单退款
|
|
/// <summary>
|
|
/// 交易支付接口测试
|
|
/// 商家扫用户支付二维码
|
|
/// 传入参数
|
|
/// </summary>
|
|
/// <param name="operator_id">操作员编号</param>
|
|
/// <param name="terminal_id">平台订单号</param>
|
|
/// <param name="refund_fee">退款金额</param>
|
|
/// <param name="refund_subject">退款描述</param>
|
|
/// <param name="out_trade_no">交易上行流水号</param>
|
|
/// <param name="trade_no">交易下行流水号</param>
|
|
/// <param name="out_refund_no">退款流水号</param>
|
|
/// <param name="MerchantInfo">商户信息(商户号,秘钥)</param>
|
|
/// <returns></returns>
|
|
public static string TradeRefund(string operator_id, string terminal_id, string refund_fee, string refund_subject,
|
|
string out_trade_no, string trade_no, string out_refund_no, MobilePayConfig.PayMerchant MerchantInfo)
|
|
{
|
|
string ResString = "";
|
|
if (MerchantInfo == null || MerchantInfo.MerchantCode == null || MerchantInfo.MerchantKey == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
long timestamp = CommonHelper.ConvertDataTimeLong(DateTime.Now);
|
|
string MD5String = "", PostStr = "";
|
|
|
|
SortedDictionary<string, string> _ApiDictionary = new SortedDictionary<string, string>();
|
|
|
|
_ApiDictionary.Add("busi_id", MerchantInfo.MerchantCode);//商户编号
|
|
_ApiDictionary.Add("channel_type", "0"); //支付渠道
|
|
_ApiDictionary.Add("fee_type", "CNY");//币种。默认CNY
|
|
_ApiDictionary.Add("operator_id", operator_id);//操作员编号
|
|
_ApiDictionary.Add("out_refund_no", out_refund_no);//退款流水号
|
|
if (!string.IsNullOrEmpty(out_trade_no))
|
|
{
|
|
_ApiDictionary.Add("out_trade_no", out_trade_no);//交易上行流水号
|
|
}
|
|
_ApiDictionary.Add("refund_fee", refund_fee);//退款金额
|
|
_ApiDictionary.Add("refund_subject", refund_subject);//退款描述
|
|
_ApiDictionary.Add("terminal_id", terminal_id);//设备编号
|
|
if (!string.IsNullOrEmpty(trade_no))
|
|
{
|
|
_ApiDictionary.Add("trade_no", trade_no);//交易下行流水号
|
|
}
|
|
|
|
PostStr = JsonConvert.SerializeObject(_ApiDictionary);
|
|
MD5String = CommonHelper.GetMD5(timestamp + MerchantInfo.MerchantKey + PostStr) + ":" + timestamp;//创建签名
|
|
|
|
//以上参数进行签名
|
|
ResString = CommonHelper.HttpUrlPost(PostStr, MobilePayConfig.FFDZPay.BASE_URL +
|
|
"/refund?sign=" + MD5String, "application/json;charset=UTF-8");
|
|
|
|
return ResString;
|
|
}
|
|
#endregion
|
|
|
|
#region 退款查询
|
|
/// <summary>
|
|
/// 退款查询
|
|
/// </summary>
|
|
/// <param name="operator_id">操作员编号</param>
|
|
/// <param name="terminal_id">设备编号</param>
|
|
/// <param name="out_refund_no">商户退款单号</param>
|
|
/// <param name="MerchantInfo">商户信息(商户号,秘钥)</param>
|
|
/// <returns></returns>
|
|
public static string RefundQuery(string operator_id, string terminal_id, string out_refund_no,
|
|
MobilePayConfig.PayMerchant MerchantInfo)
|
|
{
|
|
string ResString = "";
|
|
if (MerchantInfo == null || MerchantInfo.MerchantCode == null || MerchantInfo.MerchantKey == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
long timestamp = CommonHelper.ConvertDataTimeLong(DateTime.Now);
|
|
string MD5String = "", PostStr = "";
|
|
SortedDictionary<string, string> _ApiDictionary = new SortedDictionary<string, string>
|
|
{
|
|
{ "busi_id", MerchantInfo.MerchantCode },//商户编号
|
|
{ "operator_id", operator_id }, //操作员编号
|
|
{ "out_refund_no", out_refund_no },//商户退款单号
|
|
{ "terminal_id", terminal_id }//设备编号
|
|
};
|
|
//以上参数进行签名
|
|
PostStr = JsonConvert.SerializeObject(_ApiDictionary);
|
|
MD5String = CommonHelper.GetMD5(timestamp + MerchantInfo.MerchantKey + PostStr) + ":" + timestamp;//创建签名
|
|
ResString = CommonHelper.HttpUrlPost(PostStr, MobilePayConfig.FFDZPay.BASE_URL +
|
|
"/refundQuery?sign=" + MD5String, "application/json;charset=UTF-8");
|
|
|
|
return ResString;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|