feat(tenpayv3): 重命名回调通知事件相关的模型

This commit is contained in:
Fu Diwei 2021-05-28 19:08:11 +08:00
parent e0bb33d266
commit 782d46cad9
20 changed files with 178 additions and 119 deletions

View File

@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 MALL_REFUND.SUCCESS 通知的数据。</para> /// <para>表示 MALL_REFUND.SUCCESS 通知的数据。</para>
/// </summary> /// </summary>
public class MallRefundResource : WechatTenpayCallback.Types.IDecryptedResource public class MallRefundResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
/// <summary> /// <summary>
/// 获取或设置微信商户号。 /// 获取或设置微信商户号。

View File

@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 MALL_TRANSACTION.SUCCESS 通知的数据。</para> /// <para>表示 MALL_TRANSACTION.SUCCESS 通知的数据。</para>
/// </summary> /// </summary>
public class MallTransactionResource : WechatTenpayCallback.Types.IDecryptedResource public class MallTransactionResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
/// <summary> /// <summary>
/// 获取或设置微信商户号。 /// 获取或设置微信商户号。

View File

@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 TRANSACTION.SUCCESS 通知的数据。</para> /// <para>表示 TRANSACTION.SUCCESS 通知的数据。</para>
/// </summary> /// </summary>
public class CombineTransactionResource : WechatTenpayCallback.Types.IDecryptedResource public class CombineTransactionResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
public static class Types public static class Types
{ {

View File

@ -1,14 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 DISCOUNT_CARD.USER_ACCEPTED 通知的数据。</para> /// <para>表示 DISCOUNT_CARD.USER_ACCEPTED 通知的数据。</para>
/// <para>表示 DISCOUNT_CARD.AGREEMENT_ENDED 通知的数据。</para> /// <para>表示 DISCOUNT_CARD.AGREEMENT_ENDED 通知的数据。</para>
/// <para>表示 DISCOUNT_CARD.USER_PAID 通知的数据。</para> /// <para>表示 DISCOUNT_CARD.USER_PAID 通知的数据。</para>
/// </summary> /// </summary>
public class DiscountCardResource : WechatTenpayCallback.Types.IDecryptedResource public class DiscountCardResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
public static class Types public static class Types
{ {

View File

@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 COUPON.SEND 通知的数据。</para> /// <para>表示 COUPON.SEND 通知的数据。</para>
/// </summary> /// </summary>
public class MarketingBusifavorCouponResource : WechatTenpayCallback.Types.IDecryptedResource public class MarketingBusifavorCouponResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
public static class Types public static class Types
{ {

View File

@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 COUPON.USE 通知的数据。</para> /// <para>表示 COUPON.USE 通知的数据。</para>
/// </summary> /// </summary>
public class MarketingFavorCouponResource : WechatTenpayCallback.Types.IDecryptedResource public class MarketingFavorCouponResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
public static class Types public static class Types
{ {

View File

@ -1,13 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 COMPLAINT.CREATE 通知的数据。</para> /// <para>表示 COMPLAINT.CREATE 通知的数据。</para>
/// <para>表示 COMPLAINT.STATE_CHANGE 通知的数据。</para> /// <para>表示 COMPLAINT.STATE_CHANGE 通知的数据。</para>
/// </summary> /// </summary>
public class ComplaintResource : WechatTenpayCallback.Types.IDecryptedResource public class ComplaintResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
/// <summary> /// <summary>
/// 获取或设置投诉单号。 /// 获取或设置投诉单号。

View File

@ -1,14 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 REFUND.SUCCESS (仅服务商)通知的数据。</para> /// <para>表示 REFUND.SUCCESS (仅服务商)通知的数据。</para>
/// <para>表示 REFUND.ABNORMAL (仅服务商)通知的数据。</para> /// <para>表示 REFUND.ABNORMAL (仅服务商)通知的数据。</para>
/// <para>表示 REFUND.CLOSED (仅服务商)通知的数据。</para> /// <para>表示 REFUND.CLOSED (仅服务商)通知的数据。</para>
/// </summary> /// </summary>
public class PartnerRefundResource : WechatTenpayCallback.Types.IDecryptedResource public class PartnerRefundResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
public static class Types public static class Types
{ {

View File

@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 TRANSACTION.SUCCESS (仅限服务商)通知的数据。</para> /// <para>表示 TRANSACTION.SUCCESS (仅限服务商)通知的数据。</para>
/// </summary> /// </summary>
public class PartnerTransactionResource : WechatTenpayCallback.Types.IDecryptedResource public class PartnerTransactionResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
public static class Types public static class Types
{ {

View File

@ -1,13 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 PAYSCORE.USER_OPEN_SERVICE 通知的数据。</para> /// <para>表示 PAYSCORE.USER_OPEN_SERVICE 通知的数据。</para>
/// <para>表示 PAYSCORE.USER_CLOSE_SERVICE 通知的数据。</para> /// <para>表示 PAYSCORE.USER_CLOSE_SERVICE 通知的数据。</para>
/// </summary> /// </summary>
public class PayScorePartnerPermissionsResource : WechatTenpayCallback.Types.IDecryptedResource public class PayScorePartnerPermissionsResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
/// <summary> /// <summary>
/// 获取或设置服务商商户号。 /// 获取或设置服务商商户号。

View File

@ -1,13 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 PAYSCORE.USER_CONFIRM 通知的数据。</para> /// <para>表示 PAYSCORE.USER_CONFIRM 通知的数据。</para>
/// <para>表示 PAYSCORE.USER_PAID 通知的数据。</para> /// <para>表示 PAYSCORE.USER_PAID 通知的数据。</para>
/// </summary> /// </summary>
public class PayScorePartnerServiceOrderResource : WechatTenpayCallback.Types.IDecryptedResource public class PayScorePartnerServiceOrderResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
public static class Types public static class Types
{ {

View File

@ -1,13 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 PAYSCORE.USER_OPEN_SERVICE 通知的数据。</para> /// <para>表示 PAYSCORE.USER_OPEN_SERVICE 通知的数据。</para>
/// <para>表示 PAYSCORE.USER_CLOSE_SERVICE 通知的数据。</para> /// <para>表示 PAYSCORE.USER_CLOSE_SERVICE 通知的数据。</para>
/// </summary> /// </summary>
public class PayScorePermissionsResource : WechatTenpayCallback.Types.IDecryptedResource public class PayScorePermissionsResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
/// <summary> /// <summary>
/// 获取或设置微信商户号。 /// 获取或设置微信商户号。

View File

@ -1,13 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 PAYSCORE.USER_CONFIRM 通知的数据。</para> /// <para>表示 PAYSCORE.USER_CONFIRM 通知的数据。</para>
/// <para>表示 PAYSCORE.USER_PAID 通知的数据。</para> /// <para>表示 PAYSCORE.USER_PAID 通知的数据。</para>
/// </summary> /// </summary>
public class PayScoreServiceOrderResource : WechatTenpayCallback.Types.IDecryptedResource public class PayScoreServiceOrderResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
public static class Types public static class Types
{ {

View File

@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 TRANSACTION.SUCCESS (仅限直连商户)通知的数据。</para> /// <para>表示 TRANSACTION.SUCCESS (仅限直连商户)通知的数据。</para>
/// </summary> /// </summary>
public class TransactionResource : WechatTenpayCallback.Types.IDecryptedResource public class TransactionResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
public static class Types public static class Types
{ {

View File

@ -1,14 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Resources namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Events
{ {
/// <summary> /// <summary>
/// <para>表示 REFUND.SUCCESS (仅直连商户)通知的数据。</para> /// <para>表示 REFUND.SUCCESS (仅直连商户)通知的数据。</para>
/// <para>表示 REFUND.ABNORMAL (仅直连商户)通知的数据。</para> /// <para>表示 REFUND.ABNORMAL (仅直连商户)通知的数据。</para>
/// <para>表示 REFUND.CLOSED (仅直连商户)通知的数据。</para> /// <para>表示 REFUND.CLOSED (仅直连商户)通知的数据。</para>
/// </summary> /// </summary>
public class RefundResource : WechatTenpayCallback.Types.IDecryptedResource public class RefundResource : WechatTenpayEvent.Types.IDecryptedResource
{ {
public static class Types public static class Types
{ {

View File

@ -1,24 +0,0 @@
using System;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Exceptions
{
public class WechatTenpayCallbackDecryptionException : WechatTenpayException
{
/// <inheritdoc/>
internal WechatTenpayCallbackDecryptionException()
{
}
/// <inheritdoc/>
internal WechatTenpayCallbackDecryptionException(string message)
: base(message)
{
}
/// <inheritdoc/>
internal WechatTenpayCallbackDecryptionException(string message, Exception innerException)
: base(message, innerException)
{
}
}
}

View File

@ -0,0 +1,24 @@
using System;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Exceptions
{
public class WechatTenpayEventDecryptionException : WechatTenpayException
{
/// <inheritdoc/>
internal WechatTenpayEventDecryptionException()
{
}
/// <inheritdoc/>
internal WechatTenpayEventDecryptionException(string message)
: base(message)
{
}
/// <inheritdoc/>
internal WechatTenpayEventDecryptionException(string message, Exception innerException)
: base(message, innerException)
{
}
}
}

View File

@ -5,21 +5,20 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
/// <summary> /// <summary>
/// 为 <see cref="WechatTenpayClient"/> 提供回调通知事件的扩展方法。 /// 为 <see cref="WechatTenpayClient"/> 提供回调通知事件的扩展方法。
/// </summary> /// </summary>
public static class WechatTenpayClientCallbackDeserializationExtensions public static class WechatTenpayClientEventExtensions
{ {
/// <summary> /// <summary>
/// <para>反序列化得到 <see cref="WechatTenpayCallback"/> 对象。</para> /// <para>反序列化得到 <see cref="WechatTenpayEvent"/> 对象。</para>
/// </summary> /// </summary>
/// <typeparam name="TResponse"></typeparam>
/// <param name="client"></param> /// <param name="client"></param>
/// <param name="callbackJson"></param> /// <param name="callbackJson"></param>
/// <returns></returns> /// <returns></returns>
public static WechatTenpayCallback DeserializeCallback(this WechatTenpayClient client, string callbackJson) public static WechatTenpayEvent DeserializeEvent(this WechatTenpayClient client, string callbackJson)
{ {
if (client == null) throw new ArgumentNullException(nameof(client)); if (client == null) throw new ArgumentNullException(nameof(client));
if (string.IsNullOrEmpty(callbackJson)) throw new ArgumentNullException(callbackJson); if (string.IsNullOrEmpty(callbackJson)) throw new ArgumentNullException(callbackJson);
return client.JsonSerializer.Deserialize<WechatTenpayCallback>(callbackJson); return client.JsonSerializer.Deserialize<WechatTenpayEvent>(callbackJson);
} }
/// <summary> /// <summary>
@ -29,13 +28,13 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
/// <param name="client"></param> /// <param name="client"></param>
/// <param name="callback"></param> /// <param name="callback"></param>
/// <returns></returns> /// <returns></returns>
public static T DecryptCallbackResource<T>(this WechatTenpayClient client, WechatTenpayCallback callback) public static T DecryptEventResource<T>(this WechatTenpayClient client, WechatTenpayEvent callback)
where T : WechatTenpayCallback.Types.IDecryptedResource, new() where T : WechatTenpayEvent.Types.IDecryptedResource, new()
{ {
if (client == null) throw new ArgumentNullException(nameof(client)); if (client == null) throw new ArgumentNullException(nameof(client));
if (callback == null) throw new ArgumentNullException(nameof(callback)); if (callback == null) throw new ArgumentNullException(nameof(callback));
return DecryptCallbackResource<T>(client, callback.Resource); return DecryptEventResource<T>(client, callback.Resource);
} }
/// <summary> /// <summary>
@ -45,8 +44,8 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
/// <param name="client"></param> /// <param name="client"></param>
/// <param name="resource"></param> /// <param name="resource"></param>
/// <returns></returns> /// <returns></returns>
public static T DecryptCallbackResource<T>(this WechatTenpayClient client, WechatTenpayCallback.Types.Resource resource) public static T DecryptEventResource<T>(this WechatTenpayClient client, WechatTenpayEvent.Types.Resource resource)
where T : WechatTenpayCallback.Types.IDecryptedResource, new() where T : WechatTenpayEvent.Types.IDecryptedResource, new()
{ {
if (client == null) throw new ArgumentNullException(nameof(client)); if (client == null) throw new ArgumentNullException(nameof(client));
if (resource == null) throw new ArgumentNullException(nameof(resource)); if (resource == null) throw new ArgumentNullException(nameof(resource));
@ -66,12 +65,12 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
} }
catch (Exception ex) catch (Exception ex)
{ {
throw new Exceptions.WechatTenpayCallbackDecryptionException("Decrypt callback failed.", ex); throw new Exceptions.WechatTenpayEventDecryptionException("Decrypt event resource failed.", ex);
} }
} }
else else
{ {
throw new Exceptions.WechatTenpayCallbackDecryptionException("Unknown encrypt algorithm of the resource."); throw new Exceptions.WechatTenpayEventDecryptionException("Unknown encrypt algorithm of the resource.");
} }
return client.JsonSerializer.Deserialize<T>(plainJson); return client.JsonSerializer.Deserialize<T>(plainJson);

View File

@ -14,12 +14,10 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_3.shtml </para> /// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_3.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/wechatpay/wechatpay4_3.shtml </para> /// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/wechatpay/wechatpay4_3.shtml </para>
/// </summary> /// </summary>
/// <typeparam name="TResponse"></typeparam>
/// <param name="client"></param> /// <param name="client"></param>
/// <param name="response"></param> /// <param name="response"></param>
/// <returns></returns> /// <returns></returns>
public static TResponse DecryptResponseEncryptedData<TResponse>(this WechatTenpayClient client, TResponse response) public static Models.GetEcommerceApplymentByOutRequestNumberResponse DecryptResponseEncryptedData(this WechatTenpayClient client, Models.GetEcommerceApplymentByOutRequestNumberResponse response)
where TResponse : WechatTenpayResponse
{ {
if (client == null) throw new ArgumentNullException(nameof(client)); if (client == null) throw new ArgumentNullException(nameof(client));
if (response == null) throw new ArgumentNullException(nameof(response)); if (response == null) throw new ArgumentNullException(nameof(response));
@ -30,42 +28,6 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
if (!response.IsSuccessful()) if (!response.IsSuccessful())
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed, because of the response is not successful."); throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed, because of the response is not successful.");
if (response is Models.GetEcommerceApplymentByOutRequestNumberResponse resGetEcommerceApplymentByOutRequestNumber)
{
DecryptResponse(resGetEcommerceApplymentByOutRequestNumber, client.MerchantCertPrivateKey);
return (resGetEcommerceApplymentByOutRequestNumber as TResponse)!;
}
else if (response is Models.GetEcommerceBillFundflowBillResponse resGetEcommerceBillFundflowBill)
{
DecryptResponse(resGetEcommerceBillFundflowBill, client.MerchantCertPrivateKey);
return (resGetEcommerceBillFundflowBill as TResponse)!;
}
else if (response is Models.GetMerchantServiceComplaintByComplaintIdResponse resGetMerchantServiceComplaintByComplaintId)
{
DecryptResponse(resGetMerchantServiceComplaintByComplaintId, client.MerchantCertPrivateKey);
return (resGetMerchantServiceComplaintByComplaintId as TResponse)!;
}
else if (response is Models.QueryCertificatesResponse resQueryCertificates)
{
DecryptResponse(resQueryCertificates, client.MerchantV3Secret);
return (resQueryCertificates as TResponse)!;
}
else if (response is Models.QueryMerchantServiceComplaintsResponse resQueryMerchantServiceComplaints)
{
DecryptResponse(resQueryMerchantServiceComplaints, client.MerchantCertPrivateKey);
return (resQueryMerchantServiceComplaints as TResponse)!;
}
else if (response is Models.QuerySmartGuidesResponse resQuerySmartGuides)
{
DecryptResponse(resQuerySmartGuides, client.MerchantCertPrivateKey);
return (resQuerySmartGuides as TResponse)!;
}
return response;
}
private static void DecryptResponse(Models.GetEcommerceApplymentByOutRequestNumberResponse response, string privateKey)
{
if (response.AccountValidation != null) if (response.AccountValidation != null)
{ {
IList<Exception> exceptions = new List<Exception>(); IList<Exception> exceptions = new List<Exception>();
@ -77,7 +39,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
try try
{ {
accountValidationModel.AccountNameEncryptedData = Utilities.RsaUtil.DecryptWithECB( accountValidationModel.AccountNameEncryptedData = Utilities.RsaUtil.DecryptWithECB(
privateKey, client.MerchantCertPrivateKey,
accountValidationModel.AccountNameEncryptedData accountValidationModel.AccountNameEncryptedData
); );
} }
@ -92,7 +54,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
try try
{ {
accountValidationModel.AccountNumberEncryptedData = Utilities.RsaUtil.DecryptWithECB( accountValidationModel.AccountNumberEncryptedData = Utilities.RsaUtil.DecryptWithECB(
privateKey, client.MerchantCertPrivateKey,
accountValidationModel.AccountNumberEncryptedData! accountValidationModel.AccountNumberEncryptedData!
); );
} }
@ -105,10 +67,29 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
if (exceptions.Any()) if (exceptions.Any())
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed.", new AggregateException(exceptions)); throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed.", new AggregateException(exceptions));
} }
return response;
} }
private static void DecryptResponse(Models.GetEcommerceBillFundflowBillResponse response, string privateKey) /// <summary>
/// <para>解密响应中返回的敏感数据。该方法会改变传入的响应信息。</para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_3.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/wechatpay/wechatpay4_3.shtml </para>
/// </summary>
/// <param name="client"></param>
/// <param name="response"></param>
/// <returns></returns>
public static Models.GetEcommerceBillFundflowBillResponse DecryptResponseEncryptedData(this WechatTenpayClient client, Models.GetEcommerceBillFundflowBillResponse response)
{ {
if (client == null) throw new ArgumentNullException(nameof(client));
if (response == null) throw new ArgumentNullException(nameof(response));
if (string.IsNullOrEmpty(client.MerchantCertPrivateKey))
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed, because of there is no merchant private key.");
if (!response.IsSuccessful())
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed, because of the response is not successful.");
if (response.DownloadBillList != null) if (response.DownloadBillList != null)
{ {
IList<Exception> exceptions = new List<Exception>(); IList<Exception> exceptions = new List<Exception>();
@ -120,7 +101,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
try try
{ {
downloadBillModel.EncryptKeyEncryptedData = Utilities.RsaUtil.DecryptWithECB( downloadBillModel.EncryptKeyEncryptedData = Utilities.RsaUtil.DecryptWithECB(
privateKey, client.MerchantCertPrivateKey,
downloadBillModel.EncryptKeyEncryptedData downloadBillModel.EncryptKeyEncryptedData
); );
} }
@ -134,10 +115,29 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
if (exceptions.Any()) if (exceptions.Any())
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed.", new AggregateException(exceptions)); throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed.", new AggregateException(exceptions));
} }
return response;
} }
private static void DecryptResponse(Models.GetMerchantServiceComplaintByComplaintIdResponse response, string privateKey) /// <summary>
/// <para>解密响应中返回的敏感数据。该方法会改变传入的响应信息。</para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_3.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/wechatpay/wechatpay4_3.shtml </para>
/// </summary>
/// <param name="client"></param>
/// <param name="response"></param>
/// <returns></returns>
public static Models.GetMerchantServiceComplaintByComplaintIdResponse DecryptResponseEncryptedData(this WechatTenpayClient client, Models.GetMerchantServiceComplaintByComplaintIdResponse response)
{ {
if (client == null) throw new ArgumentNullException(nameof(client));
if (response == null) throw new ArgumentNullException(nameof(response));
if (string.IsNullOrEmpty(client.MerchantCertPrivateKey))
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed, because of there is no merchant private key.");
if (!response.IsSuccessful())
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed, because of the response is not successful.");
if (response.ComplaintDetail != null) if (response.ComplaintDetail != null)
{ {
if (!string.IsNullOrEmpty(response.PayerPhoneEncryptedData)) if (!string.IsNullOrEmpty(response.PayerPhoneEncryptedData))
@ -145,7 +145,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
try try
{ {
response.PayerPhoneEncryptedData = Utilities.RsaUtil.DecryptWithECB( response.PayerPhoneEncryptedData = Utilities.RsaUtil.DecryptWithECB(
privateKey, client.MerchantCertPrivateKey,
response.PayerPhoneEncryptedData! response.PayerPhoneEncryptedData!
); );
} }
@ -155,10 +155,29 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
} }
} }
} }
return response;
} }
private static void DecryptResponse(Models.QueryCertificatesResponse response, string aesKey) /// <summary>
/// <para>解密响应中返回的敏感数据。该方法会改变传入的响应信息。</para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_3.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/wechatpay/wechatpay4_3.shtml </para>
/// </summary>
/// <param name="client"></param>
/// <param name="response"></param>
/// <returns></returns>
public static Models.QueryCertificatesResponse DecryptResponseEncryptedData(this WechatTenpayClient client, Models.QueryCertificatesResponse response)
{ {
if (client == null) throw new ArgumentNullException(nameof(client));
if (response == null) throw new ArgumentNullException(nameof(response));
if (string.IsNullOrEmpty(client.MerchantV3Secret))
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed, because of there is no merchant secret.");
if (!response.IsSuccessful())
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed, because of the response is not successful.");
if (response.CertificateList != null) if (response.CertificateList != null)
{ {
IList<Exception> exceptions = new List<Exception>(); IList<Exception> exceptions = new List<Exception>();
@ -170,7 +189,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
try try
{ {
certificateModel.EncryptCertificate.CipherText = Utilities.AesUtil.DecryptWithGCM( certificateModel.EncryptCertificate.CipherText = Utilities.AesUtil.DecryptWithGCM(
aesKey: aesKey, aesKey: client.MerchantV3Secret,
nonce: certificateModel.EncryptCertificate.Nonce, nonce: certificateModel.EncryptCertificate.Nonce,
associatedData: certificateModel.EncryptCertificate.AssociatedData, associatedData: certificateModel.EncryptCertificate.AssociatedData,
cipherText: certificateModel.EncryptCertificate.CipherText cipherText: certificateModel.EncryptCertificate.CipherText
@ -190,10 +209,29 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
if (exceptions.Any()) if (exceptions.Any())
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed.", new AggregateException(exceptions)); throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed.", new AggregateException(exceptions));
} }
return response;
} }
private static void DecryptResponse(Models.QueryMerchantServiceComplaintsResponse response, string privateKey) /// <summary>
/// <para>解密响应中返回的敏感数据。该方法会改变传入的响应信息。</para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_3.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/wechatpay/wechatpay4_3.shtml </para>
/// </summary>
/// <param name="client"></param>
/// <param name="response"></param>
/// <returns></returns>
public static Models.QueryMerchantServiceComplaintsResponse DecryptResponseEncryptedData(this WechatTenpayClient client, Models.QueryMerchantServiceComplaintsResponse response)
{ {
if (client == null) throw new ArgumentNullException(nameof(client));
if (response == null) throw new ArgumentNullException(nameof(response));
if (string.IsNullOrEmpty(client.MerchantCertPrivateKey))
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed, because of there is no merchant private key.");
if (!response.IsSuccessful())
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed, because of the response is not successful.");
if (response.ComplaintList != null) if (response.ComplaintList != null)
{ {
IList<Exception> exceptions = new List<Exception>(); IList<Exception> exceptions = new List<Exception>();
@ -205,7 +243,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
try try
{ {
complaintModel.PayerPhoneEncryptedData = Utilities.RsaUtil.DecryptWithECB( complaintModel.PayerPhoneEncryptedData = Utilities.RsaUtil.DecryptWithECB(
privateKey, client.MerchantCertPrivateKey,
complaintModel.PayerPhoneEncryptedData! complaintModel.PayerPhoneEncryptedData!
); );
} }
@ -219,10 +257,29 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
if (exceptions.Any()) if (exceptions.Any())
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed.", new AggregateException(exceptions)); throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed.", new AggregateException(exceptions));
} }
return response;
} }
private static void DecryptResponse(Models.QuerySmartGuidesResponse response, string privateKey) /// <summary>
/// <para>解密响应中返回的敏感数据。该方法会改变传入的响应信息。</para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_3.shtml </para>
/// <para>REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/wechatpay/wechatpay4_3.shtml </para>
/// </summary>
/// <param name="client"></param>
/// <param name="response"></param>
/// <returns></returns>
public static Models.QuerySmartGuidesResponse DecryptResponseEncryptedData(this WechatTenpayClient client, Models.QuerySmartGuidesResponse response)
{ {
if (client == null) throw new ArgumentNullException(nameof(client));
if (response == null) throw new ArgumentNullException(nameof(response));
if (string.IsNullOrEmpty(client.MerchantCertPrivateKey))
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed, because of there is no merchant private key.");
if (!response.IsSuccessful())
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed, because of the response is not successful.");
if (response.GuideList != null) if (response.GuideList != null)
{ {
IList<Exception> exceptions = new List<Exception>(); IList<Exception> exceptions = new List<Exception>();
@ -234,7 +291,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
try try
{ {
guideModel.UserNameEncryptedData = Utilities.RsaUtil.DecryptWithECB( guideModel.UserNameEncryptedData = Utilities.RsaUtil.DecryptWithECB(
privateKey, client.MerchantCertPrivateKey,
guideModel.UserNameEncryptedData guideModel.UserNameEncryptedData
); );
} }
@ -249,7 +306,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
try try
{ {
guideModel.UserMobileEncryptedData = Utilities.RsaUtil.DecryptWithECB( guideModel.UserMobileEncryptedData = Utilities.RsaUtil.DecryptWithECB(
privateKey, client.MerchantCertPrivateKey,
guideModel.UserMobileEncryptedData guideModel.UserMobileEncryptedData
); );
} }
@ -263,6 +320,8 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
if (exceptions.Any()) if (exceptions.Any())
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed.", new AggregateException(exceptions)); throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed.", new AggregateException(exceptions));
} }
return response;
} }
} }
} }

View File

@ -6,7 +6,8 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
/// <summary> /// <summary>
/// 表示微信支付 API 回调通知事件的基类。 /// 表示微信支付 API 回调通知事件的基类。
/// </summary> /// </summary>
public abstract class WechatTenpayCallback [Serializable]
public class WechatTenpayEvent
{ {
public static class Types public static class Types
{ {