Skip to content

Commit

Permalink
Merge pull request #41 from RunsTp/master
Browse files Browse the repository at this point in the history
🐛 #40 修复微信生成二维码中传入的参数不生效问题。
  • Loading branch information
RunsTp authored Feb 22, 2020
2 parents 89f5b8a + 54ee0c2 commit 7284f2e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"require": {
"php": ">=7.1.0",
"ext-json": "*",
"ext-swoole": "^4.4.6",
"easyswoole/component": ">=1.0",
"easyswoole/spl": "^1.1",
Expand Down
28 changes: 28 additions & 0 deletions src/Bean/OfficialAccount/QrCodeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
7 changes: 5 additions & 2 deletions src/OfficialAccount/QrCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 7284f2e

Please sign in to comment.