Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples.md #2851

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
-->

Loading