MSDev.PddOpenSdk.AspNetCore 2.4.4

Install-Package MSDev.PddOpenSdk.AspNetCore -Version 2.4.4
dotnet add package MSDev.PddOpenSdk.AspNetCore --version 2.4.4
<PackageReference Include="MSDev.PddOpenSdk.AspNetCore" Version="2.4.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MSDev.PddOpenSdk.AspNetCore --version 2.4.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MSDev.PddOpenSdk.AspNetCore, 2.4.4"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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=2.4.4

// Install MSDev.PddOpenSdk.AspNetCore as a Cake Tool
#tool nuget:?package=MSDev.PddOpenSdk.AspNetCore&version=2.4.4
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": "",
    "RedirectUri": "",
    "SocketUrl": "",
    // 心跳间隔
    "HeartBeatSeconds": 5
}
  • 然后在控制器使用注入服务
readonly PddService _pdd;
public YourController(PddService pdd)
{
    _pdd = pdd;
}
2.2.0及以后版本
/// <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);
}
使用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值,会覆盖配置中的值。
2.1.0及以前版本
  • 获取 AccessToken
/// <summary>
/// 测试获取token
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public async Task<IActionResult> Callback(string code)
{
    var token = await _pdd.AuthApi.GetAccessTokenAsync(code);
    // 自行维护Token过期时间
    return Content(token.AccessToken);
}
  • 调用其他接口

    获取 AccessToken 之后才能正常调用其他接口。

public async Task<ActionResult> Test()
{
    // 构造请求模型
    var requestModel = new SearchDdkGoodsRequestModel
    {
        SortType = 0,
        WithCoupon = false
    };
    // 调用相应接口方法
    var result = await _pdd.DdkApi.SearchDdkGoodsAsync(requestModel);
    return Content(JsonConvert.SerializeObject(result));
}

所有方法名与官方文档保持一致,并有中文注释提醒,只是更改了命名规范,非常容易查找使用。

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
2.4.4 153 9/26/2021
2.4.3 113 8/11/2021
2.4.2 126 7/19/2021
2.4.1 125 7/19/2021
2.4.0 201 7/19/2021
2.3.5 195 7/15/2021
2.3.4 199 7/12/2021
2.3.3 179 6/21/2021
2.3.2 207 6/21/2021
2.3.1 139 6/9/2021
2.3.0 139 4/26/2021
2.3.0-beta 109 2/25/2021
2.2.0-beta 153 12/14/2020
2.1.0 223 10/15/2020
2.0.0 314 9/14/2020
1.1.9 345 10/8/2019
1.1.7 282 7/15/2019
1.1.6 340 5/29/2019
1.1.5 316 5/12/2019
1.1.4 325 4/7/2019
1.0.4 322 3/12/2019
1.0.2 318 2/25/2019
1.0.0 431 1/10/2019
0.2.0 415 11/12/2018
0.1.1 4,892 9/30/2018
0.1.0-CI-20180929-054251 428 9/29/2018
0.0.1 466 9/27/2018

拼多多SDK ASP.NET Core依赖包
更新同步到最新(202109)!