12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace App\Service;
- use App\Log;
- use App\Models\CustomerDetails;
- class ExternalContactService
- {
- /**
- * 获取外部联系人信息详情
- * @param $corpid string 授权方企业微信id
- * @param $externalUserid string 外部联系人的userid
- * @param $cursor string 上次请求返回的next_cursor,用于分页请求(见官方文档)
- * @param $retry integer 重试次数,默认为0
- * */
- public static function getExternalContactDetail($corpid, $externalUserid, $cursor=null, $retry=0)
- {
- # 获取SuiteAccessToken
- $accessToken = AccessTokenService::getAccessToken($corpid, '获取外部联系人信息详情');
- if(empty($accessToken)) { // 令牌获取失败,发送报警
- Log::logError('【获取外部联系人信息详情】令牌获取失败', [
- 'corpid' => $corpid,
- 'externalUserId' => $externalUserid,
- 'cursor' => $cursor,
- 'retry' => $retry,
- 'access_token' => $accessToken
- ], 'GetExternalContactDetail');
- return false;
- }
- # 获取外部联系人详情信息API
- $getExternalContactUri = config('qyWechat.external_contact_detail');
- $getExternalContactUri .= $accessToken . '&external_userid=' . $externalUserid;
- if($cursor) {
- $getExternalContactUri .= '&cursor=' . $cursor;
- }
- $response = HttpService::httpGet($getExternalContactUri);
- $responseData = json_decode($response, true);
- if(isset($responseData['errcode']) && $responseData['errcode']) {
- if($retry <=5 && $responseData['errcode'] == -1) {
- $retry++;
- return ExternalContactService::getExternalContactDetail($corpid, $externalUserid, $cursor, $retry);
- }
- Log::logError('获取外部联系人详情信息返回错误码', [
- 'response' => $response
- ], 'ExternalContactDetailGet');
- return [];
- }
- return $responseData;
- }
- }
|