企业微信开发笔记

接收消息与事件

企业互联回调事件

企业内部开发

通讯录管理

部门管理

注意:此处 $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'];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

罐装面包

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值