2

我正在测试 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 );
        }
    }

}
4

2 回答 2

1

在付款之前和使用试用积分时,收到的消息是以下文本: 消息内容 感谢您测试 Clickatell 的网关覆盖范围。初次购买消息积分后,您将能够更改消息的内容。

这意味着您已成功向您的设备发送和接收短信。只有在您支付积分后,收件人设备才能看到您自己的实际消息。

于 2016-11-16T17:05:49.657 回答
0

作为@Dimitris Magdalinos'答案的扩展,这似乎是正确的,以下文档有这个说法(强调我的):

您可以使用“日常任务”一章中列出的方法开始测试网关。但是,请注意,如果您使用帐户附带的 10 个免费 SMS 积分,在您购买积分之前,Clickatell 将用感谢文本替换内容,如下面的消息

感谢您测试 Clickatell 的网关覆盖范围。初次购买消息积分后,您将能够更改消息的内容。

于 2017-01-24T02:03:21.067 回答