как конвертировать адрес / адрес телефона в хэш-коды в PHP sms API - PullRequest
0 голосов
/ 01 февраля 2019

Я хочу создать приложение для отправки SMS, используя PHP с SMS API .В моем ответном сообщении я вижу код успеха и сообщение об успехе, но моя проблема в моем файле журнала выглядит как

Пропущенное исключение ' SMSServiceException ' с сообщением ' Форматадрес недействителен '

Я думаю, что проблема в том, начинается, когда я хэширую кодирующий номер телефона.И я не знаю, как это сделать, пожалуйста, помогите мне.

Я пытался преобразовать номер телефона, используя md5 () , но результат тот же.

my index.php

$jsonData = array( 'requestId'=> '','message' => 'thismsg hello',
  'password' => '25c8db49905003e3347ad861546fce1a',
  'sourceAddress' => '77000',
  'deliveryStatusRequest' => '1',
  'chargingAmount' => '2.00',
  'destinationAddresses' => ['88b7a1e8dbf419a2c0835b4f33d06c1a'],//this convert with md5
  'applicationId' => 'APP_051000',
  'encoding' => '0',
  'version' => '1.0',
  'binaryHeader' => ''
);

мой файл .log:

[01-Feb-2019 08:57:34 Asia/Colombo] Message received msg_header hello
[01-Feb-2019 08:57:35 Asia/Colombo] Passed Exception exception 'SMSServiceException' with message 'Format of the address is invalid.' in /ophielapp/lib/SMSSender.php:58
Stack trace:
#0 /ophielapp/lib/SMSSender.php(46): SMSSender->handleResponse(Object(stdClass))
#1 /ophielapp/lib/SMSSender.php(34): SMSSender->sendRequest('{"applicationId...')
#2 /ophielapp/sms.php(66): SMSSender->sendMessage('hello', '77000')
#3 {main}

Я хочу правильно отправить номер телефона в smsSender.php с хэш-кодом и Ifхочу более подробную информацию о других файлах PHP, я могу предоставить его.

результат в моем браузере: это изображение ответа

это мой smsSender.php

<?php

require_once 'SMSServiceException.php';
class SMSSender{
    private $applicationId,
            $password,
            $serverURL;

    public function __construct($serverURL, $applicationId, $password)
    {
            $this->applicationId = $applicationId;
            $this->password = $password;
            $this->serverURL = $serverURL;
    }

    public function broadcastMessage($message){
        return $this->sendMessage($message, array('tel:all'));
    }

    public function sendMessage($message, $addresses){
        if(empty($addresses))
            throw new SMSServiceException('Format of the address is invalid.', 'E1325');
        else {
            $jsonStream = (is_string($addresses))?$this->resolveJsonStream($message, array($addresses)):(is_array($addresses)?$this->resolveJsonStream($message, $addresses):null);
            return ($jsonStream!=null)?$this->sendRequest($jsonStream):false;

        }
    }

    private function sendRequest($jsonStream){
        $opts = array('http'=>array('method'=>'POST',
                                    'header'=>'Content-type: application/json',
                                    'content'=>$jsonStream));
        $context = stream_context_create($opts);
        $response = file_get_contents($this->serverURL, 0, $context);

        return $this->handleResponse(json_decode($response));
    }

    private function handleResponse($jsonResponse){
        $statusCode = $jsonResponse->statusCode;
        $statusDetail = $jsonResponse->statusDetail;

        if(empty($jsonResponse))
            throw new SMSServiceException('Invalid server URL', '500');
        else if(strcmp($statusCode, 'S1000')==0)
            return true;
        else
            throw new SMSServiceException($statusDetail, $statusCode);
    }

    private function resolveJsonStream($message, $addresses){
        // $addresses is a array

        $messageDetails = array('message'=>$message,
                                'destinationAddresses'=>$addresses);

        $applicationDetails = array('applicationId'=>$this->applicationId,
                                    'password'=>$this->password);

        $jsonStream = json_encode($applicationDetails+$messageDetails);

        return $jsonStream;
    }

    public function get_location_stream( $addresse){

                $reqDetails = array(
                                        'applicationId'=>$this->applicationId,
                                        'password'=>$this->password,
                                        'serviceType'=>'IMMEDIATE',
                                        'subscriberId'=>$addresse
                                    );

                return json_encode($reqDetails);

    }

    public function getlocation( $addresse){

        //$jsonStream = get_location_stream($addresse);

        $jsonStream= array(
                                        'applicationId'=>$this->applicationId,
                                        'password'=>$this->password,
                                        'serviceType'=>'IMMEDIATE',
                                        'subscriberId'=>$addresse
                    );
        print_r($jsonStream);
        json_encode($jsonStream);                           
        $opts = array('http'=>array('method'=>'POST',
                                    'header'=>'Content-Type: application/json',
                                    'content'=>$jsonStream));

        $context = stream_context_create($opts);
        $response = file_get_contents('http://localhost:7000/lbs/locate', 0, $context);

        echo $response;

        //return $this->location_response(json_decode($response));
        return json_decode($response);
    }

    public function location_response($jsonResponse){
        $statusCode = $jsonResponse->statusCode;

        if(empty($jsonResponse)){

            throw new SMSServiceException('Invalid server URL', '500');

        }else if(strcmp($statusCode, 'S1000')==0){

             return array(
                            $jsonResponse->longitude, 
                            $jsonResponse->latitude,
                            $jsonResponse->horizontalAccuracy,
                            $jsonResponse->freshness,
                            $jsonResponse->messageId

                        );

        }else{

            throw new SMSServiceException($statusDetail, $statusCode);
        }
    }

      public function getResponse($addresse){

        $jsonStream= array(
                                        'applicationId'=>$this->applicationId,
                                        'password'=>$this->password,
                                        'serviceType'=>'IMMEDIATE',
                                        'subscriberId'=>$addresse
                            );


        $opts = array('http'=>array('method'=>'POST',
                                    'header'=>'Content-Type: application/json',
                                    'content'=>json_encode($jsonStream)));

        $context = stream_context_create($opts);
        $response = file_get_contents('http://localhost:7000/lbs/locate', 0, $context);

        return json_decode($response);
    }





}
?>

1 Ответ

0 голосов
/ 01 февраля 2019

адреса назначения передаются в виде строки

'destinationAddresses' =>'88b7a1e8dbf419a2c0835b4f33d06c1a',
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...