參考文檔
http://www.wtbis.cn/doc/workerman/components/workerman-http-client.html
協(xié)程用法
協(xié)程用法需要workerman>=5.0,workerman/http-client>=2.0.0 并安裝 composer require revolt/event-loop
public static function request($cmd, $postData)
{
foreach ($postData as $index => $postDatum) {
if ($postDatum == '') {
unset($postData[$index]);
}
}
$reqBean = [
'orgId' => config('pay.tq.appid'),
'reqData' => $postData,
'reqId' => session_create_id(),
'signType' => 'RSA',
'timestamp' => date('ymdHis', time()),
'version' => '1.0',
];
$sign = self::generateSign($reqBean);
$reqBean['sign'] = $sign;
$client = new Client();
try {
$apiUrl = config('pay.tq.api') . $cmd;
$response = $client->post($apiUrl, $reqBean);
if ($response->getStatusCode() !== 200) {
debug_log('狀態(tài)不對', $reqBean, $response->getStatusCode(), 'tq');
throw new BusinessException('EQT-ServerStatus響應(yīng)錯誤');
}
$content = json_decode($response->getBody()->getContents(), true);
if ($content['bizCode'] !== '0000') {
debug_log($cmd, $reqBean, $content, 'tq');
throw new BusinessException($cmd . '@' . $content['bizMsg']);
}
return $content;
} catch (\Throwable $e) {
debug_log($cmd, $reqBean, $e->getMessage(), 'tq');
throw new BusinessException($e->getMessage());
}
}
Call to a member function getStatusCode() on null
debian12 和 windows11/10都試了
在config/process.php
加一句
$worker->eventLoop = \Workerman\Events\Fiber::class;
Fatal error: [Fatal error in R8] Cannot declare class Workerman\Coroutine, because the name is already in use
Stack trace: