From 54ee0c2dca1908fcfc539afdeec4fb9f289fcb2f Mon Sep 17 00:00:00 2001 From: "hongbei.huang" Date: Sat, 22 Feb 2020 12:57:24 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20#40=20=E4=BF=AE=E5=A4=8D=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E7=94=9F=E6=88=90=E4=BA=8C=E7=BB=B4=E7=A0=81=E4=B8=AD?= =?UTF-8?q?=E4=BC=A0=E5=85=A5=E7=9A=84=E5=8F=82=E6=95=B0=E4=B8=8D=E7=94=9F?= =?UTF-8?q?=E6=95=88=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 1 + src/Bean/OfficialAccount/QrCodeRequest.php | 28 ++++++++++++++++++++++ src/OfficialAccount/QrCode.php | 7 ++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index dae339e..1f6c18a 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ ], "require": { "php": ">=7.1.0", + "ext-json": "*", "ext-swoole": "^4.4.6", "easyswoole/component": ">=1.0", "easyswoole/spl": "^1.1", diff --git a/src/Bean/OfficialAccount/QrCodeRequest.php b/src/Bean/OfficialAccount/QrCodeRequest.php index a715829..a87d962 100644 --- a/src/Bean/OfficialAccount/QrCodeRequest.php +++ b/src/Bean/OfficialAccount/QrCodeRequest.php @@ -103,4 +103,32 @@ public function setSceneStr($scene_str): void { $this->scene_str = $scene_str; } + + /** + * @return array + */ + public function buildRequest(): array + { + if (is_string($this->getActionInfo())) { + $this->action_info = json_decode($this->action_info, true); + } + + if (!is_null($this->getActionInfo())) { + return parent::toArray(['action_name', 'action_info']); + } + + $scene = []; + if (!is_null($this->getSceneId())) { + $scene['scene_id'] = (int)$this->getSceneId(); + } + + if (!is_null($this->getSceneStr())) { + $scene['scene_str'] = (string)$this->getSceneStr(); + } + + $this->action_info = [ + 'scene' => $scene + ]; + return parent::toArray(['action_name', 'action_info']); + } } \ No newline at end of file diff --git a/src/OfficialAccount/QrCode.php b/src/OfficialAccount/QrCode.php index 4451487..6374b2c 100644 --- a/src/OfficialAccount/QrCode.php +++ b/src/OfficialAccount/QrCode.php @@ -8,9 +8,11 @@ namespace EasySwoole\WeChat\OfficialAccount; +use EasySwoole\HttpClient\Exception\InvalidUrl; use EasySwoole\WeChat\Bean\OfficialAccount\QrCodeRequest; use EasySwoole\WeChat\Bean\OfficialAccount\QrCode as QrCodeBean; use EasySwoole\WeChat\Exception\OfficialAccountError; +use EasySwoole\WeChat\Exception\RequestError; use EasySwoole\WeChat\Utility\NetWork; class QrCode extends OfficialAccountBase @@ -20,14 +22,15 @@ class QrCode extends OfficialAccountBase * @param QrCodeRequest $codeRequest * @return QrCodeBean|null * @throws OfficialAccountError - * @throws \EasySwoole\WeChat\Exception\RequestError + * @throws InvalidUrl + * @throws RequestError */ function getTick(QrCodeRequest $codeRequest): ?QrCodeBean { $token = $this->getOfficialAccount()->accessToken()->getToken(); $response = NetWork::postJsonForJson(ApiUrl::generateURL(ApiUrl::QRCODE_CREATE, [ 'ACCESS_TOKEN' => $token - ]), $codeRequest->toArray()); + ]), $codeRequest->buildRequest()); $ex = OfficialAccountError::hasException($response); if ($ex) {