diff --git a/src/MiniProgram/AppCode/Client.php b/src/MiniProgram/AppCode/Client.php new file mode 100644 index 0000000..84cd2f8 --- /dev/null +++ b/src/MiniProgram/AppCode/Client.php @@ -0,0 +1,77 @@ + $path, + ], $optional); + + return $this->getStream('/wxa/getwxacode', $params); + } + + /** + * @param string $scene + * @param array $optional + * @return StreamResponseInterface + * @throws \EasySwoole\WeChat\Kernel\Exceptions\HttpException + */ + public function getUnLimit(string $scene, array $optional = []) + { + $params = array_merge([ + 'scene' => $scene, + ], $optional); + + return $this->getStream('/wxa/getwxacodeunlimit', $params); + } + + /** + * @param string $path + * @param int|null $width + * @return StreamResponseInterface + * @throws \EasySwoole\WeChat\Kernel\Exceptions\HttpException + */ + public function getQrCode(string $path, int $width = null) + { + return $this->getStream('/cgi-bin/wxaapp/createwxaqrcode', compact('path', 'width')); + } + + /** + * @param string $endpoint + * @param array $params + * @return StreamResponse + * @throws \EasySwoole\WeChat\Kernel\Exceptions\HttpException + */ + protected function getStream(string $endpoint, array $params) + { + $response = $this->getClient() + ->setMethod('POST') + ->setBody($this->jsonDataToStream($params)) + ->send($this->buildUrl( + $endpoint, + ['access_token' => $this->app[ServiceProviders::AccessToken]->getToken()]) + ); + + if (false !== stripos($response->getHeaderLine('Content-disposition'), 'attachment')) { + return new StreamResponse($response->getBody()); + } + + $this->checkResponse($response); + } +} diff --git a/src/MiniProgram/AppCode/ServiceProvider.php b/src/MiniProgram/AppCode/ServiceProvider.php new file mode 100644 index 0000000..8209664 --- /dev/null +++ b/src/MiniProgram/AppCode/ServiceProvider.php @@ -0,0 +1,21 @@ +