首页 > 解决方案 > 如何在php中发送短信?

问题描述

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

$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。

标签: phpsmssemaphore

解决方案


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

    <?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",

使用实时密钥和测试并尝试达到相同的代码检查状态等待接收


推荐阅读