Skip to content

[版本号:1.8]自定义代理器的同学注意下 #146

@abellee

Description

@abellee

如果你们做自定义代理器,要注意库里的代码有一处有问题,
Toplan\PhpSms\Sms.php289行开始
代码是:

if (!empty($options)) {
    self::$agents[$name] = new ParasiticAgent($config, $options);
} elseif (class_exists($className)) {
    self::$agents[$name] = new $className($config);
} else {
    throw new PhpSmsException("Not support agent `$name`.");
}

这样如果你在phpsms.php里的scheme里以数组的形式设置了你的自定义代理器并加了weight
比如

'scheme' => [
    App\agents\AAA\Agent::class => [
        '20',
        'agentClass' => App\Libs\AAA\Agent::class
    ],
    App\agents\BBB\Agent::class => [
        '10 backup',
        'agentClass' => App\Libs\BBB\Agent::class
    ]
]

那么这两个Agent经过那段代码后,就跑ParasiticAgent去了。
所以,要不就不要有weight,这样的后果 我不知道会不会造成没有权重的特性了,
我也没多看其它代码,就把elseif改了一下

if (!empty($options)) {
    self::$agents[$name] = new ParasiticAgent($config, $options);
} 
if (class_exists($className)) {
    self::$agents[$name] = new $className($config);
} else {
    throw new PhpSmsException("Not support agent `$name`.");
}

希望遇到同样问题的同学能看到,着实弄了我半天。醉了!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions