我正在测试 Clickatell API 以在我的基于 php 的应用程序中集成 SMS 确认,我使用他们的 rest api 将消息发送给自己进行测试,但消息永远不会到达。
我的尝试
我用这个https://www.clickatell.com/developers/api-docs/get-coverage-rest/检查覆盖率,这是 JSON 响应:
object(stdClass)[54]
public 'data' =>
object(stdClass)[57]
public 'routable' => boolean true
public 'destination' => string ' 21655609125' (length=12)
public 'minimumCharge' => float 0.8
我还通过检查状态确保消息实际上是发送的;这是 JSON 响应:
object(stdClass)[54]
public 'data' =>
object(stdClass)[57]
public 'charge' => float 0.8
public 'messageStatus' => string '004' (length=3)
public 'description' => string 'Received by recipient' (length=21)
public 'apiMessageId' => string 'b57f4a28dece65a134b56be2010c8a78' (length=32)
public 'clientMessageId' => string '' (length=0)
然后我尝试了他们自己的网站发送消息报告,这就是我所看到的:
消息内容 感谢您测试 Clickatell 的网关覆盖范围。初次购买消息积分后,您将能够更改消息的内容。
移动网络突尼斯:橙色转21655609125
收件人收到(状态 4)
但我自己从来没有收到过消息。可能是什么问题?
编辑:这是我目前在我的应用程序中使用的完整课程
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* MC_SMS class
*/
class MC_SMS {
public $rest_uri = 'https://api.clickatell.com/rest';
public $method = 'post';
public $args = array();
/**
* Constructor
*/
public function __construct( $action, $data = null ) {
$this->data = $data;
$this->init();
switch( $action ) :
// Send message
case 'send' :
$this->endpoint = '/message';
$this->method = 'post';
break;
// Message status
case 'status' :
$this->endpoint = '/message/' . $data;
$this->method = 'get';
break;
// Network coverage
case 'coverage' :
$this->endpoint = '/coverage/' . $data;
$this->method = 'get';
break;
// Account balance
case 'balance' :
$this->endpoint = '/account/balance';
$this->method = 'get';
break;
endswitch;
$this->queried_uri = $this->rest_uri . $this->endpoint;
$this->do_request();
$this->response = ( isset( $this->response_body['body'] ) ) ? json_decode( $this->response_body['body'] ) : null;
}
/**
* Init.
*/
public function init() {
$this->headers = array(
'X-Version' => 1,
'Authorization' => 'Bearer ClHrbIEo_LwAlSVTSMemBIA5Gmvz8HNb5sio3N9GVDdAO_PPJPaZKzdi8Y8cDSmrs4A4',
'Content-Type' => 'application/json',
'Accept' => 'application/json'
);
$this->data = ( ! empty( $this->data ) && is_array( $this->data ) ) ? json_encode( $this->data ) : null;
$this->args['headers'] = $this->headers;
if ( $this->data ) {
$this->args['body'] = $this->data;
}
}
/**
* Do the API request
*/
public function do_request() {
if ( $this->method == 'get' ) {
$this->response_body = wp_remote_get( $this->queried_uri, $this->args );
}
if ( $this->method == 'post' ) {
$this->response_body = wp_remote_post( $this->queried_uri, $this->args );
}
}
}