Skip to content

Commit

Permalink
Update examples.md (#2851)
Browse files Browse the repository at this point in the history
  • Loading branch information
pengxuxu authored Oct 16, 2024
1 parent c81d8dd commit 976c602
Showing 1 changed file with 51 additions and 4 deletions.
55 changes: 51 additions & 4 deletions docs/src/6.x/official-account/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,56 @@ class OfficialAccount

</details>

<!--

<details>
<summary>标题</summary>
内容
<summary>Hyperf 服务端验证消息</summary>

##### 方法一:
* 安装包,composer require limingxinleo/easywechat-classmap,
* 在授权回调地址中使用:
```php
<?php

namespace App\Controller;

use EasyWeChat\OfficialAccount\Application;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Psr\SimpleCache\CacheInterface;
use Hyperf\Context\ApplicationContext;

// 授权事件回调地址:http://easywechat.com/OfficialAccount/server

class OfficialAccountController
{
public function server(RequestInterface $request, ResponseInterface $response)
{
$app = new Application(config('wechat.defaults'));

if (method_exists($app, 'setRequest')) {
$app->setRequest($request); //必须替换服务端请求
}

if (method_exists($app, 'setCache')) {
$app->setCache(ApplicationContext::getContainer()->get(CacheInterface::class) //可选,根据实际需求替换缓存
}

$server = $app->getServer();

$server->with(function ($message, \Closure $next) {
return '谢谢关注!';

// 你的自定义逻辑
// return $next($message);
});

return $server->serve();
}
}
```

##### 方法二:
* 安装包,composer require pengxuxu/hyperf-easywechat6,包里已替换了服务端请求和缓存,并封装了公众号、微信支付、小程序等外观。
* 参照文档在授权回调地址和其他场景中直接使用。
</details>
-->

0 comments on commit 976c602

Please sign in to comment.