31 lines
992 B
C#
31 lines
992 B
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using System.Net.Http;
|
|
|
|
namespace Hncore.Wx.Open
|
|
{
|
|
public static class WxApiExt
|
|
{
|
|
|
|
public static void AddWxApi(this IServiceCollection services)
|
|
{
|
|
services.AddHttpClient("WxOpen", client =>
|
|
{
|
|
client.BaseAddress = new Uri("https://api.weixin.qq.com/");
|
|
client.Timeout = TimeSpan.FromSeconds(10);
|
|
});
|
|
}
|
|
|
|
public static void UseWxApi(this IApplicationBuilder app)
|
|
{
|
|
var serviceProvider = app.ApplicationServices;
|
|
var configuration = serviceProvider.GetService<IConfiguration>();
|
|
var httpFactory = serviceProvider.GetService<IHttpClientFactory>();
|
|
WxOpenApi.Init(configuration, httpFactory);
|
|
TemplateApi.Init(httpFactory);
|
|
}
|
|
}
|
|
}
|