123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- /**
- * Created by:PhpStorm
- * Author:chenzhiyuan
- * Date: 2022/5/31
- * Time: 11:34 上午
- */
- namespace App\Support\qyApi;
- use App\Service\HttpService;
- use App\Log;
- use App\Models\AuthorizeCorp;
- use App\RedisModel;
- class QyReport
- {
- /**
- * 获取员工联系客户的会话统计数据
- * 文档地址:https://developer.work.weixin.qq.com/document/path/92275
- * 规则:查询跨度最大30天,最多统计180天内的数据
- * @param $corpid
- * @param $userid
- * @param $start_time
- * @param $end_time
- */
- public static function customer_conversation_report($corpid, $userid, $start_time, $end_time, $retry = 0){
- $accessToken = AuthorizeCorp::getAccessToken($corpid, '获取联系客户统计数据');
- if(empty($accessToken)) {
- Log::logError('获取联系客户统计数据 参数:'.json_encode(['corpid' => $corpid, 'user_id' => $userid,'start_time'=>$start_time,'end_time'=>$end_time]),
- ['errmsg' => '令牌获取失败'], 'qyWechat');
- return false;
- }
- $postData = [
- 'userid' => [$userid],
- 'start_time' => strtotime($start_time),
- 'end_time' => strtotime($end_time),
- ];
- $requestUri = config('qyWechat.user_conversation_report');
- $requestUri .= $accessToken;
- $response = HttpService::httpPost($requestUri, json_encode($postData));
- if(false === $response && $retry < 5) {
- sleep(1);
- $retry++;
- return self::customer_conversation_report($corpid, $userid, $start_time, $end_time, $retry);
- }
- $responseData = json_decode($response, true);
- Log::logInfo('获取联系客户统计数据', [
- 'params' => ['corpid' => $corpid, 'user_id' => $userid,'start_time'=>$start_time,'end_time'=>$end_time],
- 'response' => $responseData
- ], 'qyWechat');
- if(isset($responseData['errcode']) && -1 == $responseData['errcode'] && $retry<5) {
- sleep(1);
- $retry++;
- return self::customer_conversation_report($corpid, $userid, $start_time, $end_time, $retry);
- }
- return $responseData;
- }
- }
|