企业内部开发
通讯录管理
部门管理
注意:此处 $id 允许为 0,表示获取可见的部门
/**
* 部门列表
* https://open.work.weixin.qq.com/api/doc/90000/90135/90208
*
* @param int $branch_id
* @param int $id
* @return array
*/
public static function listDepartment($branch_id, $id = 0)
{
$access_token = self::getAccessToken($branch_id);
if (!$access_token) {
return [];
}
$query_string = http_build_query([
'access_token' => $access_token,
'id' => $id
]);
$url = "https://qyapi.weixin.qq.com/cgi-bin/department/list?{$query_string}";
$response = json_decode(file_get_contents($url), true);
if ($response['errcode'] != 0) {
return [];
}
return $response['department'];
}
消息推送
发送应用消息
注意:url 可以不传,表示点击图文不跳转
/**
* 发送图文消息
* https://open.work.weixin.qq.com/api/doc/90000/90135/90236#%E5%9B%BE%E6%96%87%E6%B6%88%E6%81%AF
* @param $branch_id
* @param $options
* @return string
*/
public static function sendImageText($branch_id, $options)
{
$access_token = self::getAccessToken($branch_id);
$branch = Branch::getById($branch_id);
$data = [
'touser' => $options['touser'],
'toparty' => $options['toparty'],
'totag' => $options['totag'],
'msgtype' => 'news',
'agentid' => $branch['agentid'],
'news' => [
'articles' => [
[
'title' => $options['title'],
'description' => $options['description'],
'url' => $options['url'],
'picurl' => $options['picurl'],
'appid' => $options['appid'],
'pagepath' => $options['pagepath']
]
]
],
'enable_id_trans' => $options["enable_id_trans"] ? 1 : 0,
'enable_duplicate_check' => $options["enable_duplicate_check"] ? 1 : 0,
'duplicate_check_interval' => $options["duplicate_check_interval"] ?: 1800
];
$qs = http_build_query([
'access_token' => $access_token
]);
$url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?{$qs}";
return httpRequestJson($url, $data);
}
家校沟通
部门管理
- 获取部门列表
注意:此处 $part_id
不可以传 0,或者不传,或者传有效值。传 0 将得到全部架构。
/**
* 获取学校部门
* https://work.weixin.qq.com/api/doc/90000/90135/92343
* @param int $branch_id
* @param int $part_id
* @return array | false
*/
public static function listSchoolDepartment($branch_id, $part_id)
{
$access_token = self::getAccessToken($branch_id);
if (!$access_token) {
return false;
}
$params = [
'access_token' => $access_token
];
if ($part_id) {
$params['id'] = $part_id;
}
$query_string = http_build_query($params);
$url = "https://qyapi.weixin.qq.com/cgi-bin/school/department/list?{$query_string}";
$response = json_decode(file_get_contents($url), true);
if ($response['errcode'] != 0) {
return false;
}
return $response['departments'];
}