You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
2.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
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
*/
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();
// 定义请求方法为POST
$queryAction = 'POST';
// 初始化模板数组
$template = array();
// 设置主行业ID
$template['industry_id1'] = "$industryId1";
// 设置副行业ID
$template['industry_id2'] = "$industryId2";
// 将模板数组转换为JSON格式
$template = json_encode($template);
// 调用Curl类的方法发送请求并获取结果
return Curl::callWebServer($queryUrl, $template, $queryAction);
}
}
类声明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并返回结果。