忽略dll文件git
This commit is contained in:
@@ -1,119 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Alipay.AopSdk.F2FPay.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// 类名:Core
|
||||
/// 功能:支付宝接口公用函数类
|
||||
/// 详细:该类是请求、通知返回两个文件所调用的公用函数核心处理文件,不需要修改
|
||||
/// 版本:3.4
|
||||
/// 修改日期:2015-06-05
|
||||
/// 说明:
|
||||
/// 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
/// 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
|
||||
/// </summary>
|
||||
public class Core
|
||||
{
|
||||
|
||||
public Core()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 除去数组中的空值和签名参数并以字母a到z的顺序排序
|
||||
/// </summary>
|
||||
/// <param name="dicArrayPre">过滤前的参数组</param>
|
||||
/// <returns>过滤后的参数组</returns>
|
||||
public static Dictionary<string, string> FilterPara(SortedDictionary<string, string> dicArrayPre)
|
||||
{
|
||||
Dictionary<string, string> dicArray = new Dictionary<string, string>();
|
||||
foreach (KeyValuePair<string, string> temp in dicArrayPre)
|
||||
{
|
||||
if (temp.Key.ToLower() != "sign" && temp.Key.ToLower()!="sign_type" && temp.Value != "" && temp.Value != null)
|
||||
{
|
||||
dicArray.Add(temp.Key, temp.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return dicArray;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
|
||||
/// </summary>
|
||||
/// <param name="sArray">需要拼接的数组</param>
|
||||
/// <returns>拼接完成以后的字符串</returns>
|
||||
public static string CreateLinkString(Dictionary<string, string> dicArray)
|
||||
{
|
||||
StringBuilder prestr = new StringBuilder();
|
||||
foreach (KeyValuePair<string, string> temp in dicArray)
|
||||
{
|
||||
prestr.Append(temp.Key + "=" + temp.Value + "&");
|
||||
}
|
||||
|
||||
//去掉最後一個&字符
|
||||
int nLen = prestr.Length;
|
||||
prestr.Remove(nLen-1,1);
|
||||
|
||||
return prestr.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对参数值做urlencode
|
||||
/// </summary>
|
||||
/// <param name="sArray">需要拼接的数组</param>
|
||||
/// <param name="code">字符编码</param>
|
||||
/// <returns>拼接完成以后的字符串</returns>
|
||||
//public static string CreateLinkStringUrlencode(Dictionary<string, string> dicArray, Encoding code)
|
||||
//{
|
||||
// StringBuilder prestr = new StringBuilder();
|
||||
// foreach (KeyValuePair<string, string> temp in dicArray)
|
||||
// {
|
||||
// prestr.Append(temp.Key + "=" + HttpUtility.UrlEncode(temp.Value, code) + "&");
|
||||
// }
|
||||
|
||||
// //去掉最後一個&字符
|
||||
// int nLen = prestr.Length;
|
||||
// prestr.Remove(nLen - 1, 1);
|
||||
|
||||
// return prestr.ToString();
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件的md5摘要
|
||||
/// </summary>
|
||||
/// <param name="sFile">文件流</param>
|
||||
/// <returns>MD5摘要结果</returns>
|
||||
public static string GetAbstractToMD5(Stream sFile)
|
||||
{
|
||||
MD5 md5 = new MD5CryptoServiceProvider();
|
||||
byte[] result = md5.ComputeHash(sFile);
|
||||
StringBuilder sb = new StringBuilder(32);
|
||||
for (int i = 0; i < result.Length; i++)
|
||||
{
|
||||
sb.Append(result[i].ToString("x").PadLeft(2, '0'));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件的md5摘要
|
||||
/// </summary>
|
||||
/// <param name="dataFile">文件流</param>
|
||||
/// <returns>MD5摘要结果</returns>
|
||||
public static string GetAbstractToMD5(byte[] dataFile)
|
||||
{
|
||||
MD5 md5 = new MD5CryptoServiceProvider();
|
||||
byte[] result = md5.ComputeHash(dataFile);
|
||||
StringBuilder sb = new StringBuilder(32);
|
||||
for (int i = 0; i < result.Length; i++)
|
||||
{
|
||||
sb.Append(result[i].ToString("x").PadLeft(2, '0'));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
using Alipay.AopSdk.Core.Response;
|
||||
using Alipay.AopSdk.F2FPay.Model;
|
||||
|
||||
namespace Alipay.AopSdk.F2FPay.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// AlipayF2FMonitorResult 的摘要说明
|
||||
/// </summary>
|
||||
public class AlipayF2FMonitorResult
|
||||
{
|
||||
public AlipayF2FMonitorResult()
|
||||
{
|
||||
//
|
||||
// TODO: 在此处添加构造函数逻辑
|
||||
//
|
||||
}
|
||||
|
||||
public MonitorHeartbeatSynResponse response { get; set; }
|
||||
|
||||
public ResultEnum Status
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
if (response.Code == ResultCode.SUCCESS)
|
||||
{
|
||||
return ResultEnum.SUCCESS;
|
||||
}
|
||||
else
|
||||
return ResultEnum.FAILED;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ResultEnum.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
using Alipay.AopSdk.Core.Response;
|
||||
using Alipay.AopSdk.F2FPay.Model;
|
||||
|
||||
namespace Alipay.AopSdk.F2FPay.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// AlipayF2FPayResult 的摘要说明
|
||||
/// </summary>
|
||||
public class AlipayF2FPayResult
|
||||
{
|
||||
public AlipayF2FPayResult()
|
||||
{
|
||||
//
|
||||
// TODO: 在此处添加构造函数逻辑
|
||||
//
|
||||
}
|
||||
|
||||
public AlipayTradePayResponse response { get; set; }
|
||||
|
||||
public ResultEnum Status
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
if (response.Code == ResultCode.SUCCESS)
|
||||
{
|
||||
return ResultEnum.SUCCESS;
|
||||
}
|
||||
else
|
||||
return ResultEnum.FAILED;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ResultEnum.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
using Alipay.AopSdk.Core.Response;
|
||||
using Alipay.AopSdk.F2FPay.Model;
|
||||
|
||||
namespace Alipay.AopSdk.F2FPay.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// AlipayF2FPayResult 的摘要说明
|
||||
/// </summary>
|
||||
public class AlipayF2FPrecreateResult
|
||||
{
|
||||
public AlipayF2FPrecreateResult()
|
||||
{
|
||||
//
|
||||
// TODO: 在此处添加构造函数逻辑
|
||||
//
|
||||
}
|
||||
|
||||
public AlipayTradePrecreateResponse response { get; set; }
|
||||
|
||||
public ResultEnum Status
|
||||
{
|
||||
get
|
||||
{
|
||||
if (response != null)
|
||||
{
|
||||
if (response.Code == ResultCode.SUCCESS)
|
||||
{
|
||||
return ResultEnum.SUCCESS;
|
||||
}
|
||||
if (response.Code == ResultCode.ERROR)
|
||||
{
|
||||
return ResultEnum.UNKNOWN;
|
||||
}
|
||||
else
|
||||
return ResultEnum.FAILED;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ResultEnum.UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
using Alipay.AopSdk.Core.Response;
|
||||
using Alipay.AopSdk.F2FPay.Model;
|
||||
|
||||
namespace Alipay.AopSdk.F2FPay.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// AlipayF2FPayResult 的摘要说明
|
||||
/// </summary>
|
||||
public class AlipayF2FQueryResult
|
||||
{
|
||||
public AlipayF2FQueryResult()
|
||||
{
|
||||
//
|
||||
// TODO: 在此处添加构造函数逻辑
|
||||
//
|
||||
}
|
||||
|
||||
public AlipayTradeQueryResponse response { get; set; }
|
||||
|
||||
public ResultEnum Status
|
||||
{
|
||||
get
|
||||
{
|
||||
if (response != null)
|
||||
{
|
||||
if (response.Code == ResultCode.SUCCESS &&
|
||||
(response.TradeStatus.Equals(TradeStatus.TRADE_SUCCESS) || response.TradeStatus.Equals(TradeStatus.TRADE_FINISHED)))
|
||||
{
|
||||
return ResultEnum.SUCCESS;
|
||||
}
|
||||
if (response.Code == ResultCode.ERROR)
|
||||
{
|
||||
return ResultEnum.UNKNOWN;
|
||||
}
|
||||
else
|
||||
return ResultEnum.FAILED;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ResultEnum.UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using Alipay.AopSdk.Core.Response;
|
||||
using Alipay.AopSdk.F2FPay.Model;
|
||||
|
||||
namespace Alipay.AopSdk.F2FPay.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// AlipayF2FPayResult 的摘要说明
|
||||
/// </summary>
|
||||
public class AlipayF2FRefundResult
|
||||
{
|
||||
public AlipayF2FRefundResult()
|
||||
{
|
||||
//
|
||||
// TODO: 在此处添加构造函数逻辑
|
||||
//
|
||||
}
|
||||
|
||||
public AlipayTradeRefundResponse response { get; set; }
|
||||
|
||||
public ResultEnum Status
|
||||
{
|
||||
get
|
||||
{
|
||||
if (response != null)
|
||||
{
|
||||
if (response.Code == ResultCode.SUCCESS)
|
||||
{
|
||||
return ResultEnum.SUCCESS;
|
||||
}
|
||||
if (response.Code == ResultCode.ERROR)
|
||||
{
|
||||
return ResultEnum.UNKNOWN;
|
||||
}
|
||||
else
|
||||
return ResultEnum.FAILED;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ResultEnum.UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
using Alipay.AopSdk.Core;
|
||||
using Alipay.AopSdk.Core.Request;
|
||||
using Alipay.AopSdk.F2FPay.Domain;
|
||||
|
||||
namespace Alipay.AopSdk.F2FPay.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// AlipayTradePayImpl 的摘要说明
|
||||
/// </summary>
|
||||
public class AlipayMonitorImpl : IAlipayMonitor
|
||||
{
|
||||
|
||||
IAopClient client = null;
|
||||
|
||||
public AlipayMonitorImpl(string monitorUrl, string appId, string merchant_private_key, string format, string version,
|
||||
string sign_type, string alipay_public_key, string charset)
|
||||
{
|
||||
client = new DefaultAopClient(monitorUrl, appId, merchant_private_key, format, version,
|
||||
sign_type, alipay_public_key, charset);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#region 接口方法
|
||||
|
||||
public AlipayF2FMonitorResult mcloudMonitor(AlipayMonitorContentBuilder build)
|
||||
{
|
||||
AlipayF2FMonitorResult result = new AlipayF2FMonitorResult();
|
||||
try
|
||||
{
|
||||
MonitorHeartbeatSynRequest monitorRequest = new MonitorHeartbeatSynRequest();
|
||||
monitorRequest.BizContent = build.BuildJson();
|
||||
result.response = client.Execute(monitorRequest);
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
result.response = null;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 内部方法
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,393 +0,0 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Alipay.AopSdk.Core;
|
||||
using Alipay.AopSdk.Core.Request;
|
||||
using Alipay.AopSdk.Core.Response;
|
||||
using Alipay.AopSdk.Core.Util;
|
||||
using Alipay.AopSdk.F2FPay.Domain;
|
||||
using Alipay.AopSdk.F2FPay.Model;
|
||||
|
||||
|
||||
namespace Alipay.AopSdk.F2FPay.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// AlipayTradePayImpl 的摘要说明
|
||||
/// </summary>
|
||||
public class AlipayTradeImpl : IAlipayTradeService
|
||||
{
|
||||
|
||||
|
||||
|
||||
IAopClient client = null;
|
||||
|
||||
public AlipayTradeImpl(string serverUrl, string appId, string merchant_private_key, string format, string version,
|
||||
string sign_type, string alipay_public_key, string charset)
|
||||
{
|
||||
client = new DefaultAopClient(serverUrl, appId, merchant_private_key, format, version,
|
||||
sign_type, alipay_public_key, charset);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#region 接口方法
|
||||
public AlipayF2FPayResult TradePay(AlipayTradePayContentBuilder builder)
|
||||
{
|
||||
AlipayF2FPayResult payResult = new AlipayF2FPayResult();
|
||||
try
|
||||
{
|
||||
|
||||
AlipayTradePayRequest payRequest = new AlipayTradePayRequest();
|
||||
payRequest.BizContent = builder.BuildJson();
|
||||
AlipayTradePayResponse payResponse = client.Execute(payRequest);
|
||||
|
||||
//payRequest.SetBizModel("");
|
||||
|
||||
if (payResponse != null)
|
||||
{
|
||||
|
||||
switch (payResponse.Code)
|
||||
{
|
||||
case ResultCode.SUCCESS:
|
||||
break;
|
||||
|
||||
//返回支付处理中,需要进行轮询
|
||||
case ResultCode.INRROCESS:
|
||||
|
||||
AlipayTradeQueryResponse queryResponse = LoopQuery(builder.out_trade_no, 10, 3000); //用订单号trade_no进行轮询也是可以的。
|
||||
//轮询结束后还是支付处理中,需要调撤销接口
|
||||
if (queryResponse != null)
|
||||
{
|
||||
if (queryResponse.TradeStatus == "WAIT_BUYER_PAY")
|
||||
{
|
||||
CancelAndRetry(builder.out_trade_no);
|
||||
payResponse.Code = ResultCode.FAIL;
|
||||
}
|
||||
payResponse = toTradePayResponse(queryResponse);
|
||||
}
|
||||
break;
|
||||
|
||||
//明确返回业务失败
|
||||
case ResultCode.FAIL:
|
||||
break;
|
||||
|
||||
//返回系统异常,需要调用一次查询接口,没有返回支付成功的话调用撤销接口撤销交易
|
||||
case ResultCode.ERROR:
|
||||
|
||||
AlipayTradeQueryResponse queryResponse2 = sendTradeQuery(builder.out_trade_no);
|
||||
|
||||
if (queryResponse2 != null)
|
||||
{
|
||||
if (queryResponse2.TradeStatus == TradeStatus.WAIT_BUYER_PAY)
|
||||
{
|
||||
AlipayTradeCancelResponse cancelResponse = CancelAndRetry(builder.out_trade_no);
|
||||
payResponse.Code = ResultCode.FAIL;
|
||||
}
|
||||
|
||||
payResponse = toTradePayResponse(queryResponse2);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
payResult.response = payResponse;
|
||||
break;
|
||||
}
|
||||
payResult.response = payResponse;
|
||||
return payResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
AlipayTradeQueryResponse queryResponse3 = sendTradeQuery(builder.out_trade_no);
|
||||
if (queryResponse3 != null)
|
||||
{
|
||||
if (queryResponse3.TradeStatus == TradeStatus.WAIT_BUYER_PAY)
|
||||
{
|
||||
AlipayTradeCancelResponse cancelResponse = CancelAndRetry(builder.out_trade_no);
|
||||
payResponse.Code = ResultCode.FAIL;
|
||||
}
|
||||
payResponse = toTradePayResponse(queryResponse3);
|
||||
}
|
||||
payResult.response = payResponse;
|
||||
return payResult;
|
||||
}
|
||||
//return payResult;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
||||
AlipayTradePayResponse payResponse = new AlipayTradePayResponse();
|
||||
payResponse.Code = ResultCode.FAIL;
|
||||
payResponse.Body = e.Message;
|
||||
payResult.response = payResponse;
|
||||
return payResult;
|
||||
}
|
||||
}
|
||||
|
||||
public AlipayF2FQueryResult TradeQuery(string outTradeNo)
|
||||
{
|
||||
return AsyncHelper.RunSync(async () => await TradeQueryAsync(outTradeNo));
|
||||
}
|
||||
|
||||
public async Task<AlipayF2FQueryResult> TradeQueryAsync(string outTradeNo)
|
||||
{
|
||||
AlipayF2FQueryResult result = new AlipayF2FQueryResult();
|
||||
try
|
||||
{
|
||||
|
||||
AlipayTradeQueryContentBuilder build = new AlipayTradeQueryContentBuilder();
|
||||
build.out_trade_no = outTradeNo;
|
||||
AlipayTradeQueryRequest payRequest = new AlipayTradeQueryRequest();
|
||||
payRequest.BizContent = build.BuildJson();
|
||||
result.response = await client.ExecuteAsync(payRequest);
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
result.response = null;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public AlipayF2FRefundResult TradeRefund(AlipayTradeRefundContentBuilder builder)
|
||||
{
|
||||
return AsyncHelper.RunSync(async () => await TradeRefundAsync(builder));
|
||||
}
|
||||
|
||||
public async Task<AlipayF2FRefundResult> TradeRefundAsync(AlipayTradeRefundContentBuilder builder)
|
||||
{
|
||||
var refundResult = new AlipayF2FRefundResult();
|
||||
try
|
||||
{
|
||||
|
||||
AlipayTradeRefundRequest refundRequest = new AlipayTradeRefundRequest();
|
||||
refundRequest.BizContent = builder.BuildJson();
|
||||
refundResult.response = await client.ExecuteAsync(refundRequest);
|
||||
return refundResult;
|
||||
}
|
||||
catch
|
||||
{
|
||||
refundResult.response = null;
|
||||
return refundResult;
|
||||
}
|
||||
}
|
||||
|
||||
public AlipayF2FPrecreateResult TradePrecreate(AlipayTradePrecreateContentBuilder builder)
|
||||
{
|
||||
return AsyncHelper.RunSync(async () => await TradePrecreateAsync(builder));
|
||||
}
|
||||
|
||||
public async Task<AlipayF2FPrecreateResult> TradePrecreateAsync(AlipayTradePrecreateContentBuilder builder)
|
||||
{
|
||||
AlipayF2FPrecreateResult payResult = new AlipayF2FPrecreateResult();
|
||||
try
|
||||
{
|
||||
|
||||
AlipayTradePrecreateRequest payRequest = new AlipayTradePrecreateRequest();
|
||||
payRequest.BizContent = builder.BuildJson();
|
||||
|
||||
|
||||
payResult.response = await client.ExecuteAsync(payRequest);
|
||||
return payResult;
|
||||
}
|
||||
catch
|
||||
{
|
||||
payResult.response = null;
|
||||
return payResult;
|
||||
}
|
||||
}
|
||||
|
||||
public AlipayF2FPrecreateResult TradePrecreate(AlipayTradePrecreateContentBuilder builder, string notify_url)
|
||||
{
|
||||
return AsyncHelper.RunSync(async () => await TradePrecreateAsync(builder, notify_url));
|
||||
}
|
||||
|
||||
public async Task<AlipayF2FPrecreateResult> TradePrecreateAsync(AlipayTradePrecreateContentBuilder builder, string notify_url)
|
||||
{
|
||||
AlipayF2FPrecreateResult payResult = new AlipayF2FPrecreateResult();
|
||||
try
|
||||
{
|
||||
AlipayTradePrecreateRequest payRequest = new AlipayTradePrecreateRequest();
|
||||
payRequest.BizContent = builder.BuildJson();
|
||||
payRequest.SetNotifyUrl(notify_url);
|
||||
payResult.response = await client.ExecuteAsync(payRequest);
|
||||
return payResult;
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
payResult.response = null;
|
||||
return payResult;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 内部方法
|
||||
private AlipayTradeCancelResponse tradeCancel(string outTradeNo)
|
||||
{
|
||||
try
|
||||
{
|
||||
AlipayTradeCancelRequest request = new AlipayTradeCancelRequest();
|
||||
StringBuilder sb2 = new StringBuilder();
|
||||
sb2.Append("{\"out_trade_no\":\"" + outTradeNo + "\"}");
|
||||
request.BizContent = sb2.ToString();
|
||||
AlipayTradeCancelResponse response = client.Execute(request);
|
||||
return response;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private AlipayTradePayResponse toTradePayResponse(AlipayTradeQueryResponse queryResponse)
|
||||
{
|
||||
if (queryResponse == null || queryResponse.Code != ResultCode.SUCCESS)
|
||||
return null;
|
||||
AlipayTradePayResponse payResponse = new AlipayTradePayResponse();
|
||||
|
||||
if (queryResponse.TradeStatus == TradeStatus.WAIT_BUYER_PAY)
|
||||
{
|
||||
payResponse.Code = ResultCode.INRROCESS;
|
||||
}
|
||||
if (queryResponse.TradeStatus == TradeStatus.TRADE_FINISHED
|
||||
|| queryResponse.TradeStatus == TradeStatus.TRADE_SUCCESS)
|
||||
{
|
||||
payResponse.Code = ResultCode.SUCCESS;
|
||||
}
|
||||
if (queryResponse.TradeStatus == TradeStatus.TRADE_CLOSED)
|
||||
{
|
||||
payResponse.Code = ResultCode.FAIL;
|
||||
}
|
||||
|
||||
payResponse.Msg = queryResponse.Msg;
|
||||
payResponse.SubCode = queryResponse.SubCode;
|
||||
payResponse.SubMsg = queryResponse.SubMsg;
|
||||
payResponse.Body = queryResponse.Body;
|
||||
payResponse.BuyerLogonId = queryResponse.BuyerLogonId;
|
||||
payResponse.FundBillList = queryResponse.FundBillList;
|
||||
payResponse.OpenId = queryResponse.OpenId;
|
||||
payResponse.OutTradeNo = queryResponse.OutTradeNo;
|
||||
payResponse.ReceiptAmount = queryResponse.ReceiptAmount;
|
||||
payResponse.TotalAmount = queryResponse.TotalAmount;
|
||||
payResponse.TradeNo = queryResponse.TradeNo;
|
||||
|
||||
|
||||
return payResponse;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private AlipayTradeQueryResponse sendTradeQuery(string outTradeNo)
|
||||
{
|
||||
try
|
||||
{
|
||||
AlipayTradeQueryContentBuilder build = new AlipayTradeQueryContentBuilder();
|
||||
build.out_trade_no = outTradeNo;
|
||||
AlipayTradeQueryRequest payRequest = new AlipayTradeQueryRequest();
|
||||
payRequest.BizContent = build.BuildJson();
|
||||
AlipayTradeQueryResponse payResponse = client.Execute(payRequest);
|
||||
return payResponse;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 1.返回支付处理中,轮询订单状态
|
||||
/// 2.本示例中轮询了6次,每次相隔5秒
|
||||
/// </summary>
|
||||
/// <param name="biz_content"></param>
|
||||
/// <returns></returns>
|
||||
private AlipayTradeQueryResponse LoopQuery(string out_trade_no, int count, int interval)
|
||||
{
|
||||
AlipayTradeQueryResponse queryResult = null;
|
||||
|
||||
for (int i = 1; i <= count; i++)
|
||||
{
|
||||
Thread.Sleep(interval);
|
||||
AlipayTradeQueryResponse queryResponse = sendTradeQuery(out_trade_no);
|
||||
if (queryResponse != null && string.Compare(queryResponse.Code, ResultCode.SUCCESS, false) == 0)
|
||||
{
|
||||
queryResult = queryResponse;
|
||||
if (queryResponse.TradeStatus == "TRADE_FINISHED"
|
||||
|| queryResponse.TradeStatus == "TRADE_SUCCESS"
|
||||
|| queryResponse.TradeStatus == "TRADE_CLOSED")
|
||||
return queryResponse;
|
||||
}
|
||||
}
|
||||
|
||||
return queryResult;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 撤销订单
|
||||
/// </summary>
|
||||
/// <param name="out_trade_no"></param>
|
||||
/// <returns></returns>
|
||||
private AlipayTradeCancelResponse CancelAndRetry(string out_trade_no)
|
||||
{
|
||||
AlipayTradeCancelResponse cancelResponse = null;
|
||||
|
||||
cancelResponse = tradeCancel(out_trade_no);
|
||||
|
||||
//如果撤销失败,新开一个线程重试撤销,不影响主业务
|
||||
if (cancelResponse == null || (cancelResponse.Code == ResultCode.FAIL && cancelResponse.RetryFlag == "Y"))
|
||||
{
|
||||
ParameterizedThreadStart ParStart = new ParameterizedThreadStart(cancelThreadFunc);
|
||||
Thread myThread = new Thread(ParStart);
|
||||
object o = out_trade_no;
|
||||
myThread.Start(o);
|
||||
}
|
||||
return cancelResponse;
|
||||
}
|
||||
|
||||
private void cancelThreadFunc(object o)
|
||||
{
|
||||
int RETRYCOUNT = 10;
|
||||
int INTERVAL = 10000;
|
||||
|
||||
for (int i = 0; i < RETRYCOUNT; ++i)
|
||||
{
|
||||
|
||||
Thread.Sleep(INTERVAL);
|
||||
AlipayTradeCancelRequest cancelRequest = new AlipayTradeCancelRequest();
|
||||
string outTradeNo = o.ToString();
|
||||
AlipayTradeCancelResponse cancelResponse = tradeCancel(outTradeNo);
|
||||
|
||||
if (null != cancelResponse)
|
||||
{
|
||||
if (cancelResponse.Code == ResultCode.FAIL)
|
||||
{
|
||||
if (cancelResponse.RetryFlag == "N")
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((cancelResponse.Code == ResultCode.SUCCESS))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == RETRYCOUNT - 1)
|
||||
{
|
||||
/** !!!!!!!注意!!!!!!!!
|
||||
处理到最后一次,还是未撤销成功,需要在商户数据库中对此单最标记,人工介入处理*/
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using Alipay.AopSdk.Core.Util;
|
||||
|
||||
namespace Alipay.AopSdk.F2FPay.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// 类名:Notify
|
||||
/// 功能:支付宝通知处理类
|
||||
/// 详细:处理支付宝各接口通知返回
|
||||
/// 版本:3.3
|
||||
/// 修改日期:2011-07-05
|
||||
/// '说明:
|
||||
/// 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
/// 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
|
||||
///
|
||||
/// //////////////////////注意/////////////////////////////
|
||||
/// 调试通知返回时,可查看或改写log日志的写入TXT里的数据,来检查通知返回是否正常
|
||||
/// </summary>
|
||||
public class Notify
|
||||
{
|
||||
#region 字段
|
||||
private string _partner = ""; //合作身份者ID
|
||||
private string _charset = ""; //编码格式
|
||||
private string _sign_type = ""; //签名方式
|
||||
private string _alipay_public_key = ""; //支付宝公钥文件地址
|
||||
|
||||
//支付宝消息验证地址
|
||||
private string Https_veryfy_url = "";
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// 从配置文件中初始化变量
|
||||
/// </summary>
|
||||
/// <param name="inputPara">通知返回参数数组</param>
|
||||
/// <param name="notify_id">通知验证ID</param>
|
||||
|
||||
public Notify(string charset, string sign_type, string pid, string mapiUrl, string alipay_public_key)
|
||||
{
|
||||
//初始化基础配置信息
|
||||
_charset = charset;
|
||||
_sign_type = sign_type;
|
||||
_partner = pid;
|
||||
Https_veryfy_url = mapiUrl + "?service=notify_verify&";
|
||||
_alipay_public_key = alipay_public_key;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 验证消息是否是支付宝发出的合法消息
|
||||
/// </summary>
|
||||
/// <param name="inputPara">通知返回参数数组</param>
|
||||
/// <param name="notify_id">通知验证ID</param>
|
||||
/// <param name="sign">支付宝生成的签名结果</param>
|
||||
/// <returns>验证结果</returns>
|
||||
public bool Verify(SortedDictionary<string, string> inputPara, string notify_id, string sign)
|
||||
{
|
||||
//获取返回时的签名验证结果
|
||||
bool isSign = GetSignVeryfy(inputPara, sign);
|
||||
//获取是否是支付宝服务器发来的请求的验证结果
|
||||
|
||||
//string responseTxt = "true";
|
||||
//当面付2.0的异步通
|
||||
//if (notify_id != null && notify_id != "") { responseTxt = GetResponseTxt(notify_id); }
|
||||
|
||||
//写日志记录(若要调试,请取消下面两行注释)
|
||||
//string sWord = "responseTxt=" + responseTxt + "\n isSign=" + isSign.ToString() + "\n 返回回来的参数:" + GetPreSignStr(inputPara) + "\n ";
|
||||
//Core.LogResult(sWord);
|
||||
|
||||
//对于开放平台的异步通知,通过验签可以达到安全校验的目的
|
||||
//isSign不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
|
||||
if (isSign)//验证成功
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else//验证失败
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取待签名字符串(调试用)
|
||||
/// </summary>
|
||||
/// <param name="inputPara">通知返回参数数组</param>
|
||||
/// <returns>待签名字符串</returns>
|
||||
private string GetPreSignStr(SortedDictionary<string, string> inputPara)
|
||||
{
|
||||
Dictionary<string, string> sPara = new Dictionary<string, string>();
|
||||
|
||||
//过滤空值、sign与sign_type参数
|
||||
sPara = Core.FilterPara(inputPara);
|
||||
|
||||
//获取待签名字符串
|
||||
string preSignStr = Core.CreateLinkString(sPara);
|
||||
|
||||
return preSignStr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取返回时的签名验证结果
|
||||
/// </summary>
|
||||
/// <param name="inputPara">通知返回参数数组</param>
|
||||
/// <param name="sign">对比的签名结果</param>
|
||||
/// <returns>签名验证结果</returns>
|
||||
private bool GetSignVeryfy(SortedDictionary<string, string> inputPara, string sign)
|
||||
{
|
||||
Dictionary<string, string> sPara = new Dictionary<string, string>();
|
||||
|
||||
//过滤空值、sign与sign_type参数
|
||||
sPara = Core.FilterPara(inputPara);
|
||||
|
||||
//获取待签名字符串
|
||||
string preSignStr = Core.CreateLinkString(sPara);
|
||||
|
||||
|
||||
|
||||
//获得签名验证结果
|
||||
bool isSign = false;
|
||||
if (sign != null && sign != "")
|
||||
{
|
||||
switch (_sign_type)
|
||||
{
|
||||
case "RSA":
|
||||
isSign = AlipaySignature.RSACheckContent(preSignStr, sign, _alipay_public_key, _charset, _sign_type,false);
|
||||
break;
|
||||
case "RSA2":
|
||||
isSign = AlipaySignature.RSACheckContent(preSignStr, sign, _alipay_public_key, _charset, _sign_type,false);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isSign;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取是否是支付宝服务器发来的请求的验证结果
|
||||
/// </summary>
|
||||
/// <param name="notify_id">通知验证ID</param>
|
||||
/// <returns>验证结果</returns>
|
||||
private string GetResponseTxt(string notify_id)
|
||||
{
|
||||
string veryfy_url = Https_veryfy_url + "partner=" + _partner + "¬ify_id=" + notify_id;
|
||||
|
||||
//获取远程服务器ATN结果,验证是否是支付宝服务器发来的请求
|
||||
string responseTxt = Get_Http(veryfy_url, 120000);
|
||||
|
||||
return responseTxt;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取远程服务器ATN结果
|
||||
/// </summary>
|
||||
/// <param name="strUrl">指定URL路径地址</param>
|
||||
/// <param name="timeout">超时时间设置</param>
|
||||
/// <returns>服务器ATN结果</returns>
|
||||
private string Get_Http(string strUrl, int timeout)
|
||||
{
|
||||
string strResult;
|
||||
try
|
||||
{
|
||||
HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(strUrl);
|
||||
myReq.Timeout = timeout;
|
||||
HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
|
||||
Stream myStream = HttpWResp.GetResponseStream();
|
||||
StreamReader sr = new StreamReader(myStream, Encoding.Default);
|
||||
StringBuilder strBuilder = new StringBuilder();
|
||||
while (-1 != sr.Peek())
|
||||
{
|
||||
strBuilder.Append(sr.ReadLine());
|
||||
}
|
||||
|
||||
strResult = strBuilder.ToString();
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
strResult = "错误:" + exp.Message;
|
||||
}
|
||||
|
||||
return strResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
|
||||
namespace Alipay.AopSdk.F2FPay.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// F2FBiz 的摘要说明
|
||||
/// </summary>
|
||||
public class F2FBiz
|
||||
{
|
||||
private F2FBiz() { }
|
||||
|
||||
public static IAlipayTradeService serviceClient = null;
|
||||
|
||||
|
||||
public static IAlipayTradeService CreateClientInstance(string serverUrl, string appId, string merchant_private_key, string version,
|
||||
string sign_type, string alipay_public_key, string charset)
|
||||
{
|
||||
|
||||
|
||||
|
||||
serviceClient = new AlipayTradeImpl(serverUrl, appId, merchant_private_key, "json", version,
|
||||
sign_type, alipay_public_key, charset);
|
||||
|
||||
return serviceClient;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
|
||||
namespace Alipay.AopSdk.F2FPay.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// F2FBiz 的摘要说明
|
||||
/// </summary>
|
||||
public class F2FMonitor
|
||||
{
|
||||
private F2FMonitor() { }
|
||||
|
||||
public static IAlipayMonitor monitorClient = null;
|
||||
|
||||
public static IAlipayMonitor CreateClientInstance(string monitorUrl, string appId, string merchant_private_key, string version,
|
||||
string sign_type, string alipay_public_key, string charset)
|
||||
{
|
||||
if (monitorClient == null)
|
||||
{
|
||||
monitorClient = new AlipayMonitorImpl(monitorUrl, appId, merchant_private_key, "json", version,
|
||||
sign_type, alipay_public_key, charset);
|
||||
}
|
||||
return monitorClient;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using Alipay.AopSdk.Core;
|
||||
|
||||
namespace Alipay.AopSdk.F2FPay.Business
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// F2FResult 的摘要说明
|
||||
/// </summary>
|
||||
public abstract class F2FResult
|
||||
{
|
||||
public abstract bool IsSuccess();
|
||||
public abstract AopResponse AopResponse();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using Alipay.AopSdk.F2FPay.Domain;
|
||||
|
||||
namespace Alipay.AopSdk.F2FPay.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// IAlipayMonitor 的摘要说明
|
||||
/// </summary>
|
||||
public interface IAlipayMonitor
|
||||
{
|
||||
|
||||
//云监控接口
|
||||
AlipayF2FMonitorResult mcloudMonitor(AlipayMonitorContentBuilder builder);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using Alipay.AopSdk.F2FPay.Domain;
|
||||
|
||||
namespace Alipay.AopSdk.F2FPay.Business
|
||||
{
|
||||
/// <summary>
|
||||
/// IAlipayTrade 的摘要说明
|
||||
/// </summary>
|
||||
public interface IAlipayTradeService
|
||||
{
|
||||
//当面付条码支付
|
||||
AlipayF2FPayResult TradePay(AlipayTradePayContentBuilder builder);
|
||||
|
||||
// 当面付2.0交易查询
|
||||
AlipayF2FQueryResult TradeQuery(string outTradeNo);
|
||||
|
||||
// 当面付2.0交易退货
|
||||
AlipayF2FRefundResult TradeRefund(AlipayTradeRefundContentBuilder builder);
|
||||
|
||||
// 当面付2.0预下单
|
||||
AlipayF2FPrecreateResult TradePrecreate(AlipayTradePrecreateContentBuilder builder);
|
||||
AlipayF2FPrecreateResult TradePrecreate(AlipayTradePrecreateContentBuilder builder, string notify_url);
|
||||
|
||||
//云监控接口
|
||||
//AlipayF2FMonitorResult mcloudMonitor(AlipayMonitorContentBuilder builder);
|
||||
Task<AlipayF2FQueryResult> TradeQueryAsync(string outTradeNo);
|
||||
Task<AlipayF2FRefundResult> TradeRefundAsync(AlipayTradeRefundContentBuilder builder);
|
||||
Task<AlipayF2FPrecreateResult> TradePrecreateAsync(AlipayTradePrecreateContentBuilder builder);
|
||||
Task<AlipayF2FPrecreateResult> TradePrecreateAsync(AlipayTradePrecreateContentBuilder builder, string notify_url);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user