From c87d61d03b48a6f55c0a0819b9be522f77e3c9a0 Mon Sep 17 00:00:00 2001
From: sunpengfei <i@angelzzz.com>
Date: 星期一, 01 十二月 2025 14:48:40 +0800
Subject: [PATCH] feat:开发

---
 ApiTools.Core/Utils/WxmpUtils/WxmpUtils.cs |   39 +++++++++++++++++++++++++++------------
 1 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/ApiTools.Core/Utils/WxmpUtils/WxmpUtils.cs b/ApiTools.Core/Utils/WxmpUtils/WxmpUtils.cs
index ee4d5cc..5dcf926 100644
--- a/ApiTools.Core/Utils/WxmpUtils/WxmpUtils.cs
+++ b/ApiTools.Core/Utils/WxmpUtils/WxmpUtils.cs
@@ -130,6 +130,27 @@
         }
 
         /// <summary>
+        /// 鏌ヨ璁㈤槄娑堟伅妯℃澘
+        /// </summary>
+        /// <param name="command"></param>
+        /// <returns></returns>
+        public async Task<GetWxmpSubscribMessageTemplatesResponse> GetWxmpSubscribMessageTemplate(GetWxmpSubscribMessageTemplatesRequest command)
+        {
+            var option = options.Value.Items.FirstOrDefault(it => it.Code == command.WxmpCode);
+            if (option == null || option.AppId.IsNull() || option.AppSecret.IsNull())
+                throw Oops.Oh(EnumErrorCodeType.s400, "鍙戦�佽闃呮秷鎭け璐ワ紝缂哄け閰嶇疆锛歐xmpOptions");
+            var accessToken = await GetAccessToken(command.WxmpCode);
+            var jsonContent = JsonConvert.SerializeObject(command, new JsonSerializerSettings
+            {
+                NullValueHandling = NullValueHandling.Ignore
+            });
+            var response = await httpRemoteService.GetAsAsync<GetWxmpSubscribMessageTemplatesResponse>(
+                "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate",
+                builder => builder.WithQueryParameter("access_token", accessToken));
+            return response;
+        }
+
+        /// <summary>
         /// 鍙戦�佽闃呮秷鎭�
         /// </summary>
         /// <param name="command"></param>
@@ -140,11 +161,6 @@
             if (option == null || option.AppId.IsNull() || option.AppSecret.IsNull())
                 throw Oops.Oh(EnumErrorCodeType.s400, "鍙戦�佽闃呮秷鎭け璐ワ紝缂哄け閰嶇疆锛歐xmpOptions");
             command.EnvVersion = option.EnvVersion;
-            if (!options.Value.SubscribMessageTemplates.ContainsKey(command.TemplateId))
-                throw Oops.Oh(EnumErrorCodeType.s400, "鍙戦�佽闃呮秷鎭け璐ワ紝妯℃澘涓嶅瓨鍦�");
-            var template = options.Value.SubscribMessageTemplates[command.TemplateId];
-            command.TemplateId = template.TemplateId;
-            if (command.Page.IsNull()) command.Page = template.Page;
             var accessToken = await GetAccessToken(command.WxmpCode);
             var jsonContent = JsonConvert.SerializeObject(command, new JsonSerializerSettings
             {
@@ -155,13 +171,12 @@
                 .WithQueryParameter("access_token", accessToken)
                 .SetJsonContent(jsonContent));
             response.EnsureSuccessStatusCode();
-            if (response.Content.Headers.ContentType.ToString() == "application/json; charset=UTF-8")
-            {
-                var jsonResult = await response.Content.ReadAsStringAsync();
-                var callback = jsonResult.JsonTo<WxmpSendSubscribMessageResponse>();
-                if (callback == null || callback.ErrorCode != 0)
-                    throw Oops.Oh(EnumErrorCodeType.s510, $"鍙戦�佽闃呮秷鎭け璐ワ細{callback.ErrorMessage}锛岃鑱旂郴绠$悊鍛�");
-            }
+            var jsonResult = await response.Content.ReadAsStringAsync();
+            var callback = jsonResult.JsonTo<WxmpSendSubscribMessageResponse>();
+            if (callback == null || callback.ErrorCode != 0)
+                throw Oops.Oh(EnumErrorCodeType.s510, $"鍙戦�佽闃呮秷鎭け璐ワ細{callback.ErrorMessage}锛岃鑱旂郴绠$悊鍛�");
         }
+
+
     }
 }

--
Gitblit v1.9.1