【问题标题】:Clickatell API will send message successfully but I can never receive the messageClickatell API 将成功发送消息,但我永远无法收到消息
【发布时间】:2016-09-20 19:46:11
【问题描述】:

我正在测试 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 的网关覆盖范围。你 将能够在您初始后更改您的消息内容 购买消息积分。

突尼斯移动网络:Orange To 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 );
        }
    }

}

【问题讨论】:

  • 你付过账吗?
  • 还没有 :) 我只是用测试积分对其进行测试,以确定它是否适用于我的应用程序。
  • 贴出你实际用来发送消息的代码
  • 我发布了处理所有请求的整个课程。我这样做是为了发送一条消息: $msg = new SMS( 'send', array( 'to' => array( 'mynumber' ), 'text' => 'test msg' ) );

标签: php api clickatell


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    @Dimitris Magdalinos' answer 的扩展似乎是正确的,following documentation has this to say(强调我的):

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

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

    【讨论】:

      猜你喜欢
      • 2013-08-28
      • 2019-10-13
      • 2018-04-24
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多