Bladeren bron

!1024 增加公众号和小程序消息服务器配置
Merge pull request !1024 from KaneLeung/next

zuohuaijun 2 jaren geleden
bovenliggende
commit
3de32326e2

+ 5 - 1
Admin.NET/Admin.NET.Application/Configuration/Wechat.json

@@ -5,9 +5,13 @@
     // 公众号
     "WechatAppId": "",
     "WechatAppSecret": "",
+    "WechatToken": "", //微信公众号服务器配置中的令牌(Token)
+    "WechatEncodingAESKey": "", //微信公众号服务器配置中的消息加解密密钥(EncodingAESKey)
     // 小程序
     "WxOpenAppId": "",
-    "WxOpenAppSecret": ""
+    "WxOpenAppSecret": "",
+    "WxToken": "", //小程序消息推送中的令牌(Token)
+    "WxEncodingAESKey": "" //小程序消息推送中的消息加解密密钥(EncodingAESKey)
   },
   // 微信支付
   "WechatPay": {

+ 26 - 6
Admin.NET/Admin.NET.Core/Option/WechatOptions.cs

@@ -13,13 +13,33 @@ namespace Admin.NET.Core;
 /// </summary>
 public sealed class WechatOptions : IConfigurableOptions
 {
-    //公众号
-    public string WechatAppId { get; set; }
+	//公众号
+	public string WechatAppId { get; set; }
 
-    public string WechatAppSecret { get; set; }
+	public string WechatAppSecret { get; set; }
 
-    //小程序
-    public string WxOpenAppId { get; set; }
+	/// <summary>
+	/// 微信公众号服务器配置中的令牌(Token)
+	/// </summary>
+	public string WechatToken { get; set; }
 
-    public string WxOpenAppSecret { get; set; }
+	/// <summary>
+	/// 微信公众号服务器配置中的消息加解密密钥(EncodingAESKey)
+	/// </summary>
+	public string WechatEncodingAESKey { get; set; }
+
+	//小程序
+	public string WxOpenAppId { get; set; }
+
+	public string WxOpenAppSecret { get; set; }
+
+	/// <summary>
+	/// 小程序消息推送中的令牌(Token)
+	/// </summary>
+	public string WxToken { get; set; }
+
+	/// <summary>
+	/// 小程序消息推送中的消息加解密密钥(EncodingAESKey)
+	/// </summary>
+	public string WxEncodingAESKey { get; set; }
 }

+ 6 - 2
Admin.NET/Admin.NET.Core/Service/Wechat/WechatApiHttpClient.cs

@@ -37,6 +37,8 @@ public partial class WechatApiClientFactory : ISingleton
         {
             AppId = _wechatOptions.WechatAppId,
             AppSecret = _wechatOptions.WechatAppSecret,
+            PushToken = _wechatOptions.WechatToken,
+            PushEncodingAESKey = _wechatOptions.WechatEncodingAESKey,
         })
             .UseHttpClient(_httpClientFactory.CreateClient(), disposeClient: false) // 设置 HttpClient 不随客户端一同销毁
             .Build();
@@ -64,8 +66,10 @@ public partial class WechatApiClientFactory : ISingleton
         var client = WechatApiClientBuilder.Create(new WechatApiClientOptions()
         {
             AppId = _wechatOptions.WxOpenAppId,
-            AppSecret = _wechatOptions.WxOpenAppSecret
-        })
+            AppSecret = _wechatOptions.WxOpenAppSecret,
+			PushToken = _wechatOptions.WxToken,
+			PushEncodingAESKey = _wechatOptions.WxEncodingAESKey,
+		})
         .UseHttpClient(_httpClientFactory.CreateClient(), disposeClient: false) // 设置 HttpClient 不随客户端一同销毁
         .Build();