12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace App\Service;
- use App\Log;
- use App\Models\AuthorizeCorp;
- class ChatService
- {
- /**
- * 同步客户和客服间的聊天记录
- * @param string $corpid 企业ID
- * @param string $token 回调事件返回的token字段,10分钟内有效;可不填,如果不填接口有严格的频率限制
- * @param int $limit 期望请求的数据量,不允许超过1000
- * @param int $voiceFormat 语音消息类型,0-Amr 1-Silk,默认0。可通过该参数控制返回的语音格式
- * */
- public static function syncChatMsg($corpid, $token, $limit=1000, $cursor=null, $voiceFormat=0)
- {
- # 获取SuiteAccessToken
- $accessToken = AuthorizeCorp::getAccessToken($corpid, '获取客户与客服聊天记录');
- if(empty($accessToken)) { // 令牌获取失败,发送报警
- Log::logError('【获取外部联系人信息详情】令牌获取失败', [
- 'corpid' => $corpid,
- 'token' => $token,
- 'cursor' => $cursor,
- 'limit' => $limit,
- 'voice_format' => $voiceFormat,
- 'access_token' => $accessToken
- ], 'SyncChatMsg');
- return false;
- }
- # 获取外部联系人详情信息API
- $requestUri = config('qyWechat.sync_chat_msg');
- $requestUri .= $accessToken;
- $postData = array(
- 'token' => $token,
- 'limit' => $limit,
- 'voice_format' => $voiceFormat
- );
- if($cursor) $postData['cursor'] = $cursor;
- Log::logInfo('请求参数:', $postData, '05-05Sync');
- $response = HttpService::httpPost($requestUri, json_encode($postData));
- $responseData = json_decode($response, true);
- Log::logInfo('响应结果:', $responseData, '05-05Sync');
- return $responseData;
- }
- }
|