mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-03 20:27:59 +08:00
Update wechat.md (#790)
This commit is contained in:
parent
0d10dda04d
commit
d6e66f87af
@ -51,3 +51,46 @@ AbstractProvider::setGuzzleOptions([
|
|||||||
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL | SWOOLE_HOOK_CURL);
|
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL | SWOOLE_HOOK_CURL);
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 如何使用 EasyWeChat
|
||||||
|
|
||||||
|
`EasyWeChat` 是为 `PHP-FPM` 架构设计的,所以在某些地方需要修改下才能在 Hyperf 下使用。下面我们以支付回调为例进行讲解。
|
||||||
|
|
||||||
|
1. `EasyWeChat` 中自带了 `XML` 解析,所以我们获取到原始 `XML` 即可。
|
||||||
|
|
||||||
|
```php
|
||||||
|
$xml = $this->request->getBody()->getContents();
|
||||||
|
```
|
||||||
|
|
||||||
|
2. 将 XML 数据放到 `EasyWeChat` 的 `Request` 中。
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
$get = $this->request->getQueryParams();
|
||||||
|
$post = $this->request->getParsedBody();
|
||||||
|
$cookie = $this->request->getCookieParams();
|
||||||
|
$files = $this->request->getUploadedFiles();
|
||||||
|
$server = $this->request->getServerParams();
|
||||||
|
$xml = $this->request->getBody()->getContents();
|
||||||
|
|
||||||
|
$app['request'] = new Request($get,$post,[],$cookie,$files,$server,$xml);
|
||||||
|
|
||||||
|
// Do something...
|
||||||
|
```
|
||||||
|
|
||||||
|
## 如何替换缓存
|
||||||
|
|
||||||
|
`EasyWeChat` 默认使用 `文件缓存`,而现实场景是 `Redis` 缓存居多,所以这里可以替换成 `Hyperf` 提供的 `hyperf/cache` 缓存组件,如您当前没有安装该组件,请执行 `composer require hyperf/cache` 引入,使用示例如下:
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
use Hyperf\Cache\CacheInterface;
|
||||||
|
use Hyperf\Utils\ApplicationContext;
|
||||||
|
use EasyWeChat\Factory;
|
||||||
|
|
||||||
|
$app = Factory::miniProgram([]);
|
||||||
|
$app['cache'] = ApplicationContext::getContainer()->get(CacheInterface::class);
|
||||||
|
|
||||||
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user