From 7b529c7fca8681ed338a784936a838dbbee67a16 Mon Sep 17 00:00:00 2001 From: pfspx4a7z <2942132918@qq.com> Date: Wed, 8 Jan 2025 20:08:22 +0800 Subject: [PATCH] Update autoreply.lib.php --- core/autoreply.lib.php | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/core/autoreply.lib.php b/core/autoreply.lib.php index 3ca2027..4ec0c4c 100644 --- a/core/autoreply.lib.php +++ b/core/autoreply.lib.php @@ -5,24 +5,38 @@ namespace LaneWeChat\Core; * 这个类用于处理微信公众号的自动回复功能。 */ class AutoReply{ - /** + /** * 获取自动回复规则 * 这个函数用于从微信公众号的API获取当前的自动回复规则。 * * @param int $industryId1 主行业ID * @param int $industryId2 副行业ID * @return String 返回结果与字段说明请查看微信公众平台文档 - * http://mp.weixin.qq.com/wiki/7/7b5789bb1262fb866d01b4b40b0efecb.html + * http://mp.weixin.qq.com/wiki/7/7b5789bb1262fb866d01b4b40b0efecb.html */ public static function getRole($industryId1, $industryId2){ - // 构建请求URL,这里需要替换'access_token'为实际的access_token值 - $queryUrl = 'https://api.weixin.qq.com/cgi-bin/get_current_autoreply_info?access_token=' . AccessToken::getAccessToken(); + // 构建请求URL,这里需要替换'access_token'为实际的access_token值 + $queryUrl = 'https://api.weixin.qq.com/cgi-bin/get_current_autoreply_info?access_token=' . AccessToken::getAccessToken(); // 定义请求方法为POST $queryAction = 'POST'; - $template = array();// 初始化模板数组 - $template['industry_id1'] = "$industryId1"; // 设置主行业ID - $template['industry_id2'] = "$industryId2";// 设置副行业ID - $template = json_encode($template);// 将模板数组转换为JSON格式 - return Curl::callWebServer($queryUrl, $template, $queryAction);// 调用Curl类的方法发送请求并获取结果 + // 初始化模板数组 + $template = array(); + // 设置主行业ID + $template['industry_id1'] = "$industryId1"; + // 设置副行业ID + $template['industry_id2'] = "$industryId2"; + // 将模板数组转换为JSON格式 + $template = json_encode($template); + // 调用Curl类的方法发送请求并获取结果 + return Curl::callWebServer($queryUrl, $template, $queryAction); } -} \ No newline at end of file +} +类声明:class AutoReply 定义了一个名为 AutoReply 的类,用于处理微信公众号的自动回复功能。 +方法声明:public static function getRole($industryId1, $industryId2) 定义了一个静态方法 getRole,用于获取自动回复规则。该方法接受两个参数:主行业ID ($industryId1) 和副行业ID ($industryId2)。 +构建请求URL:$queryUrl = 'https://api.weixin.qq.com/cgi-bin/get_current_autoreply_info?access_token=' . AccessToken::getAccessToken(); 构建请求微信API的URL,使用 AccessToken::getAccessToken() 方法获取 access_token 并拼接到URL中。 +定义请求方法:$queryAction = 'POST'; 设置请求方法为POST。 +初始化模板数组:$template = array(); 创建一个空数组用于存储请求数据。 +设置主行业ID:$template['industry_id1'] = "$industryId1"; 将主行业ID添加到模板数组中。 +设置副行业ID:$template['industry_id2'] = "$industryId2"; 将副行业ID添加到模板数组中。 +转换为JSON格式:$template = json_encode($template); 将模板数组转换为JSON字符串,以便发送给微信API。 +发送请求并获取结果:return Curl::callWebServer($queryUrl, $template, $queryAction); 使用 Curl::callWebServer 方法发送POST请求到微信API,并返回结果。 \ No newline at end of file