Skip to content

Commit

Permalink
add new error_code and external batch get by user
Browse files Browse the repository at this point in the history
  • Loading branch information
DoveChen committed Dec 22, 2020
1 parent 769991c commit fa928d9
Show file tree
Hide file tree
Showing 4 changed files with 695 additions and 430 deletions.
17 changes: 16 additions & 1 deletion Work.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use dovechen\yii2\weWork\src\dataStructure\BatchJobArgs;
use dovechen\yii2\weWork\src\dataStructure\Department;
use dovechen\yii2\weWork\src\dataStructure\ExternalContact;
use dovechen\yii2\weWork\src\dataStructure\ExternalContactBatchGetByUser;
use dovechen\yii2\weWork\src\dataStructure\ExternalContactBehavior;
use dovechen\yii2\weWork\src\dataStructure\ExternalContactGroupChat;
use dovechen\yii2\weWork\src\dataStructure\ExternalContactMsgTemplate;
Expand Down Expand Up @@ -581,6 +582,20 @@ public function ECGet ($externalUserId)
return ExternalContact::parseFromArray($externalContact);
}

public function ECBatchGetByUser (ExternalContactBatchGetByUser $batchGetByUser)
{
ExternalContactBatchGetByUser::CheckExternalContactBatchGetByUserArgs($batchGetByUser);
$args = Utils::Object2EmptyArray($batchGetByUser);
self::_HttpCall(self::EXTERNAL_CONTACT_BATCH_GET_BY_USER, 'POST', $args);

$externalContactListInfo = [
'external_contact_list' => Utils::arrayGet($this->repJson, 'external_contact_list'),
'next_cursor' => Utils::arrayGet($this->repJson, 'next_cursor')
];

return $externalContactListInfo;
}

public function ECRemark (ExternalContactRemark $externalContactRemark)
{
ExternalContactRemark::CheckExternalContactRmarkArgs($externalContactRemark);
Expand Down Expand Up @@ -787,7 +802,7 @@ public function ECGroupChatTransfer ($chadIdList, $newOwner)
public function EContactGetTransferResult ($handoverData)
{
$args = Utils::Object2Array($handoverData);
self::_HttpCall(self::EXTERNAL_CONTACT_GET_TRANSFER_RESULT, 'POST',$args);
self::_HttpCall(self::EXTERNAL_CONTACT_GET_TRANSFER_RESULT, 'POST', $args);

return $this->repJson;
}
Expand Down
36 changes: 36 additions & 0 deletions components/BaseWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ abstract class BaseWork extends Component
/* 客户管理 */
const EXTERNAL_CONTACT_LIST = '/cgi-bin/externalcontact/list?access_token=ACCESS_TOKEN'; // 获取客户列表 GET
const EXTERNAL_CONTACT_GET = '/cgi-bin/externalcontact/get?access_token=ACCESS_TOKEN'; // 获取客户详情 GET
const EXTERNAL_CONTACT_BATCH_GET_BY_USER = '/cgi-bin/externalcontact/batch/get_by_user?access_token=ACCESS_TOKEN'; // 批量获取客户详情 POST
const EXTERNAL_CONTACT_REMARK = '/cgi-bin/externalcontact/remark?access_token=ACCESS_TOKEN'; // 修改客户备注信息 POST

/* 客户标签管理 */
Expand Down Expand Up @@ -463,6 +464,19 @@ protected function _HttpGetParseToJson ($url, $refreshTokenWhenExpired = true)
}
}

$save_path = '/work/' . date('Ymd') . '/';
$save_dir = \Yii::getAlias('@upload') . $save_path;
if (!file_exists($save_dir) && !mkdir($save_dir, 0755, true)) {
}

@file_put_contents($save_dir . 'work-api.txt', json_encode([
'time' => date('Y-m-d H:i'),
'errcode' => isset($this->repJson["errcode"]) ? $this->repJson["errcode"] : 0,
'realUrl' => $realUrl,
'method' => 'get',
'refreshTokenWhenExpired' => $refreshTokenWhenExpired,
], JSON_UNESCAPED_UNICODE) . "\n", FILE_APPEND);

return $this->repRawStr;
}
}
Expand Down Expand Up @@ -537,6 +551,21 @@ protected function _HttpPostParseToJson ($url, $args, $refreshTokenWhenExpired =
}
}

$save_path = '/work/' . date('Ymd') . '/';
$save_dir = \Yii::getAlias('@upload') . $save_path;
if (!file_exists($save_dir) && !mkdir($save_dir, 0755, true)) {
}

@file_put_contents($save_dir . 'work-api.txt', json_encode([
'time' => date('Y-m-d H:i'),
'errcode' => isset($this->repJson["errcode"]) ? $this->repJson["errcode"] : 0,
'realUrl' => $realUrl,
'method' => 'post',
'args' => $args,
'refreshTokenWhenExpired' => $refreshTokenWhenExpired,
'isPostFile' => $isPostFile,
], JSON_UNESCAPED_UNICODE) . "\n", FILE_APPEND);

return $json;
}
}
Expand All @@ -558,6 +587,13 @@ protected function _CheckErrCode ()
return;
}
$errCode = $rsp["errcode"];
$errInfo = errorCode::getErrorInfo($errCode);

if (!is_null($errInfo)) {
$raw = json_decode($raw, true);
$raw['errmsg'] = $errInfo;
$raw = json_encode($raw, JSON_UNESCAPED_UNICODE);
}
if (!is_int($errCode))
throw new \QyApiError(
"invalid errcode type " . gettype($errCode) . ":" . $raw);
Expand Down
Loading

0 comments on commit fa928d9

Please sign in to comment.