简体   繁体   English

如何将目标地址/电话号码转换为PHP SMS API中的哈希码

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

I want to create SMS sending application using PHP with SMS API . 我想使用PHPSMS API创建SMS发送应用程序。 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 ' 通过消息“ 地址格式无效 ”传递的异常异常“ SMSServiceException

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. 我尝试使用md5()转换电话号码,但结果相同。

my index.php 我的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: 我的.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}

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. 我想用哈希码正确地将电话号码发送到smsSender.php中,如果想了解其他php文件的更多详细信息,我可以提供。

result in my browser: this is the image of response 结果在我的浏览器中: 这是响应的图像

this is my smsSender.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);
    }





}
?>

destinationAddresses作为字符串传递

'destinationAddresses' =>'88b7a1e8dbf419a2c0835b4f33d06c1a',

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM