Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的PHP代码中出现语法错误(android服务的api sms发送者)_Php_Api_Syntax_Array Merge - Fatal编程技术网

我的PHP代码中出现语法错误(android服务的api sms发送者)

我的PHP代码中出现语法错误(android服务的api sms发送者),php,api,syntax,array-merge,Php,Api,Syntax,Array Merge,伙计,我的.php代码做得非常好,但我不明白为什么我在函数和数组合并的每一行中都会出现语法错误 我使用安卓服务应用程序来做网关的工作,它可以将我的html页面(数字信息)中的信息发送到服务网站,这样它就可以通过我的手机发送短信 但我无法使用此代码,我正在使用此代码发布帖子: <?php include "smsGateway.php"; $smsGateway = new SmsGateway($email, $password); $deviceID = $device; $numbe

伙计,我的.php代码做得非常好,但我不明白为什么我在函数和数组合并的每一行中都会出现语法错误

我使用安卓服务应用程序来做网关的工作,它可以将我的html页面(数字信息)中的信息发送到服务网站,这样它就可以通过我的手机发送短信

但我无法使用此代码,我正在使用此代码发布帖子:

<?php
include "smsGateway.php";
$smsGateway = new SmsGateway($email, $password);

$deviceID = $device;
$number = $number;
$message = $message;

//Please note options is no required and can be left out
$result = $smsGateway->sendMessageToNumber($number, $message, $deviceID, $options);
?>

一切正常,但我的主库smsGateway.php出现了很多语法错误:

<?php

    class SmsGateway {

        static $baseUrl = "https://smsgateway.me";


        function __construct($email,$password) {
            $this->email = $email;
            $this->password = $password;
        }

        function sendMessageToNumber($to, $message, $device, $options=[]) {
            $query = array_merge(['number'=>$to, 'message'=>$message, 'device' => $device], $options);
            return $this->makeRequest('/api/v3/messages/send','POST',$query);
        }

        function sendMessageToManyNumbers ($to, $message, $device, $options=[]) {
            $query = array_merge(['number'=>$to, 'message'=>$message, 'device' => $device], $options);
            return $this->makeRequest('/api/v3/messages/send','POST', $query);
        }

        function sendMessageToContact ($to, $message, $device, $options=[]) {
            $query = array_merge(['contact'=>$to, 'message'=>$message, 'device' => $device], $options);
            return $this->makeRequest('/api/v3/messages/send','POST', $query);
        }

        function sendMessageToManyContacts ($to, $message, $device, $options=[]) {
            $query = array_merge(['contact'=>$to, 'message'=>$message, 'device' => $device], $options);
            return $this->makeRequest('/api/v3/messages/send','POST', $query);
        }

        function sendManyMessages ($data) {
            $query['data'] = $data;
            return $this->makeRequest('/api/v3/messages/send','POST', $query);
        }

        private function makeRequest ($url, $method, $fields=[]) {

            $fields['email'] = $this->email;
            $fields['password'] = $this->password;

            $url = smsGateway::$baseUrl.$url;

            $fieldsString = http_build_query($fields);


            $ch = curl_init();

            if($method == 'POST')
            {
                curl_setopt($ch,CURLOPT_POST, count($fields));
                curl_setopt($ch,CURLOPT_POSTFIELDS, $fieldsString);
            }
            else
            {
                $url .= '?'.$fieldsString;
            }

            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_HEADER , false);  // we want headers
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

            $result = curl_exec ($ch);

            $return['response'] = json_decode($result,true);

            if($return['response'] == false)
                $return['response'] = $result;

            $return['status'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);

            curl_close ($ch);

            return $return;
        }
    }

?>

你应该写这个

$message = ''.$message.''; 
而不是这个

$message = $message;

我想我理解你的问题

我通过改变来解决这个问题:

$options=[] 
致:

致:


在发生这些错误的所有行中。它成功了。

您使用的是什么版本的PHP<代码>[…]在5.4中添加了数组文字的符号。在此之前,您必须使用
数组(…)
。我正在使用hostinger来承载它。使用PHP5.5。我这样做就是为了这个,因为我知道在PHP5.4中这是可能的。我得到了这个错误:警告:array#u merge():Argument#2不是/home/u549063526/public_html/home/smsGateway.php中的数组,在第46行代码行是$query=array_merge(['number'=>$to,'message'=>$message',device=>$device],$options);我重新提出这个问题。你说你有语法错误,但那不是语法错误。该错误意味着
$options
不是数组。当您调用
sendMessageToNumber
时,您使用的是变量
$options
,但您从未对其进行初始化。如果你想在函数定义中使用默认值,你应该完全不使用参数。这到底能解决什么问题?
$options
array_merge(['number'=>$to, 'message'=>$message, 'device' => $device], $options); 
array_merge(array('number'=>$to, 'message'=>$message, 'device' => $device), $options);