// Import necessary namespaces using System.Net.Http; using System.Text; using System.Threading.Tasks; // Define a method to send a message to the WeChat group public async Task SendMessageToWeChatGroup(string message) { // Define the WeChat group webhook URL string weChatGroupWebhookUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOUR_KEY_HERE"; // Define the message payload string payload = "{\"msgtype\": \"text\", \"text\": {\"content\": \"" + message + "\"}}"; // Create a new HTTP client using (HttpClient client = new HttpClient()) { // Create a new StringContent object with the message payload StringContent content = new StringContent(payload, Encoding.UTF8, "application/json"); // Send a POST request to the WeChat group webhook URL with the message payload HttpResponseMessage response = await client.PostAsync(weChatGroupWebhookUrl, content); // Check if the response was successful if (response.IsSuccessStatusCode) { // Log a success message Console.WriteLine("Message sent successfully to WeChat group!"); } else { // Log an error message Console.WriteLine("Error sending message to WeChat group: " + response.StatusCode); } } }
学无止境 未来已来
标签:group,AI,代码,Cursor,WeChat,using,new,message,payload From: https://www.cnblogs.com/dayang12525/p/17286869.html