using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WebService.SDK.PayCommon
{
public class FFDZPayHelper
{
#region 商家扫用户支付二维码
///
/// 交易支付接口测试
/// 商家扫用户支付二维码
/// 传入参数
///
/// 用户付款授权码
/// 商户订单号
/// 商品描述
/// 交易金额
/// 商户信息(商户号,秘钥)
/// 通知回调地址
///
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 _ApiDictionary = new SortedDictionary
{
{ "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 订单查询
///
/// 交易结果查询
///
/// 商户订单号
/// 交易下行流水号
/// 商户信息(商户号,秘钥)
///
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 _ApiDictionary = new SortedDictionary();
_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 订单退款
///
/// 交易支付接口测试
/// 商家扫用户支付二维码
/// 传入参数
///
/// 操作员编号
/// 平台订单号
/// 退款金额
/// 退款描述
/// 交易上行流水号
/// 交易下行流水号
/// 退款流水号
/// 商户信息(商户号,秘钥)
///
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 _ApiDictionary = new SortedDictionary();
_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 退款查询
///
/// 退款查询
///
/// 操作员编号
/// 设备编号
/// 商户退款单号
/// 商户信息(商户号,秘钥)
///
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 _ApiDictionary = new SortedDictionary
{
{ "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
}
}