Skip to content

Commit

Permalink
🎨 调用商城支付相关模型
Browse files Browse the repository at this point in the history
  • Loading branch information
Lxy829 committed Aug 27, 2024
1 parent bbc6291 commit 7e492cd
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Mobius.Models/Mobius.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
</Compile>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Essensoft.Paylink.WeChatPay" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions src/Mobius.Models/Models/Shop/Response/ResultResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Mobius.Models.Shop.Response;

public class ResultResponse<TData, TOtherData>
{
public TData? Data { get; set; }

public TOtherData? OtherData { get; set; }
}
11 changes: 8 additions & 3 deletions src/Mobius.Models/Models/Shop/Response/ShopBaseResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ namespace Mobius.Models.Shop.Response;
/// <summary>
/// 商城响应模型类
/// </summary>
/// <typeparam name="T"></typeparam>
public sealed class ShopBaseResponse<T> : IShopBaseResponse
/// <typeparam name="TData"></typeparam>
public class ShopBaseResponse<TData> : IShopBaseResponse
{
/// <inheritdoc/>
public bool Status { get; set; }

/// <inheritdoc cref="IShopBaseResponse.Data"/>
public T? Data { get; set; }
public TData? Data { get; set; }

/// <inheritdoc/>
public string? Msg { get; set; }

/// <inheritdoc/>
object? IShopBaseResponse.Data => Data;
}

public class ShopBaseResponse<TData, TOtherData> : ShopBaseResponse<TData>
{
public TOtherData? OtherData { get; set; }
}
8 changes: 8 additions & 0 deletions src/Mobius.Models/Models/Shop/Response/WeiChatPayResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Mobius.Models.Shop.Response;

public class WeiChatPayResponse
{
public WeChatPayUnifiedOrderResponse? Response { get; set; }

public string? PaymentId { get; set; }
}
23 changes: 23 additions & 0 deletions src/Mobius.SDK/Services/Abstractions/ISppWebApiService.Send.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,28 @@ Task<ApiRspImpl<nil>> SendAsync(
HttpHandlerCategory category = DefaultHttpHandlerCategory)
where TRequestModel : notnull;

/// <summary>
/// RequestModel+ResponseModel(调用 Shop 服务端接口)
/// </summary>
/// <typeparam name="TRequestModel">请求模型类型</typeparam>
/// <typeparam name="TResponseModel">响应模型类型</typeparam>
/// <typeparam name="TResponseOtherDataModel">OtherData 响应模型</typeparam>
/// <param name="cancellationToken">传播应取消操作的通知</param>
/// <param name="method">HTTP 方法</param>
/// <param name="requestUri">服务端接口 Url 地址</param>
/// <param name="request">请求模型</param>
/// <param name="responseContentMaybeNull">响应内容是否能为<see langword="null"/></param>
/// <param name="isAnonymous">是否使用匿名身份访问</param>
/// <param name="category"></param>
/// <returns></returns>
Task<ApiRspImpl<ResultResponse<TResponseModel, TResponseOtherDataModel>?>> SendShopAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TRequestModel, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TResponseModel, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TResponseOtherDataModel>(
CancellationToken cancellationToken,
HttpMethod method,
string requestUri,
TRequestModel? request,
bool responseContentMaybeNull = false,
bool isAnonymous = false,
HttpHandlerCategory category = DefaultHttpHandlerCategory)
where TRequestModel : notnull;
#endregion
}
25 changes: 25 additions & 0 deletions src/Mobius.SDK/Services/SppWebApiServiceImplBase.Send.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,29 @@ public async Task<ApiRspImpl<nil>> SendAsync(
shopApiDeserialize: SppWebApiClientSendArgs.ShopApiDeserializeImpl<TResponseModel>);
return rsp;
}

/// <inheritdoc/>
public async Task<ApiRspImpl<ResultResponse<TResponseModel, TResponseOtherDataModel>?>> SendShopAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TRequestModel, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TResponseModel, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TResponseOtherDataModel>(
CancellationToken cancellationToken,
HttpMethod method,
string requestUri,
TRequestModel? request,
bool responseContentMaybeNull,
bool isAnonymous,
HttpHandlerCategory category)
where TRequestModel : notnull
{
var rsp = await SendCoreAsync<TRequestModel, ResultResponse<TResponseModel, TResponseOtherDataModel>>(
isAnonymous: isAnonymous,
isApi: true,
cancellationToken,
method,
requestUri,
requestModel: request,
responseContentMaybeNull,
isSecurity: false,
category: category,
shopApiDeserialize: SppWebApiClientSendArgs.ShopApiDeserializeImpl<TResponseModel, TResponseOtherDataModel>);
return rsp;
}
}
27 changes: 27 additions & 0 deletions src/Mobius.SDK/Services/SppWebApiServiceImplBase.SendArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,32 @@ public override async Task<HttpRequestMessage> GetHttpRequestMessage(WebApiClien
return ApiRspHelper.Code((ApiRspCode)response.StatusCode, obj.Msg, obj.Data);
}
}

public static async Task<object?> ShopApiDeserializeImpl<TData, TOtherData>(WebApiClientService s, HttpResponseMessage response, CancellationToken cancellationToken = default)
{
using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
#pragma warning disable IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
var obj = await SystemTextJsonSerializer.DeserializeAsync<ShopBaseResponse<TData, TOtherData>>(stream, ((SppWebApiServiceImplBase)s).UseJsonSerializerOptions_ShopApi, cancellationToken: cancellationToken);
#pragma warning restore IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
if (obj == null)
{
return ApiRspHelper.Code<TData>(ApiRspCode.NoResponseContent);
}
if (obj.Status)
{
var result = new ResultResponse<TData, TOtherData>
{
Data = obj.Data,
OtherData = obj.OtherData,
};
return ApiRspHelper.Ok(result);
}
else
{
return ApiRspHelper.Code((ApiRspCode)response.StatusCode, obj.Msg, obj.Data);
}
}
}
}
3 changes: 2 additions & 1 deletion src/Shared/GlobalUsings.Mobius.Models.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
<Using Include="Mobius.Models.Shop.Abstractions" />
<Using Include="Mobius.Models.Shop.Request" />
<Using Include="Mobius.Models.Shop.Response" />

<Using Include="Essensoft.Paylink.WeChatPay.V2.Response" />

<!-- 👇 插件 -->
<Using Include="Mobius.Models.Plugin.Response" />
<Using Include="Mobius.Models.Plugin.Request" />
Expand Down

0 comments on commit 7e492cd

Please sign in to comment.