EasyWeChat调用企业微信接口获取客户群数据

use EasyWeChat\Factory;
use fast\Http;

       $config = [
            'corp_id' => Config::get('site.corp_id'),
            'agent_id' =>  Config::get('site.agend_id'), // 如果有 agend_id 则填写
            'secret'   => Config::get('site.agent_secret'),
            // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
            'response_type' => 'array',
            'log' => [
                'level' => 'debug',
                'file' => __DIR__.'/wechat.log',
            ],
        ];

        $app = Factory::work($config);
        // 获取 access token 实例
        $accessToken = $app->access_token;
        $access_token = $accessToken->getToken()['access_token']; // token 数组  token['access_token'] 字符串
        $url = 'https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/list?access_token='.$access_token;
        $res = Http::post($url, json_encode(['limit'=>1000]));
        $res = json_decode($res,true);

//得到如下数据并转成了数组形式
{
	"errcode": 0,
	"errmsg": "ok",
	"group_chat_list": [{
		"chat_id": "wrOgQhDgAAMYQiS5ol9G7gK9JVAAAA",
		"status": 0
	}, {
		"chat_id": "wrOgQhDgAAcwMTB7YmDkbeBsAAAA",
		"status": 0
	}],
	"next_cursor":"tJzlB9tdqfh-g7i_J-ehOz_TWcd7dSKa39_AqCIeMFw"
}

EasyWeChat对企业微信的再开发比较少,本方案是用EasyWeChat维护accessToken,接口的请求自己来。接口的请求使用了FastAdmin封装的Http类。

其他接口类似,阅读疼腾讯的文档传参即可。

你可能感兴趣的:(企业微信)