-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e355a59
commit 726a168
Showing
8 changed files
with
133 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Version>0.0.2</Version> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<Authors>雪雁</Authors> | ||
<Company>Magicodes</Company> | ||
<Product>麦扣</Product> | ||
<PackageProjectUrl>https://docs.xin-lai.com/</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/xin-lai/Magicodes.Wx.Sdk</RepositoryUrl> | ||
<PackageTags>WeChat Sdk;Wx Sdk;Public Account;Magicodes</PackageTags> | ||
<Description> | ||
最简洁最易于使用的微信Sdk,包括公众号Sdk、小程序Sdk、企业微信Sdk等,以及Abp VNext集成。 | ||
开源库地址:https://github.com/xin-lai | ||
博客地址:http://www.cnblogs.com/codelove/ | ||
公众号:麦扣聊技术 | ||
交流QQ群:85318032 | ||
|
||
</Description> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile> | ||
</PropertyGroup> | ||
</Project> |
14 changes: 14 additions & 0 deletions
14
src/Magicodes.Wx.PublicAccount.Sdk.Abp/Magicodes.Wx.PublicAccount.Sdk.Abp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="..\..\common.props"></Import> | ||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Volo.Abp.Autofac" Version="4.1.1" /> | ||
<PackageReference Include="Volo.Abp.AspNetCore" Version="4.1.1" /> | ||
<PackageReference Include="Volo.Abp.Caching" Version="4.1.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Magicodes.Wx.PublicAccount.Sdk\Magicodes.Wx.PublicAccount.Sdk.csproj" /> | ||
</ItemGroup> | ||
</Project> |
64 changes: 64 additions & 0 deletions
64
src/Magicodes.Wx.PublicAccount.Sdk.Abp/WxPublicAccountSdkModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
using Volo.Abp; | ||
using Volo.Abp.Caching; | ||
using Volo.Abp.Modularity; | ||
using Volo.Abp.Settings; | ||
|
||
namespace Magicodes.Wx.PublicAccount.Sdk.Abp | ||
{ | ||
public class WxPublicAccountSdkModule : AbpModule | ||
{ | ||
public override void ConfigureServices(ServiceConfigurationContext context) | ||
{ | ||
context.Services.AddMagicodesWeChatSdk(); | ||
} | ||
|
||
public override void OnApplicationInitialization(ApplicationInitializationContext context) | ||
{ | ||
var app = context.GetApplicationBuilder(); | ||
var cache = context.ServiceProvider.GetRequiredService<IDistributedCache<string>>(); | ||
|
||
app.UseMagicodesWeChatSdk(setup => | ||
{ | ||
if (setup.GetWeChatOptions == null) | ||
{ | ||
setup.GetWeChatOptions = () => | ||
{ | ||
var settingProvider = app.ApplicationServices.GetRequiredService<ISettingProvider>(); | ||
var appId = settingProvider.GetOrNullAsync("Wx.AppId").GetAwaiter().GetResult(); | ||
if (!string.IsNullOrEmpty(appId)) | ||
{ | ||
var appSecret = settingProvider.GetOrNullAsync("Wx.AppSecret").GetAwaiter().GetResult(); | ||
var token = settingProvider.GetOrNullAsync("Wx.Token").GetAwaiter().GetResult(); | ||
var weiXinAccount = settingProvider.GetOrNullAsync("Wx.WeiXinAccount").GetAwaiter().GetResult(); | ||
return new WeChatOptions() | ||
{ | ||
AppId = appId, | ||
AppSecret = appSecret, | ||
Token = token, | ||
WeiXinAccount = weiXinAccount, | ||
}; | ||
} | ||
else | ||
{ | ||
IConfiguration config = app.ApplicationServices.GetRequiredService<IConfiguration>(); | ||
return WeChatHelper.GetWeChatOptionsByConfiguration(config); | ||
} | ||
}; | ||
} | ||
setup.GetAccessTokenByAppId = (appid) => cache.Get($"AssessToken::{appid}"); | ||
|
||
setup.CacheAccessToken = (appid, token) => | ||
{ | ||
cache.Set($"AssessToken::{appid}", token, new Microsoft.Extensions.Caching.Distributed.DistributedCacheEntryOptions() | ||
{ | ||
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(115) | ||
}); | ||
}; | ||
}); | ||
|
||
} | ||
} | ||
} |
8 changes: 1 addition & 7 deletions
8
src/Magicodes.Wx.PublicAccount.Sdk.AspNet/Magicodes.Wx.PublicAccount.Sdk.AspNet.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 1 addition & 7 deletions
8
src/Magicodes.Wx.PublicAccount.Sdk/Magicodes.Wx.PublicAccount.Sdk.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters