MSDev.PddOpenSdk.AspNetCore
8.1.2
dotnet add package MSDev.PddOpenSdk.AspNetCore --version 8.1.2
NuGet\Install-Package MSDev.PddOpenSdk.AspNetCore -Version 8.1.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MSDev.PddOpenSdk.AspNetCore" Version="8.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MSDev.PddOpenSdk.AspNetCore" Version="8.1.2" />
<PackageReference Include="MSDev.PddOpenSdk.AspNetCore" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MSDev.PddOpenSdk.AspNetCore --version 8.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MSDev.PddOpenSdk.AspNetCore, 8.1.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MSDev.PddOpenSdk.AspNetCore@8.1.2
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MSDev.PddOpenSdk.AspNetCore&version=8.1.2
#tool nuget:?package=MSDev.PddOpenSdk.AspNetCore&version=8.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
使用说明
先安装Nuget 包 MSDev.PddOpenSdk.AspNetCore。
最新示例代码。
- 在 Startup.cs 中注入服务
services.Configure<PddOptions>(Configuration.GetSection("Pdd"));
services.AddPdd();
appsettings.json配置项参考:
"Pdd": {
"ClientId": "",
"ClientSecret": "",
"CallbackUrl": "",
// 心跳间隔
"HeartBeatSeconds": 5
}
- 然后在控制器使用注入服务
readonly PddService _pdd;
public YourController(PddService pdd)
{
_pdd = pdd;
}
在控制器中使用
/// <summary>
/// 测试获取token
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public async Task<IActionResult> Callback(string code)
{
var token = await _pdd.GetAccessTokenAsync(code);
return Content(token.AccessToken);
}
/// <summary>
/// 多租户测试
/// </summary>
/// <returns></returns>
public async Task<ActionResult> MultiTenantAsync()
{
var service = new PddService(new PddOptions
{
ClientId = "",
ClientSecret = "",
CallbackUrl = "",
// 也可直接将token
// AccessToken=""
});
// 如果没有token,可通过该方法获取token
await service.GetAccessTokenAsync(code: "");
var result = await service.DdkApi.GetDdkGoodsRecommendAsync(
new GetDdkGoodsRecommendRequestModel
{
CatId = 20100
});
return Json(result);
}
- 图片上传示例
var filePath = Path.Combine("images", "logo.png");
byte[] bytes = System.IO.File.ReadAllBytes(filePath);
// 构造图片上传内容
string base64 = "data:image/png;base64," + Convert.ToBase64String(bytes);
var model = new UploadGoodsImageRequestModel
{
Image = base64
};
var result = await _pdd.GoodsApi.UploadGoodsImageAsync(model)
使用socket消息订阅服务
- 在
StartUp.cs添加PddOption选项。// 获取选项 services.Configure<PddOptions>(Configuration.GetSection("Pdd")); - 创建一个
XXXHostService类,继承PddSocketHostServiceBase。 - 重写
XXXHostService的OnMessage方法,以进行消息的自定义处理。 - 在
Program.cs中添加启用服务的代码,如:public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }).ConfigureServices(services => { services.AddHostedService<XXXHostService>(); });
XXXHostService 类可参考Sample项目。
- 心跳检测间隔可在
appsetting.json配置中进行配置,可参考Sample项目中的配置。 此外可在自定义的XXXHostService类中的构造方法中设置HeartBeartSeconds值,会覆盖配置中的值。
所有方法名与官方文档保持一致,并有中文注释提醒,只是更改了命名规范,非常容易查找使用。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.Extensions.Configuration.FileExtensions (>= 8.0.1)
- Microsoft.Extensions.Configuration.Json (>= 8.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- MSDev.PddOpenSdk (>= 8.1.2)
- Websocket.Client (>= 5.1.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 8.1.2 | 207 | 2/26/2025 | |
| 8.1.1 | 174 | 2/26/2025 | |
| 8.0.11 | 150 | 2/13/2025 | |
| 8.0.10 | 194 | 10/12/2024 | |
| 8.0.5 | 220 | 5/9/2024 | |
| 8.0.4 | 217 | 4/16/2024 | |
| 8.0.3 | 178 | 4/12/2024 | |
| 8.0.2 | 169 | 4/10/2024 | |
| 8.0.1 | 176 | 4/10/2024 | |
| 8.0.0 | 258 | 1/9/2024 | |
| 7.0.2 | 343 | 6/20/2023 | |
| 7.0.1 | 251 | 6/16/2023 | |
| 7.0.0 | 458 | 3/17/2023 | |
| 7.0.0-rc | 252 | 2/6/2023 | |
| 6.0.3 | 971 | 7/9/2022 | |
| 6.0.2 | 585 | 5/12/2022 | |
| 6.0.1 | 533 | 5/8/2022 | |
| 6.0.0 | 593 | 2/27/2022 | |
| 6.0.0-rc | 337 | 12/10/2021 | |
| 2.4.4 | 798 | 9/26/2021 | |
| 2.4.3 | 467 | 8/11/2021 | |
| 2.4.2 | 496 | 7/19/2021 | |
| 2.4.1 | 513 | 7/19/2021 | |
| 2.4.0 | 770 | 7/19/2021 | |
| 2.3.5 | 768 | 7/15/2021 | |
| 2.3.4 | 702 | 7/12/2021 | |
| 2.3.3 | 555 | 6/21/2021 | |
| 2.3.2 | 680 | 6/21/2021 | |
| 2.3.1 | 522 | 6/9/2021 | |
| 2.3.0 | 567 | 4/26/2021 | |
| 2.3.0-beta | 400 | 2/25/2021 | |
| 2.2.0-beta | 425 | 12/14/2020 | |
| 2.1.0 | 621 | 10/15/2020 | |
| 2.0.0 | 838 | 9/14/2020 | |
| 1.1.9 | 785 | 10/8/2019 | |
| 1.1.7 | 699 | 7/15/2019 | |
| 1.1.6 | 743 | 5/29/2019 | |
| 1.1.5 | 726 | 5/12/2019 | |
| 1.1.4 | 741 | 4/7/2019 | |
| 1.0.4 | 745 | 3/12/2019 | |
| 1.0.2 | 759 | 2/25/2019 | |
| 1.0.0 | 838 | 1/10/2019 | |
| 0.2.0 | 913 | 11/12/2018 | |
| 0.1.1 | 5,354 | 9/30/2018 | |
| 0.1.0-CI-20180929-054251 | 786 | 9/29/2018 | |
| 0.0.1 | 934 | 9/27/2018 |
1. WebSockek中的CommandType类型