overtrue / easy-sms

📲 一款满足你的多种发送需求的短信发送组件
MIT License
3.13k stars 545 forks source link

难道没人发现GuzzleHttp\Client的超时时间不正确吗 #204

Closed nullforyou closed 5 years ago

nullforyou commented 5 years ago

本想着怎么改来着,后来看了部分代码,EasySms与Messenger之间的调度问题,确实存在硬伤,在不修改库源码的情况下,只能在每个服务提供者配置中添加超时时间

overtrue commented 5 years ago

麻烦详细描述问题以减少交流成本,谢谢

nullforyou commented 5 years ago

类Overtrue\EasySms\EasySms实例化时,设置的参数中有timeout,该类中方法send执行信差(Messenger)的send方法时,只传传递了短信提供者的网关配置,代码如下: `public function send($to, $message, array $gateways = []) { $to = $this->formatPhoneNumber($to); $message = $this->formatMessage($message); $gateways = empty($gateways) ? $message->getGateways() : $gateways;

    if (empty($gateways)) {
        $gateways = $this->config->get('default.gateways', []);
    }

    return $this->getMessenger()->send($to, $message, $this->formatGateways($gateways));
}`

在具体短信商(例如Overtrue\EasySms\Gateways\AliyunGateway)在创建http客户端时,获取的当前类中的属性timeout,但是这个timeout属性,并没有在任何地方赋值。 http客户端发出请求代码Overtrue\EasySms\Traits\HasHttpRequest `protected function request($method, $endpoint, $options = []) { return $this->unwrapResponse($this->getHttpClient($this->getBaseOptions())->{$method}($endpoint, $options)); } protected function getBaseOptions() { $options = [ 'base_uri' => method_exists($this, 'getBaseUri') ? $this->getBaseUri() : '', 'timeout' => method_exists($this, 'getTimeout') ? $this->getTimeout() : 5.0, ];

    return $options;
}`中,timeout并未赋值而得到5.0;