MSDev.PddOpenSdk.AspNetCore 8.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package MSDev.PddOpenSdk.AspNetCore --version 8.0.3                
NuGet\Install-Package MSDev.PddOpenSdk.AspNetCore -Version 8.0.3                
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.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MSDev.PddOpenSdk.AspNetCore --version 8.0.3                
#r "nuget: MSDev.PddOpenSdk.AspNetCore, 8.0.3"                
#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.
// Install MSDev.PddOpenSdk.AspNetCore as a Cake Addin
#addin nuget:?package=MSDev.PddOpenSdk.AspNetCore&version=8.0.3

// Install MSDev.PddOpenSdk.AspNetCore as a Cake Tool
#tool nuget:?package=MSDev.PddOpenSdk.AspNetCore&version=8.0.3                

使用说明

先安装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
  • 重写XXXHostServiceOnMessage方法,以进行消息的自定义处理。
  • 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 Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0.10 99 10/12/2024
8.0.5 130 5/9/2024
8.0.4 132 4/16/2024
8.0.3 124 4/12/2024
8.0.2 118 4/10/2024
8.0.1 112 4/10/2024
8.0.0 185 1/9/2024
7.0.2 247 6/20/2023
7.0.1 153 6/16/2023
7.0.0 329 3/17/2023
7.0.0-rc 135 2/6/2023
6.0.3 848 7/9/2022
6.0.2 476 5/12/2022
6.0.1 424 5/8/2022
6.0.0 475 2/27/2022
6.0.0-rc 203 12/10/2021
2.4.4 566 9/26/2021
2.4.3 346 8/11/2021
2.4.2 373 7/19/2021
2.4.1 371 7/19/2021
2.4.0 492 7/19/2021 2.4.0 is deprecated because it is no longer maintained.
2.3.5 498 7/15/2021 2.3.5 is deprecated because it is no longer maintained.
2.3.4 489 7/12/2021 2.3.4 is deprecated because it is no longer maintained.
2.3.3 423 6/21/2021
2.3.2 478 6/21/2021 2.3.2 is deprecated because it is no longer maintained.
2.3.1 375 6/9/2021
2.3.0 418 4/26/2021
2.3.0-beta 238 2/25/2021
2.2.0-beta 278 12/14/2020
2.1.0 485 10/15/2020
2.0.0 606 9/14/2020 2.0.0 is deprecated because it has critical bugs.
1.1.9 639 10/8/2019
1.1.7 534 7/15/2019
1.1.6 599 5/29/2019
1.1.5 550 5/12/2019
1.1.4 578 4/7/2019
1.0.4 570 3/12/2019
1.0.2 579 2/25/2019
1.0.0 701 1/10/2019
0.2.0 724 11/12/2018
0.1.1 5,179 9/30/2018
0.1.0-CI-20180929-054251 600 9/29/2018
0.0.1 762 9/27/2018

同步官方接口到最新(202401);
兼容.net6.0和.net7.0