Clickatell API をテストして、PHP ベースのアプリに SMS 確認を統合しています。残りの 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)
次に、送信されたメッセージのレポート用に独自の Web サイトを試してみましたが、次のように表示されます。
メッセージの内容 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 );
}
}
}