From f0bf887e538163e65101a4b9e2a165eb7694a90e Mon Sep 17 00:00:00 2001
From: sunpengfei <i@angelzzz.com>
Date: 星期五, 21 十一月 2025 16:08:49 +0800
Subject: [PATCH] feat:开发

---
 ApiTools.Core/Utils/WxmpUtils/WxmpUtils.cs |   54 +++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/ApiTools.Core/Utils/WxmpUtils/WxmpUtils.cs b/ApiTools.Core/Utils/WxmpUtils/WxmpUtils.cs
index cb686c5..864a1d8 100644
--- a/ApiTools.Core/Utils/WxmpUtils/WxmpUtils.cs
+++ b/ApiTools.Core/Utils/WxmpUtils/WxmpUtils.cs
@@ -130,19 +130,44 @@
         }
 
         /// <summary>
-        /// 璇ユ帴鍙g敤浜庡彂閫佽闃呮秷鎭�
+        /// 鏌ヨ璁㈤槄娑堟伅妯℃澘
         /// </summary>
         /// <param name="command"></param>
         /// <returns></returns>
-        public async Task<string> WxSend(SendRequest command)
+        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, "鑾峰彇灏忕▼搴忕爜澶辫触锛岀己澶遍厤缃細WxmpOptions");
-            command.EnvVersion = option.EnvVersion;
+                throw Oops.Oh(EnumErrorCodeType.s400, "鍙戦�佽闃呮秷鎭け璐ワ紝缂哄け閰嶇疆锛歐xmpOptions");
             var accessToken = await GetAccessToken(command.WxmpCode);
-            var request = command.Adapt<SendRequest>();
-            var jsonContent = JsonConvert.SerializeObject(request, new JsonSerializerSettings
+            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>
+        /// <returns></returns>
+        public async Task WxmpSendSubscribMessage(WxmpSendSubscribMessageRequest 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");
+            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
             {
                 NullValueHandling = NullValueHandling.Ignore
             });
@@ -151,22 +176,13 @@
                 .WithQueryParameter("access_token", accessToken)
                 .SetJsonContent(jsonContent));
             response.EnsureSuccessStatusCode();
-            //var a = response.Content.Headers.ContentType.ToString();
-            //application/json; encoding=utf-8
-            //if (response.Content.Headers.ContentType.ToString() == "application/json; charset=UTF-8")
-            if (response.Content.Headers.ContentType.ToString() == "application/json; encoding=utf-8")
+            if (response.Content.Headers.ContentType.ToString() == "application/json; charset=UTF-8")
             {
                 var jsonResult = await response.Content.ReadAsStringAsync();
-                //var callback = jsonResult.JsonTo<SendResponse>();
-                //if (callback == null || callback.ErrorCode != 0)
-                    //throw Oops.Oh(EnumErrorCodeType.s510, $"鑾峰彇灏忕▼搴忕爜澶辫触锛歿callback.errmsg}锛岃鑱旂郴绠$悊鍛�");
-                return jsonResult;
+                var callback = jsonResult.JsonTo<WxmpSendSubscribMessageResponse>();
+                if (callback == null || callback.ErrorCode != 0)
+                    throw Oops.Oh(EnumErrorCodeType.s510, $"鍙戦�佽闃呮秷鎭け璐ワ細{callback.ErrorMessage}锛岃鑱旂郴绠$悊鍛�");
             }
-            //var stream = await response.Content.ReadAsStreamAsync();
-            //var result = AliyunOSSUtils.Upload(command, stream, command.OssFileName);
-            return "";
         }
-
-
     }
 }

--
Gitblit v1.9.1