346 lines
16 KiB
C#
346 lines
16 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using WebService.SDK;
|
|
|
|
namespace MobilePayService
|
|
{
|
|
public class Common
|
|
{
|
|
//商户秘钥
|
|
//protected const string key = "9d101c97133837e13dde2d32a5054abb";
|
|
//接口请求地址,固定不变,无需修改
|
|
//protected const string req_url = "http://www.ffdzpay.com:443/gateway/pay";
|
|
//protected const string req_url = "https://www.ffdzpay.com/gateway/pay";
|
|
protected const string req_url = "https://trans.ffdzpay.com/gateway/pay";
|
|
//版本号,固定不变,无需修改
|
|
//protected const string version = "2.0";
|
|
//服务区、门店编码
|
|
protected static string[] ShopCode = ConfigurationManager.AppSettings["ShopCode"].ToString().Split(',');
|
|
//商户号
|
|
protected static string[] Business_Code = ConfigurationManager.AppSettings["Business_Code"].ToString().Split(',');
|
|
//商户号
|
|
protected static string[] term_Code = ConfigurationManager.AppSettings["term_Code"].ToString().Split(',');
|
|
|
|
public static string get_reqmsg(string trade_state)
|
|
{
|
|
switch (trade_state)
|
|
{
|
|
case "0":
|
|
return "等待付款";
|
|
case "1":
|
|
return "已付款";
|
|
case "2":
|
|
return "已撤单";
|
|
case "3":
|
|
return "申请撤单";
|
|
case "4":
|
|
return "部分退款";
|
|
case "5":
|
|
return "已退款";
|
|
case "6":
|
|
return "交易关闭";
|
|
case "7":
|
|
return "系统保留状态(查询时使用,同时查询退款和撤单记录)";
|
|
case "8":
|
|
return "退款中(平台未返回退款结果)";
|
|
case "9":
|
|
return "退款失败";
|
|
case "10":
|
|
return "待退款";
|
|
case "11":
|
|
return "退款成功";
|
|
case "12":
|
|
return "退款失败";
|
|
case "13":
|
|
return "退款取消";
|
|
case "14":
|
|
return "撤单成功";
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
#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,
|
|
string[] MerchantInfo, string notify_url)
|
|
{
|
|
string ResString = "";
|
|
if (string.IsNullOrEmpty(MerchantInfo[0]) || string.IsNullOrEmpty(MerchantInfo[1]))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
long timestamp = CommonHelper.ConvertDataTimeLong(DateTime.Now);
|
|
string MD5String = "", PostStr = "";
|
|
MD5String = timestamp + MerchantInfo[1] + "{";
|
|
Dictionary<string, string> _Dictionary = new Dictionary<string, string>();
|
|
_Dictionary.Add("auth_code", auth_code);//支付用户动态码
|
|
_Dictionary.Add("busi_id", MerchantInfo[0]);//商户编号
|
|
_Dictionary.Add("channel_type", "0"); //支付渠道
|
|
_Dictionary.Add("fee_type", "CNY");//币种。默认CNY
|
|
//_Dictionary.Add("merchant_param", "");//用户参数
|
|
//_Dictionary.Add("operator_id", "");//操作员编号
|
|
_Dictionary.Add("out_trade_no", out_trade_no);//交易上行流水号
|
|
_Dictionary.Add("pay_subject", pay_subject);//支付描述信息
|
|
//_Dictionary.Add("store_id", "");//门店编号
|
|
//_Dictionary.Add("terminal_id", "");//设备编号
|
|
_Dictionary.Add("total_fee", total_fee);//交易金额
|
|
foreach (KeyValuePair<string, string> kvp in _Dictionary)
|
|
{
|
|
MD5String += "\"" + kvp.Key + "\":\"" + kvp.Value + "\",";
|
|
PostStr += "\"" + kvp.Key + "\":\"" + kvp.Value + "\",";
|
|
}
|
|
MD5String = MD5String.TrimEnd(',') + "}";
|
|
PostStr = "{" + PostStr.TrimEnd(',') + "}";
|
|
MD5String = CommonHelper.GetMD5(MD5String) + ":" + timestamp;//创建签名
|
|
LogHelper.WriteReceiveLog(MD5String);
|
|
//以上参数进行签名
|
|
ResString = CommonHelper.HttpUrlPost(PostStr, req_url + "/order?sign=" + MD5String, "application/json;charset=UTF-8", 5);
|
|
|
|
return ResString;
|
|
}
|
|
#endregion
|
|
|
|
#region 用户扫线上二维码
|
|
public static string QRCodePay(string out_trade_no, string pay_subject, string total_fee, string[] MerchantInfo,
|
|
string notify_url, string channel_type)
|
|
{
|
|
string ResString = "";
|
|
if (string.IsNullOrEmpty(MerchantInfo[0]) || string.IsNullOrEmpty(MerchantInfo[1]))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
long timestamp = CommonHelper.ConvertDataTimeLong(DateTime.Now);
|
|
string MD5String = "", PostStr = "";
|
|
MD5String = timestamp + MerchantInfo[1] + "{";
|
|
Dictionary<string, string> _Dictionary = new Dictionary<string, string>();
|
|
_Dictionary.Add("busi_id", MerchantInfo[0]);//商户编号
|
|
_Dictionary.Add("channel_type", channel_type); //支付渠道
|
|
_Dictionary.Add("fee_type", "CNY");//币种。默认CNY
|
|
//_Dictionary.Add("merchant_param", "");//用户参数
|
|
//_Dictionary.Add("notifyUrl", notify_url);//交易通知地址
|
|
//_Dictionary.Add("openId", "");//用户标识,消费者用户标识
|
|
//_Dictionary.Add("operator_id", "");//操作员编号
|
|
_Dictionary.Add("out_trade_no", out_trade_no);//交易上行流水号
|
|
_Dictionary.Add("pay_subject", pay_subject);//支付描述信息
|
|
//_Dictionary.Add("store_id", "");//门店编号
|
|
//_Dictionary.Add("subAppId", "");//微信APPID
|
|
//_Dictionary.Add("terminal_id", "");//设备编号
|
|
_Dictionary.Add("time_expire", "5");//超时时间
|
|
_Dictionary.Add("total_fee", total_fee);//交易金额
|
|
_Dictionary.Add("trade_type", "QRCODE");//交易类型
|
|
foreach (KeyValuePair<string, string> kvp in _Dictionary)
|
|
{
|
|
MD5String += "\"" + kvp.Key + "\":\"" + kvp.Value + "\",";
|
|
PostStr += "\"" + kvp.Key + "\":\"" + kvp.Value + "\",";
|
|
}
|
|
MD5String = MD5String.TrimEnd(',') + "}";
|
|
PostStr = "{" + PostStr.TrimEnd(',') + "}";
|
|
MD5String = CommonHelper.GetMD5(MD5String) + ":" + timestamp;//创建签名
|
|
//以上参数进行签名
|
|
ResString = CommonHelper.HttpUrlPost(PostStr, req_url + "/preOrder?sign=" + MD5String, "application/json;charset=UTF-8", 5);
|
|
|
|
return ResString;
|
|
}
|
|
#endregion
|
|
|
|
#region 订单查询
|
|
//交易支付接口测试
|
|
//商家扫用户支付二维码
|
|
//传入参数
|
|
//@out_trade_no:商户订单号
|
|
//@trade_no:交易下行流水号
|
|
//@MerchantInfo:商户信息(商户号,秘钥)
|
|
public static string TradeQuery(string out_trade_no, string trade_no, string[] MerchantInfo)
|
|
{
|
|
string ResString = "";
|
|
if (string.IsNullOrEmpty(MerchantInfo[0]) || string.IsNullOrEmpty(MerchantInfo[1]))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
long timestamp = CommonHelper.ConvertDataTimeLong(DateTime.Now);
|
|
string MD5String = "", PostStr = "";
|
|
MD5String = timestamp + MerchantInfo[1] + "{";
|
|
Dictionary<string, string> _Dictionary = new Dictionary<string, string>();
|
|
_Dictionary.Add("busi_id", MerchantInfo[0]);//商户编号
|
|
if (!string.IsNullOrEmpty(out_trade_no))
|
|
{
|
|
_Dictionary.Add("out_trade_no", out_trade_no);//交易上行流水号
|
|
}
|
|
if (!string.IsNullOrEmpty(trade_no))
|
|
{
|
|
_Dictionary.Add("trade_no", trade_no);//交易下行流水号
|
|
}
|
|
foreach (KeyValuePair<string, string> kvp in _Dictionary)
|
|
{
|
|
MD5String += "\"" + kvp.Key + "\":\"" + kvp.Value + "\",";
|
|
PostStr += "\"" + kvp.Key + "\":\"" + kvp.Value + "\",";
|
|
}
|
|
MD5String = MD5String.TrimEnd(',') + "}";
|
|
PostStr = "{" + PostStr.TrimEnd(',') + "}";
|
|
MD5String = CommonHelper.GetMD5(MD5String) + ":" + timestamp;//创建签名
|
|
//以上参数进行签名
|
|
ResString = CommonHelper.HttpUrlPost(PostStr, req_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, string[] MerchantInfo)
|
|
{
|
|
string ResString = "";
|
|
if (string.IsNullOrEmpty(MerchantInfo[0]) || string.IsNullOrEmpty(MerchantInfo[1]))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
long timestamp = CommonHelper.ConvertDataTimeLong(DateTime.Now);
|
|
string MD5String = "", PostStr = "";
|
|
MD5String = timestamp + MerchantInfo[1] + "{";
|
|
Dictionary<string, string> _Dictionary = new Dictionary<string, string>();
|
|
_Dictionary.Add("busi_id", MerchantInfo[0]);//商户编号
|
|
_Dictionary.Add("channel_type", "0"); //支付渠道
|
|
_Dictionary.Add("fee_type", "CNY");//币种。默认CNY
|
|
_Dictionary.Add("operator_id", operator_id);//操作员编号
|
|
_Dictionary.Add("out_refund_no", out_refund_no);//退款流水号
|
|
if (!string.IsNullOrEmpty(out_trade_no))
|
|
{
|
|
_Dictionary.Add("out_trade_no", out_trade_no);//交易上行流水号
|
|
}
|
|
_Dictionary.Add("refund_fee", refund_fee);//退款金额
|
|
_Dictionary.Add("refund_subject", refund_subject);//退款描述
|
|
_Dictionary.Add("terminal_id", terminal_id);//设备编号
|
|
if (!string.IsNullOrEmpty(trade_no))
|
|
{
|
|
_Dictionary.Add("trade_no", trade_no);//交易下行流水号
|
|
}
|
|
foreach (KeyValuePair<string, string> kvp in _Dictionary)
|
|
{
|
|
MD5String += "\"" + kvp.Key + "\":\"" + kvp.Value + "\",";
|
|
PostStr += "\"" + kvp.Key + "\":\"" + kvp.Value + "\",";
|
|
}
|
|
MD5String = MD5String.TrimEnd(',') + "}";
|
|
PostStr = "{" + PostStr.TrimEnd(',') + "}";
|
|
MD5String = CommonHelper.GetMD5(MD5String) + ":" + timestamp;//创建签名
|
|
//以上参数进行签名
|
|
ResString = CommonHelper.HttpUrlPost(PostStr, req_url + "/refund?sign=" + MD5String, "application/json;charset=UTF-8");
|
|
|
|
return ResString;
|
|
}
|
|
#endregion
|
|
|
|
#region 退款查询
|
|
//交易支付接口测试
|
|
//商家扫用户支付二维码
|
|
//传入参数
|
|
//@operator_id:操作员编号
|
|
//@terminal_id:设备编号
|
|
//@out_refund_no:商户退款单号
|
|
//@MerchantInfo:商户信息(商户号,秘钥)
|
|
public static string RefundQuery(string operator_id, string terminal_id, string out_refund_no, string[] MerchantInfo)
|
|
{
|
|
string ResString = "";
|
|
if (string.IsNullOrEmpty(MerchantInfo[0]) || string.IsNullOrEmpty(MerchantInfo[1]))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
long timestamp = CommonHelper.ConvertDataTimeLong(DateTime.Now);
|
|
string MD5String = "", PostStr = "";
|
|
MD5String = timestamp + MerchantInfo[1] + "{";
|
|
Dictionary<string, string> _Dictionary = new Dictionary<string, string>();
|
|
_Dictionary.Add("busi_id", MerchantInfo[0]);//商户编号
|
|
_Dictionary.Add("operator_id", operator_id); //操作员编号
|
|
_Dictionary.Add("out_refund_no", out_refund_no);//商户退款单号
|
|
_Dictionary.Add("terminal_id", terminal_id);//设备编号
|
|
foreach (KeyValuePair<string, string> kvp in _Dictionary)
|
|
{
|
|
MD5String += "\"" + kvp.Key + "\":\"" + kvp.Value + "\",";
|
|
PostStr += "\"" + kvp.Key + "\":\"" + kvp.Value + "\",";
|
|
}
|
|
MD5String = MD5String.TrimEnd(',') + "}";
|
|
PostStr = "{" + PostStr.TrimEnd(',') + "}";
|
|
MD5String = CommonHelper.GetMD5(MD5String) + ":" + timestamp;//创建签名
|
|
//以上参数进行签名
|
|
ResString = CommonHelper.HttpUrlPost(PostStr, req_url + "/refundQuery?sign=" + MD5String, "application/json;charset=UTF-8");
|
|
|
|
return ResString;
|
|
}
|
|
#endregion
|
|
|
|
#region 获取商户编号
|
|
public static string[] GetMerchantInfo(string TICKETCODE)
|
|
{
|
|
string[] MerchantInfo = new string[3];
|
|
string _SERVERPARTCODE = TICKETCODE.Substring(0, 6);
|
|
string _SHOPCODE = TICKETCODE.Length == 28 ? TICKETCODE.Substring(6, 4) : TICKETCODE.Substring(6, 6);
|
|
|
|
for (int i = 0; i < ShopCode.Length; i++)
|
|
{
|
|
if (_SERVERPARTCODE == ShopCode[i] || _SHOPCODE.Substring(2, _SHOPCODE.Length - 2) == ShopCode[i] ||
|
|
_SHOPCODE == ShopCode[i])
|
|
{
|
|
MerchantInfo[0] = Business_Code[i];
|
|
MerchantInfo[1] = term_Code[i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
return MerchantInfo;
|
|
}
|
|
#endregion
|
|
|
|
#region 根据门店获取商户编号
|
|
public static string[] GetMerchantInfo(string serverPartCode,string shopCode)
|
|
{
|
|
string[] MerchantInfo = new string[3];
|
|
|
|
for (int i = 0; i < ShopCode.Length; i++)
|
|
{
|
|
if (serverPartCode == ShopCode[i] || shopCode == ShopCode[i]
|
|
|| shopCode.Substring(2, shopCode.Length - 2) == ShopCode[i])
|
|
{
|
|
MerchantInfo[0] = Business_Code[i];
|
|
MerchantInfo[1] = term_Code[i];
|
|
break;
|
|
}
|
|
}
|
|
return MerchantInfo;
|
|
}
|
|
#endregion
|
|
}
|
|
} |