Skip to content

nepton/WeChatApi

Repository files navigation

WeChatApi

Build status GitHub issues GitHub license

WeChat API is a dotnet library for WeChat API. It provides a simple way to use WeChat API.

Nuget packages

Name Version Downloads
WeChatApi.Abstractions nuget stats
WeChatApi.RestSharp nuget stats

Installing

Install the NuGet package from nuget.org

PM> Install-Package [WeChatApi.RestSharp]

Usage

In startup.cs, add the following code to configure services:

// add package WeChatApi.RestSharp
services.AddWeChatApi(options =>
{
    options.AppId     = "wx1234567890";
    options.AppSecret = "1234567890";
});

Then you can inject the client factory in your controllers:

public class HomeController : Controller
{
    private readonly IWeChatLoginApi _loginApi;
    private readonly WeChatApiOptions _options;
    
    public HomeController(IWeChatLoginApi loginApi, IOptions<WeChatApiOptions> options)
    {
        _loginApi = loginApi;
        _options = options.Value;    
    }

    public async Task<IActionResult> Index()
    {
        // call the API
        var token = await _loginApi.GetAccessTokenAsync(_options.AppId, _options.AppSecret);

        return View();
    }
}

Final

Leave a comment on GitHub if you have any questions or suggestions.

Turn on the star if you like this project.

License

This project is licensed under the MIT License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages