【问题标题】:nexmo sms api is not workingnexmo 短信 API 不工作
【发布时间】:2017-05-07 17:50:09
【问题描述】:
$url = 'https://rest.nexmo.com/sms/json?' . http_build_query(
              [
                'api_key' =>  'xxxxx',
                'api_secret' => 'xxxxxxx',
                'to' => $mobile,
                'from' => 'ABC',
                'text' => $message,
              ]
              ); 
              $ch = curl_init($url);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
              $response = curl_exec($ch);

此 api 不工作且未显示任何错误。我只使用此代码发送短信还需要其他任何东西吗? 我使用了 api_key 和 secret 正确。

【问题讨论】:

    标签: php laravel api sms


    【解决方案1】:

    假设您在 使用之前检查了 $mobile 和 $message 的值并且它们没问题

    编辑:error_reporting(E_ALL); ini_set('display_errors', 1); 在您的页面顶部并检查更新的代码

    编辑 2:

    使用您的注册电话号码和试用 API使用注册号码作为 dest 这是为了避免垃圾邮件

    你需要把$mobile$message这样写:

    error_reporting(E_ALL); ini_set('display_errors', 1);
    print_r($_POST);
    echo"[ num: $mobile / mess: $message]";
    
    $url = 'https://rest.nexmo.com/sms/json?' . http_build_query(
    
    [
      'api_key' =>  'xxxxx',
      'api_secret' => 'xxxxxx',
      'to' => ''.$mobile.'', /* dest phone number */
      'from' => '33012345678', /* my own phone number */
      'text' => ''.$message.'' /* my message */
    ]
    );
    

    NEXMO API how-to

    【讨论】:

    • "https://rest.nexmo.com/sms/json?api_key=xxxxx&api_secret=xxx&to=91xxxx871472&from=ABC&text=Hi.+Your+OTP+is%3A+3A55NP"
    • 使用您自己的凭据?在您的页面顶部添加error_reporting(E_ALL); ini_set('display_errors', 1); 并查看PHP 是否说了什么(仅供参考:在我这边运行顺利...)
    • 我正在使用试用 api 所以必须输入from = valid_no??
    • 使用您的注册号码和试用 API 并且使用注册号码作为 dest(请参阅更新的答案)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-27
    • 2017-06-23
    • 1970-01-01
    相关资源
    最近更新 更多