Skip to content

Commit

Permalink
fix exception error
Browse files Browse the repository at this point in the history
  • Loading branch information
DoveChen committed Jul 15, 2020
1 parent 43d091a commit 6f95d9b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 7 additions & 4 deletions components/BaseWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,11 @@ protected function _HttpCall ($url, $method = "GET", $args = [], $refreshTokenWh
* @param $url
* @param bool $refreshTokenWhenExpired
*
* @return \http|mixed
* @return bool|\http|string
*
* @throws \HttpError
* @throws \NetWorkError
* @throws \QyApiError
*/
protected function _HttpGetParseToJson ($url, $refreshTokenWhenExpired = true)
{
Expand Down Expand Up @@ -438,7 +439,7 @@ protected function _HttpGetParseToJson ($url, $refreshTokenWhenExpired = true)
$this->repRawStr = HttpUtils::httpGet($realUrl);

if (!Utils::notEmptyStr($this->repRawStr))
throw new QyApiError("empty response");
throw new \QyApiError("empty response");

$this->repJson = json_decode($this->repRawStr, true);
if (strpos($this->repRawStr, "errcode") !== false) {
Expand Down Expand Up @@ -475,6 +476,7 @@ protected function _HttpGetParseToJson ($url, $refreshTokenWhenExpired = true)
*
* @throws \HttpError
* @throws \NetWorkError
* @throws \QyApiError
*/
protected function _HttpPostParseToJson ($url, $args, $refreshTokenWhenExpired = true, $isPostFile = false)
{
Expand Down Expand Up @@ -511,7 +513,7 @@ protected function _HttpPostParseToJson ($url, $args, $refreshTokenWhenExpired =
$this->repRawStr = HttpUtils::httpPost($realUrl, $postData);

if (!Utils::notEmptyStr($this->repRawStr))
throw new QyApiError("empty response");
throw new \QyApiError("empty response");

$json = json_decode($this->repRawStr, true/*to array*/);
$this->repJson = $json;
Expand Down Expand Up @@ -539,6 +541,7 @@ protected function _HttpPostParseToJson ($url, $args, $refreshTokenWhenExpired =
}

/**
* @throws \ParameterError
* @throws \QyApiError
*/
protected function _CheckErrCode ()
Expand All @@ -549,7 +552,7 @@ protected function _CheckErrCode ()
return;

if (!is_array($rsp))
throw new ParameterError("invalid type " . gettype($rsp));
throw new \ParameterError("invalid type " . gettype($rsp));
if (!array_key_exists("errcode", $rsp)) {
return;
}
Expand Down
17 changes: 16 additions & 1 deletion src/dataStructure/ExternalContactMsgTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @property string $template_id 欢迎语素材id
* @property array $external_userid 客户的外部联系人id列表,不可与sender同时为空,最多可传入1万个客户
* @property string $sender 发送企业群发消息的成员userid,不可与external_userid同时为空
* @property string $chat_type 群发任务的类型,默认为single,表示发送给客户,group表示发送给客户群
* @property array $text 消息文本
* @property array $image 图片
* @property array $link 图文
Expand Down Expand Up @@ -39,6 +40,11 @@ public static function parseFromArray ($arr)
$template->external_userid = $templateExternalUserid;
}

$templateTemplateId = Utils::arrayGet($arr, 'template_id');
if (!is_null($templateTemplateId)) {
$template->template_id = $templateTemplateId;
}

$templateText = Utils::arrayGet($arr, 'text');
if (!is_null($templateText)) {
$template->text = ExternalContactMsgTemplateText::parseFromArray($templateText);
Expand All @@ -59,6 +65,15 @@ public static function parseFromArray ($arr)
$template->miniprogram = ExternalContactMsgTemplateMiniprogram::parseFromArray($templateMini);
}

$sender = Utils::arrayGet($arr, 'sender');
if (!is_null($sender)) {
$template->sender = $sender;
}

$chat_type = Utils::arrayGet($arr, 'chat_type');
if (!is_null($chat_type)) {
$template->chat_type = $chat_type;
}
return $template;
}

Expand All @@ -70,7 +85,7 @@ public static function parseFromArray ($arr)
*/
public static function checkMsgTemplateAddArgs ($msgTemplate)
{
if (!Utils::notEmptyArray($msgTemplate->external_userid) && !Utils::notEmptyArray($msgTemplate->sender)) {
if (!Utils::notEmptyArray($msgTemplate->external_userid) && !Utils::notEmptyStr($msgTemplate->sender)) {
throw new \ParameterError('input error paramter.');
}

Expand Down

0 comments on commit 6f95d9b

Please sign in to comment.