You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Twilio生产凭证购买号码时持续触发HTTP 400错误的问题

问题:Twilio生产环境购买号码时始终提示不可用,但控制台可正常购买

测试凭证下代码运行正常,但切换到生产凭证尝试购买号码时,持续触发错误:[HTTP 400] Unable to create record: +xxxxxxx is not available

获取可用号码的代码:

public function getAvailablePhoneNumbers(): array
{
    if ($this->useTestClient) {
        return [self::VALID_TEST_MAGIC_PHONE];
    }

    $numbers = $this->getClient()
        ->availablePhoneNumbers('US')
        ->local
        ->read([
            'smsEnabled' => true,
        ]);

    /* @var LocalInstance $number */
    return array_map(function ($number) {
        return $number->phoneNumber;
    }, $numbers);
}

购买号码的代码:

获取到phoneNumber列表后,会逐个尝试购买,失败则自动尝试下一个,但所有号码都触发相同错误:

public function purchaseNumber(string $number): \Twilio\Rest\Api\V2010\Account\IncomingPhoneNumber\LocalInstance
{
    return $this->getClient()
        ->incomingPhoneNumbers
        ->local
        ->create($number, [
            'SmsApplicationSid' => config('twilio.sms_app_sid'),
        ]);
}

补充说明:从日志里挑出一个被报错“不可用”的号码,在Twilio控制台中却能成功完成购买。

内容的提问来源于stack exchange,提问作者Angel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 15:13:35