1. Go to this page and download the library: Download andphp/hyperf-easywechat6 library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
andphp / hyperf-easywechat6 example snippets
declare(strict_types=1);
namespace App\Controller;
use EasyWeChat\Kernel\HttpClient\RequestUtil;
use Symfony\Component\HttpClient\HttpClient as SymfonyClient;
class IndexController extends AbstractController
{
public function index()
{
$user = $this->request->input('user', 'Hyperf');
$method = $this->request->getMethod();
$client = SymfonyClient::create(RequestUtil::formatDefaultOptions([]));
go(function () use ($client) {
$client->request('GET', 'http://www.baidu.com/');
});
go(function () use ($client) {
$client->request('GET', 'http://www.baidu.com/');
});
return [
'method' => $method,
'message' => "Hello {$user}.",
];
}
}
在swoole>=4.7.0且开启native curl修改常量SWOOLE_HOOK_ALL,共用一个HttpClient情况下,报错信息:
PHP Fatal error: Uncaught Swoole\Error: cURL is executing, cannot be operated in /data/project/hyperf-skeleton/vendor/symfony/http-client/Response/CurlResponse.php:366
$app = new Application($config);
if (method_exists($app, 'setRequest')) {
$app->setRequest(ApplicationContext::getContainer()->get(\Hyperf\HttpServer\Contract\RequestInterface));
}
if (method_exists($app, 'setCache')) {
$app->setCache(ApplicationContext::getContainer()->get(\Psr\SimpleCache\CacheInterface::class)
}