{"id":28818,"date":"2024-11-25T15:13:42","date_gmt":"2024-11-25T07:13:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28818\/"},"modified":"2024-11-25T15:13:42","modified_gmt":"2024-11-25T07:13:42","slug":"%e5%be%ae%e4%bf%a1%e5%bc%80%e5%8f%91%e4%b9%8b%e5%be%ae%e4%bf%a1%e5%8f%91%e9%80%81%e6%b6%88%e6%81%af","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28818\/","title":{"rendered":"\u5fae\u4fe1\u5f00\u53d1\u4e4b\u5fae\u4fe1\u53d1\u9001\u6d88\u606f"},"content":{"rendered":"<p>\u672c\u5185\u5bb9\u4e3a\u5fae\u4fe1\u5f00\u53d1\u4e4b\u5fae\u4fe1\u53d1\u9001\u6d88\u606f&nbsp;<\/p>\n<p>1\uff0c\u9996\u5148\uff0c\u83b7\u53d6\u5f00\u53d1\u8005\u6d4b\u8bd5\u8d26\u53f7\uff08\u7533\u8bf7\uff09\uff0c\u4f1a\u6839\u636e\u5f53\u524d\u626b\u7801\u63d0\u4f9b\u7684\u8d26\u53f7\u751f\u6210\u6d4b\u8bd5\u8d26\u53f7\uff1a \u94fe\u63a5\u5730\u5740\uff1ahttp:\/\/mp.weixin.qq.com\/wiki\/home\/index.html<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/013\/4ab828914b31c3bb585fa79a1dc2e57b-0.png\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5f00\u53d1\u4e4b\u5fae\u4fe1\u53d1\u9001\u6d88\u606f\u63d2\u56fe\" alt=\"\u5fae\u4fe1\u5f00\u53d1\u4e4b\u5fae\u4fe1\u53d1\u9001\u6d88\u606f\u63d2\u56fe\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u3000\u3000\u8fd9\u65f6\u5019\u53ef\u4ee5\u83b7\u53d6\u5230\u6d4b\u8bd5\u7528\u7684appid\u548cappsecrept,\u7136\u540e\u8c03\u7528\u83b7\u53d6\u63a5\u53e3\u8c03\u7528\u51ed\u8bc1 \u63a5\u53e3\u83b7\u53d6access_token\uff1b<\/p>\n<p>2\uff0c\u4e0b\u9762\u8bf4\u4fe1\u606f\u53d1\u9001\uff0c\u6a21\u62df\u4e86\u5355\u7528\u6237\u4fe1\u606f\u53d1\u9001\u548c\u591a\u7528\u6237\u6d88\u606f\u6279\u91cf\u53d1\u9001<\/p>\n<p>\u3000\u3000\uff081\uff09\u57fa\u7840\u65b9\u6cd5\uff0chttp\u65b9\u6cd5\u3000\u3000\u3000\u3000<\/p>\n<\/p>\n<pre>\/\/\/ &lt;summary&gt;\r\n        \/\/\/      http  get\/post \u516c\u7528\u65b9\u6cd5\r\n        \/\/\/ &lt;\/summary&gt;\r\n        \/\/\/ &lt;param name=\"requestUrl\"&gt;\u8bf7\u6c42\u94fe\u63a5&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=\"requestJsonParams\"&gt;\u8bf7\u6c42\u53c2\u6570\u503c\uff08\u5982\u679c\u662fget\u65b9\u5f0f\u6b64\u5904\u4e3a\u201c\u201d\u503c,\u9ed8\u8ba4\u4e3a \"\"\uff09&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=\"requestMethod\"&gt;\u8bf7\u6c42\u65b9\u5f0f  post or get&lt;\/param&gt;\r\n        \/\/\/ &lt;returns&gt;&lt;\/returns&gt;\r\n        public static string Request(this string requestUrl, string requestMethod, string requestJsonParams = \"\")\r\n        {\r\n            string returnText = \"\";\r\n            StreamReader streamReader = null;\r\n            HttpWebRequest request = null;\r\n            HttpWebResponse response = null;\r\n\r\n            Encoding encoding = Encoding.UTF8;\r\n            request = (HttpWebRequest)WebRequest.Create(requestUrl);\r\n            request.Method = requestMethod;\r\n            if (!string.IsNullOrEmpty(requestJsonParams) &amp;&amp; requestMethod.ToLower() == \"post\")\r\n            {\r\n                byte[] buffer = encoding.GetBytes(requestJsonParams);\r\n                request.ContentLength = buffer.Length;\r\n                request.GetRequestStream().Write(buffer, 0, buffer.Length);\r\n            }\r\n\r\n            try\r\n            {\r\n                response = (HttpWebResponse)request.GetResponse();\r\n                using (streamReader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding(\"gb2312\")))\/\/utf-8\r\n                {\r\n                    returnText = streamReader.ReadToEnd();\r\n                }\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                returnText = ex.Message;\r\n            }\r\n\r\n            return returnText;\r\n        }<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\uff082\uff09\u6a21\u62df\u53d1\u9001\uff1a\u3000\u3000<\/p>\n<\/p>\n<pre>\/\/\/ &lt;summary&gt;\r\n        \/\/\/     \u53d1\u9001\u5fae\u4fe1\u4fe1\u606f(\u5355\u7528\u6237\u53d1\u9001)\r\n        \/\/\/ &lt;\/summary&gt;\r\n        \/\/\/ &lt;param name=\"access_token\"&gt;\u6388\u6743\u7801\uff08\u5fae\u4fe1token\uff09&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=\"messageInfo\"&gt;\u53d1\u9001\u4fe1\u606f\u6a21\u578b&lt;\/param&gt;\r\n        \/\/\/ &lt;returns&gt;&lt;\/returns&gt;\r\n        public static string SendSingleMessage(WeChatParamEntity messageInfo, string access_token)\r\n        {\r\n            messageInfo.MsgType = string.IsNullOrEmpty(messageInfo.MsgType) ? \"text\" : messageInfo.MsgType;\r\n            string jsonDataParams = messageInfo == null ? \"\" : JsonConvert.SerializeObject(new\r\n            {\r\n                touser = messageInfo.ToUser,\r\n                msgtype = messageInfo.MsgType,\r\n                text = new { content = messageInfo.Text }\r\n            });\r\n            string requestUrl = string.Format(Consts.URL_POSTSINGLETEXTMESSAGE, access_token);\r\n            return requestUrl.Request(\"POST\", jsonDataParams);\r\n        }\r\n        \/\/\/ &lt;summary&gt;\r\n        \/\/\/     \u53d1\u9001\u5fae\u4fe1\u4fe1\u606f\uff08\u591a\u7528\u6237\u6279\u91cf\u53d1\u9001\uff09\r\n        \/\/\/ &lt;\/summary&gt;\r\n        \/\/\/ &lt;param name=\"access_token\"&gt;\u6388\u6743\u7801\uff08\u5fae\u4fe1token\uff09&lt;\/param&gt;\r\n        \/\/\/ &lt;param name=\"messageInfo\"&gt;\u53d1\u9001\u4fe1\u606f\u6a21\u578b&lt;\/param&gt;\r\n        \/\/\/ &lt;returns&gt;&lt;\/returns&gt;\r\n        public static string SendMessages(WeChatParamsEntity messageInfo, string access_token)\r\n        {\r\n            messageInfo.MsgType = string.IsNullOrEmpty(messageInfo.MsgType) ? \"text\" : messageInfo.MsgType;\r\n            string jsonDataParams = messageInfo == null ? \"\" : JsonConvert.SerializeObject(new\r\n            {\r\n                touser = messageInfo.ToUser,\r\n                msgtype = messageInfo.MsgType,\r\n                text = new { content = messageInfo.Text }\r\n            });\r\n            string requestUrl = string.Format(Consts.URL_POSTTEXTMESSAGES, access_token);\r\n            return requestUrl.Request(\"POST\", jsonDataParams);\r\n        }<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u3000\u3000\uff083\uff09\u4e24\u4e2a\u53c2\u6570 \u6a21\u578b\uff1a\u3000<\/p>\n<\/p>\n<pre>\/\/\/ &lt;summary&gt;\r\n    \/\/\/     \u5fae\u4fe1 \u53d1\u9001\u4fe1\u606f \u53c2\u6570\u5b9e\u4f53\u6a21\u578b\r\n    \/\/\/ &lt;\/summary&gt;\r\n    public class WeChatParamEntity\r\n    {\r\n        \/\/\/ &lt;summary&gt;\r\n        \/\/\/     \u666e\u901a\u7528\u6237openid\r\n        \/\/\/ &lt;\/summary&gt;\r\n        public string ToUser { get; set; }\r\n        \/\/\/ &lt;summary&gt;\r\n        \/\/\/     \u4f20\u8f93\u7684\u6587\u4ef6\u7c7b\u578b\uff08text,image, and so on\uff09\r\n        \/\/\/ &lt;\/summary&gt;\r\n        public string MsgType { get; set; } = \"text\";\r\n        \/\/\/ &lt;summary&gt;\r\n        \/\/\/     \u4f20\u8f93\u6587\u672c\u5185\u5bb9\r\n        \/\/\/ &lt;\/summary&gt;\r\n        public string Text { get; set; }\r\n\r\n    }\r\n\r\n    \/\/\/ &lt;summary&gt;\r\n    \/\/\/     \u5fae\u4fe1 \u53d1\u9001\u4fe1\u606f \u53c2\u6570\u5b9e\u4f53\u6a21\u578b\r\n    \/\/\/ &lt;\/summary&gt;\r\n    public class WeChatParamsEntity\r\n    {\r\n        \/\/\/ &lt;summary&gt;\r\n        \/\/\/     \u666e\u901a\u7528\u6237openid\r\n        \/\/\/ &lt;\/summary&gt;\r\n        public string[] ToUser { get; set; }\r\n        \/\/\/ &lt;summary&gt;\r\n        \/\/\/     \u4f20\u8f93\u7684\u6587\u4ef6\u7c7b\u578b\uff08text,image, and so on\uff09\r\n        \/\/\/ &lt;\/summary&gt;\r\n        public string MsgType { get; set; } = \"text\";\r\n        \/\/\/ &lt;summary&gt;\r\n        \/\/\/     \u4f20\u8f93\u6587\u672c\u5185\u5bb9\r\n        \/\/\/ &lt;\/summary&gt;\r\n        public string Text { get; set; }\r\n\r\n    }<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>&nbsp;\u3000\u3000\uff084\uff09web.config\u4e2d\u7684\u94fe\u63a5<\/p>\n<p>\u3000\u3000<\/p>\n<\/p>\n<pre>&lt;!--\u5fae\u4fe1\u63a5\u53e3--&gt;\r\n\r\n    &lt;add key=\"appid\" value=\"wx123456789021\"\/&gt;\r\n    &lt;add key=\"appSecret\" value=\"adasdsadasdasdsadasdsaqweqw\"\/&gt;\r\n    &lt;add key=\"getAccessTokenUrl\" value=\"https:\/\/api.weixin.qq.com\/cgi-bin\/token?grant_type=client_credential&amp;appid={0}&amp;secret={1}\"\/&gt;\r\n    &lt;!--\u5355\u7528\u6237\u4fe1\u606f\u53d1\u9001--&gt;\r\n    &lt;add key=\"postSingleTextMessageUrl\" value=\"https:\/\/api.weixin.qq.com\/cgi-bin\/message\/custom\/send?access_token={0}\"\/&gt;\r\n    &lt;!--\u591a\u7528\u6237\u6279\u91cf\u53d1\u9001--&gt;\r\n    &lt;add key=\"postTextMessagesUrl\" value=\"https:\/\/api.weixin.qq.com\/cgi-bin\/message\/mass\/send?access_token={0}\"\/&gt;\r\n    &lt;!--\u5fae\u4fe1\u63a5\u53e3--&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>&nbsp;3\uff0c\u6d4b\u8bd5\u4f7f\u7528\u6d89\u53ca\u5230 &nbsp;touser\u7684\u8fd9\u4e2a\u53c2\u6570\uff0c\u8fd9\u4e2a\u662f\u9700\u8981\u53d1\u9001\u7684\u5bf9\u8c61\u7684 &nbsp;openID,\u8fd9\u4e2a\u5f88\u7b80\u5355\uff0c\u5728\u5f00\u53d1\u8005\u6587\u6863\uff08\u4e5f\u5c31\u662f\u4e0a\u9762\u7684\u6b65\u9aa4\u4e8c\u4e2d\uff0c\uff09\u83b7\u53d6<\/p>\n<p>appid &nbsp;\u548cappsecrept\u7684\u65f6\u5019\uff0c\u5f53\u524d\u8fd9\u4e2a\u9875\u9762\u4e0b\u9762\u6709\u4e00\u4e2a\u4e8c\u7ef4\u7801\uff0c\u627e\u51e0\u4e2a\u4eba\u7528\u5fae\u4fe1\u626b\u626b\u5c31\u53ef\u4ee5\u81ea\u52a8\u83b7\u53d6openID ,\u8fd9\u65f6\u5019\u5c06\u53c2\u6570\u5e26\u5165\u811a\u672c\u6a21\u62df<\/p>\n<p>post\u5373\u53ef<\/p>\n<p>\u3000\u3000\u53e6\u5916\u9700\u8981\u6ce8\u610f:\u6587\u6863\u4e2d\u63d0\u793a\u7684 &nbsp;json \u53c2\u6570\u683c\u5f0f<\/p>\n<p>\u3000\u3000\u6ce8\u610f\u4e09\uff1atoken\u6709\u6548\u65f6\u95f4\u4e3a7200\uff0c\u4fe9\u5c0f\u65f6\uff0c\u9700\u8981\u5224\u65ad\u5f53\u524d\u53d1\u9001\u4fe1\u606f\u7528\u6237\u7684token\u6709\u6548\u6027\uff0c\u540c\u65f6\u6bcf\u5929\u6700\u5927\u53ef\u8bf7\u6c42\u6b21\u6570\u4e3a2000.<\/p>\n<p>\u83b7\u53d6token :<\/p>\n<\/p>\n<pre>#region \u83b7\u53d6token\uff0c\u5e76\u9a8c\u8bc1token\u8fc7\u671f\u65f6\u95f4\r\n\r\n        public static string GetAccessToken(string appid, string appSecret)\r\n        {\r\n            string token = \"\";\r\n            string requestUrl = string.Format(ConfigBLL.URL_GETACCESSTOKEN, appid, appSecret);\r\n            string requestResult = WebAPITransfer.Request(requestUrl, \"GET\", \"\");\r\n\r\n            CommonBLL.DebugLog(requestResult, \"AccessToken-token-Params\");\r\n            string[] strArray = requestResult.Split(',');\r\n            token = strArray[0].Split(':')[1].Replace(\"\"\", \"\");\r\n\r\n            return token;\r\n        }\r\n\r\n        #endregion<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5f00\u53d1\u4e4b\u5fae\u4fe1\u53d1\u9001\u6d88\u606f \u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u5185\u5bb9\u4e3a\u5fae\u4fe1\u5f00\u53d1\u4e4b\u5fae\u4fe1\u53d1\u9001\u6d88\u606f&nbsp; 1\uff0c\u9996\u5148\uff0c\u83b7\u53d6\u5f00\u53d1\u8005\u6d4b\u8bd5\u8d26\u53f7\uff08\u7533\u8bf7\uff09\uff0c\u4f1a\u6839\u636e\u5f53\u524d\u626b\u7801\u63d0\u4f9b\u7684\u8d26\u53f7\u751f\u6210\u6d4b\u8bd5\u8d26\u53f7\uff1a \u94fe\u63a5\u5730\u5740\uff1ahttp:\/\/mp.weixin.qq.com\/wiki\/home\/index.html &nbsp; \u3000\u3000\u8fd9\u65f6\u5019\u53ef\u4ee5\u83b7\u53d6\u5230\u6d4b\u8bd5\u7528\u7684appid\u548cappsecrept,\u7136\u540e\u8c03\u7528\u83b7\u53d6\u63a5\u53e3\u8c03\u7528\u51ed\u8bc1 \u63a5\u53e3\u83b7\u53d6access_token\uff1b 2\uff0c\u4e0b\u9762\u8bf4\u4fe1\u606f\u53d1\u9001\uff0c\u6a21\u62df\u4e86\u5355\u7528\u6237\u4fe1\u606f\u53d1\u9001\u548c\u591a\u7528\u6237\u6d88\u606f\u6279\u91cf\u53d1\u9001 \u3000\u3000\uff081\uff09\u57fa\u7840\u65b9\u6cd5\uff0chttp\u65b9\u6cd5\u3000\u3000\u3000\u3000 \/\/\/ &lt;summary&gt; \/\/\/ http get\/post \u516c\u7528\u65b9\u6cd5 \/\/\/ &lt;\/summary&gt; \/\/\/ &lt;param name=&#8221;requestUrl&#8221;&gt;\u8bf7\u6c42\u94fe\u63a5&lt;\/param&gt; \/\/\/ &lt;param name=&#8221;requestJsonParams&#8221;&gt;\u8bf7\u6c42\u53c2\u6570\u503c\uff08\u5982\u679c\u662fget\u65b9\u5f0f\u6b64\u5904\u4e3a\u201c\u201d\u503c,\u9ed8\u8ba4\u4e3a &#8220;&#8221;\uff09&lt;\/param&gt; \/\/\/ &lt;param name=&#8221;requestMethod&#8221;&gt;\u8bf7\u6c42\u65b9\u5f0f post or get&lt;\/param&gt; \/\/\/ &lt;returns&gt;&lt;\/returns&gt; public static string Request(this string requestUrl, string requestMethod, string requestJsonParams = &#8220;&#8221;) { string returnText = &#8220;&#8221;; StreamReader streamReader = null; HttpWebRequest request = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-28818","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=28818"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28818\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}