致命错误:未捕获异常:响应状态不成功

时间:2018-03-20 12:11:09

标签: php oauth-2.0 sms ringcentral

我正在尝试通过RingCentral发送短信。这是我在下面的错误。

  

致命错误:未捕获异常:响应在/Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/vendor/ringcentral/ringcentral-php/src/Http/Client.php:39中状态不成功堆栈跟踪:#0 /Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(276):RingCentral \ SDK \ Http \ Client - > send(Object(GuzzleHttp \ Psr7 \ Request))#1 /Applications/MAMP/htdocs/Paradise/wp-content/plugins/ring-central/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php (363):RingCentral \ SDK \ Platform \ Platform-> sendRequest(Object(GuzzleHttp \ Psr7 \ Request),Array)#2 / Applications / MAMP / htdocs / Paradise / wp-content / plugins / ring-central / vendor / ringcentral / ringcentral-php / src / Platform / Platform.php(183):RingCentral \ SDK \ Platform \ Platform-> requestToken('/ restapi / oauth / ...',Array)#3 / Applications / MAMP / htdocs /Paradise/wp-content/plugins/ring-central/includes/ring-central.class.php(26):RingCentral \ SDK \ Platform \ Platfor m->登录(数组,'#Gc090486','101')#4 / Applicati in / Applications / MAMP / htdocs / Paradise / wp-content / plugins / ring-central / vendor / ringcentral / ringcentral-php / src第50行/Http/Client.php

<?php

use RingCentral\SDK\SDK;

define("FAILED", 1);
define("LOCKED", 2);

class RingCentralConnection {

private $_sdk;

private $_platform;

function __construct($clientId, $secret) {

}

//https://platform.ringcentral.com/restapi/v1.0/account/159048008/extension/171857008/call-log?dateFrom=2012-08-26

public function sendSMS($from, $to, $text) {
    $_credentials = require (getPluginDir().'/includes/credentials.php');
    $_sdk         = new SDK($_credentials['appKey'], $_credentials['appSecret'], $_credentials['server'], '2FA Demo', '1.0.0');
    //print_r($_sdk);
    $_platform = $_sdk->platform();


    try {
        $_platform->login($_credentials['username'], $_credentials['extension'], $_credentials['password']);
        // $code     = generateRandomCode(6);
        // $myNumber = $_credentials['username'];
        // try {
        //  $response = $_platform->post('/account/~/extension/~/sms', array(
        //          'from' => array('phoneNumber' => $myNumber),
        //          'to'   => array(array('phoneNumber'   => $to)),
        //          'text' => $message
        //      ));

        //  $status = $response->json()->messageStatus;
        //  echo $status;
        //  if ($status == "SendingFailed" || $status == "DeliveryFailed") {
        //      //$db->close();
        //      createResponse(new Response(FAILED, "RC server connection error. Please try again."));
        //  } else {
        //      //$timeStamp = time();
        //      //$query = "UPDATE users SET code= " . $code . ", codeexpiry= " . $timeStamp . " WHERE email='" . $email . "'";
        //      //$db->query($query);
        //      //$db->close();
        //      createResponse(new Response(LOCKED, $message));
        //  }
        // } catch (ApiException $e) {
        //  //$db->close();
        //  $this->createResponse(new Response(FAILED, "RC server connection error. Please try again in."));
        // }
    } catch (ApiException $e) {
        //$db->close();
        //print_r($e);
        $this->createResponse(new Response(FAILED, "RC server connection error. Please try again out."));
    }

}

function createResponse($res) {
    $response = json_encode($res);
    echo $response;
}
function databaseError() {
    $res      = new Response(UNKNOWN, "Unknown database error. Please try again.");
    $response = json_encode($res);
    die($response);
}
}
class Response {
    function __construct($error, $message) {
        $this->error   = $error;
        $this->message = $message;
    }
    public $error;
    public $message;
}

//credentials
return array(
    'username'  => '+13128589951',
    'extension' => '101', // extension number
    'password'  => '',
    'appKey'    => '',
    'appSecret' => '',
    'server'    => 'https://platform.devtest.ringcentral.com'// for production - https://platform.ringcentral.com
);

0 个答案:

没有答案