【问题标题】:How send sms in php?如何在php中发送短信?
【发布时间】:2019-08-09 05:39:38
【问题描述】:

我该如何解决这个问题?我无法在我的工作上发送短信。

$ch = curl_init(); //curl()
$parameters = array(
  'apikey' => '8a6bb687750b59d8f099cb489b43c256', //Your API KEY
  'number' => '09096817174',//number
  'message' => 'I just sent my first message with Semaphore', //message
  'sendername' => 'SEMAPHORE');
curl_setopt( $ch, CURLOPT_URL,'https://semaphore.co/api/v4/messages');
curl_setopt( $ch, CURLOPT_POST, 1 );

//Send the parameters set above with the request
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $parameters ) );

我该如何解决这个问题?我在信号量中有我的 apikey。

【问题讨论】:

  • 根据文档,url应该是:https://api.semaphore.co/api/v4/messages,你缺少子域部分
  • 此代码在信号量中给出。
  • 你从返回响应中得到消息 id ?
  • 尝试打印响应并检查 $output = curl_exec( $ch ); curl_close ($ch); //显示服务器响应 echo $output;

标签: php sms semaphore


【解决方案1】:

嘿,我试过这段代码并打印输出

    <?php
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();

$ch = curl_init();
$parameters = array(
    'apikey' => '8a6bb687750b59d8f099cb489b43c256', //Your API KEY
    'number' => '0987654321',//for testing no 
    'message' => 'I just sent my first message with Semaphore',
    'sendername' => 'SEMAPHORE'
);
curl_setopt( $ch, CURLOPT_URL,'https://semaphore.co/api/v4/messages' );
curl_setopt( $ch, CURLOPT_POST, 1 );

//Send the parameters set above with the request
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $parameters ) );

// Receive response from server
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close ($ch);

//Show the server response

echo $output;

我得到了返回输出

"message_id":73840803,

"status":"Pending",

使用 live key 和 test 并尝试点击相同的代码检查状态等待接收

【讨论】:

  • 登录您的 SMS 网关面板并检查您收到的消息
  • 如果超过 1 个数字怎么办
  • 尝试使用群发短信和每个 no after ,例如 no1,no2,no3
  • while($event_cal=mysql_fetch_array($events_cal)){ $mobile=$event_cal['phone'].','; $receiver=$event_cal['receiver'].','; $ch = curl_init(); $parameters = array( 'apikey' => '8a6bb687750b59d8f099cb489b43c256', 'number' => $mobile, 'message' => 'PDI VMS: Hi '.$receiver.',我们想提醒您,您的更新单位建议最早支付 '.date('M-d-Y',strtotime($event_cal['date_end'])).'.."'", 'sendername' => 'SEMAPHORE' ); } {"number":["数字格式无效。"]}1
【解决方案2】:

这对我有用

 $ch = curl_init(); 
 $parameters = array(
          'apikey' => '8a6bb687750b59d8f099cb489b43c256', 
          'number' => '9000000000',
          'message' => 'I just sent my first message with Semaphore', 
          'sendername' => 'SEMAPHORE'
          );
curl_setopt( $ch, CURLOPT_URL,'https://semaphore.co/api/v4/messages' );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

//Send the parameters set above with the request
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $parameters ) );

$result = curl_exec($ch);
print_r($result);
if (curl_errno($ch)) {
    $error_msg = curl_error($ch);
    print_r($error_msg);
}
curl_close($ch);
exit;

【讨论】:

  • 如果超过 1 个数字怎么办。
  • 输入带逗号的手机号码
  • @Dharman 他发现,在测试服务器上他可以做到这一点,但在生产中他必须保持它。他可能因为测试服务器上的 ssl 而面临这个问题。
  • while($event_cal=mysql_fetch_array($events_cal)){ $mobile=$event_cal['phone'].','; $receiver=$event_cal['receiver'].','; $ch = curl_init(); $parameters = array( 'apikey' => '8a6bb687750b59d8f099cb489b43c256', 'number' => $mobile, 'message' => 'PDI VMS: Hi '.$receiver.', 我们想提醒您,您的更新单位建议最早支付 '.date('M-d-Y',strtotime($event_cal['date_end'])).'.."'", 'sendername' => 'SEMAPHORE' ); } {"number":["数字格式无效。"]}1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-17
  • 2023-03-27
  • 1970-01-01
  • 1970-01-01
  • 2020-09-04
  • 2022-01-19
  • 2011-02-03
相关资源
最近更新 更多