dongrou839975 2015-10-02 12:19
浏览 46

不能有plivo发送短信工作

I'm using Plivo PHP library to send sms via plivo.

I'm setting the correct auth credentials in the library and it is base64 encoded as per the library in curl_request method.

I think the headers are correct and My integration with my platform works fine but when trying the send a simple message with send_message method, I cannot have it working and always get a response status 401 which is, as per the documentation, an error of authentication.

What Am I doing wrong ?

Many Thanks

My code:

//Load library messages
                $this->load->library( 'Plivo' );
                $p = new RestAPI( 'MANXXXXXXXXXXXXXZIWOD', 'MmXXXXXXXXXXXXXXXXXXXXXXXXXXXX' );

                // //for each phone Numbers generate password associated to event
                foreach ( $nums as $key => $num ) {
                    //For each combo send Message
                    $params = array(
                            'src' => '13307782635', // Sender's phone number with country code (US)
                            'dst' => '447598XXXXXX', // Receiver's phone number with country code (UK)
                            'text' => 'Hi, Message from your fired', // Your SMS text message
                            'url' => site_url( 'eventPromotion/report' ), // The URL to which with the status of the message is sent
                            'method' => 'POST' // The method used to call the url
                        );
                    // Send message
                    $response = $p->send_message($params);

                    // Print the response
                    echo "Response : ";
                    var_dump( $response );
  • 写回答

1条回答 默认 最新

  • dptgpyl61857413 2015-12-24 12:25
    关注

    Instead of library use can use api.

    <?php
        # Plivo AUTH ID
        $AUTH_ID = 'AUTH_ID-GOES-HERE';
        # Plivo AUTH TOKEN
        $AUTH_TOKEN = 'AUTH-TOKEN-GOES-HERE';
        # SMS sender ID.
        $src = 'SM123';
        # SMS destination number
        $dst = 'MOBILE-NUMBER';
        # SMS text
        $text = 'Hello';
        $url = 'https://api.plivo.com/v1/Account/'.$AUTH_ID.'/Message/';
        $data = array("src" => "$src", "dst" => "$dst", "text" => "$text");
        $data_string = json_encode($data);
        $ch=curl_init($url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
        curl_setopt($ch, CURLOPT_USERPWD, $AUTH_ID . ":" . $AUTH_TOKEN);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        $response = curl_exec( $ch );
        curl_close($ch);
        print_r($response);
    ?>
    

    Change following params in code

    AUTH_ID-GOES-HERE
    AUTH-TOKEN-GOES-HERE
    MOBILE-NUMBER
    
    Note: Please make sure upload this code to live server in localhost it is not working
    
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算