how to convert destinationAddresses/phone number into hash codes in PHP sms API

how to convert destinationAddresses/phone number into hash codes in PHP sms API

I want to create SMS sending application using&nbsp;<strong>PHP</strong>&nbsp;with&nbsp;<strong>SMS API</strong>. In my response message I can see success code and success message but my Problem is in my log file says as

I want to create SMS sending application using PHP with SMS API. In my response message I can see success code and success message but my Problem is in my log file says as

Passed Exception exception 'SMSServiceException' with message 'Format of the address is invalid'

I think problem is, starts when I hash coding phone number. And I don't know how to do that, Please help me.

I have tried to convert phone number using md5() but result is same.

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' => ''
);

my .log file result:

[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}

I want to correctly send phone number into smsSender.php with hash code and If want to more details of other php file I can provide it.

result in my browser:this is the image of response

this is my smsSender.php

<?php

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

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

public function broadcastMessage($message){
    return $this-&gt;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-&gt;resolveJsonStream($message, array($addresses)):(is_array($addresses)?$this-&gt;resolveJsonStream($message, $addresses):null);
        return ($jsonStream!=null)?$this-&gt;sendRequest($jsonStream):false;

    }
}

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

    return $this-&gt;handleResponse(json_decode($response));
}

private function handleResponse($jsonResponse){
    $statusCode = $jsonResponse-&gt;statusCode;
    $statusDetail = $jsonResponse-&gt;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'=&gt;$message,
                            'destinationAddresses'=&gt;$addresses);

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

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

    return $jsonStream;
}

public function get_location_stream( $addresse){

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

            return json_encode($reqDetails);

}

public function getlocation( $addresse){

    //$jsonStream = get_location_stream($addresse);

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

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

    echo $response;

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

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

    if(empty($jsonResponse)){

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

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

         return array(
                        $jsonResponse-&gt;longitude, 
                        $jsonResponse-&gt;latitude,
                        $jsonResponse-&gt;horizontalAccuracy,
                        $jsonResponse-&gt;freshness,
                        $jsonResponse-&gt;messageId

                    );

    }else{

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

  public function getResponse($addresse){

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


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

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

    return json_decode($response);
}

} ?>


php json

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire Dedicated PHP Developer

Looking to hire affordable yet experienced PHP developers? **[Hire Dedicated PHP Developer](https://hourlydeveloper.io/hire-dedicated-php-developer/ "Hire Dedicated PHP Developer")**, who can convert your idea to reality, within the stipulated...

PHP Web Application Development Company

As a top **PHP Web Application Development Company in USA**[https://www.dataeximit.com/php-development-services/](https://www.dataeximit.com/php-development-services/ "https://www.dataeximit.com/php-development-services/"), we at Data EximIT have...

How to use highchart in php with example

Here, i will let you know that how to use highchart in php application with example. Highchart provides feature to draw different type of charts.

Advantages of Hiring PHP Developer for your Website Project

PHP - Hypertext pre-processor, a scripting language used by many people in developing web pages, but most of us are unaware even of the full form. To train someone and make them learn this whole language is as difficult and time-consuming as it is...

PHP Website Development

Skenix Infotech is a leading PHP Web Development Company that helps companies get results with industry best practices. Get affordable PHP Development Services.