hyperf 接入 easywechat

easyweacht是基于fpm模式开发的

不能直接在hyperf或者其他的swoole框架中直接食用

//实例化公众号 小程序 支付同理
$app = Factory::officialAccount(config('officialAccount'));

$config = $app['config']->get('http', []);

$config['handler'] = di()->get(HandlerStackFactory::class)->create();

$app->rebind('http_client', new Client($config));

// 重写 Handler
$app['guzzle_handler'] = new CoroutineHandler();

AbstractProvider::setGuzzleOptions([
    'http_errors' => false,
    'handler' => HandlerStack::create(new CoroutineHandler())
]);
//重写缓存
$app['cache'] = di()->get(CacheInterface::class);
//获取回调通知
//可以直接修改easywehcat的request 或者直接使用hyperf的 request获取body自行解析xml
//重写easywechat的request
//        $get = $request->getQueryParams();
//
//        $post = $request->getParsedBody();
//
//        $cookie = $request->getCookieParams();
//
//        $files = $request->getUploadedFiles();
//
//        $server = $request->getServerParams();
//
//        $xml = $request->getBody()->getContents();
//
//        $app['request'] = new Request($get, $post, [], $cookie, $files, $server, $xml);
讨论数量: 2

Hyperf 官网有相关的文档,可以直接根据文档的方案来使用 https://www.hyperf.wiki/#/zh-cn/sdks/wecha...

4年前 评论
liapples 1年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!