我有一个我已下载的PHP库 - 它是一个在很多网站上使用的流行库。我在本地主机上本地运行,一切正常。然后我尝试将其加载到网站并在那里运行并获得解析错误。
我无法弄清楚为什么它会在我的本地主机上而不是在网站上运行 - 请你看看是否有明显的东西?也许php.ini设置我需要设置或其他什么?
错误是
解析错误:语法错误,第14行的/home/phoenixs/public_html/smsGateway.php中的意外'['
这是图书馆,我突出了第14行:
第14行是 返回$ this-> makeRequest('/ api / v3 / contacts / create','POST',['name'=> $ name,'number'=> $ number]);我已将调用脚本放在此
下面class SmsGateway {
static $baseUrl = "https://smsgateway.me";
function __construct($email,$password) {
$this->email = $email;
$this->password = $password;
}
function createContact ($name,$number) {
return $this->makeRequest('/api/v3/contacts/create','POST',['name' => $name, 'number' => $number]);
}
function getContacts ($page=1) {
return $this->makeRequest('/api/v3/contacts','GET',['page' => $page]);
}
function getContact ($id) {
return $this->makeRequest('/api/v3/contacts/view/'.$id,'GET');
}
function getDevices ($page=1)
{
return $this->makeRequest('/api/v3/devices','GET',['page' => $page]);
}
function getDevice ($id)
{
return $this->makeRequest('/api/v3/devices/view/'.$id,'GET');
}
function getMessages($page=1)
{
return $this->makeRequest('/api/v3/messages','GET',['page' => $page]);
}
function getMessage($id)
{
return $this->makeRequest('/api/v3/messages/view/'.$id,'GET');
}
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;
}
}
?> 这是调用脚本:
<?php
include "smsGateway.php";
$ smsGateway =新的SmsGateway('用户','密码');
$deviceID = 22233;
$number = '+64210419805';
$message = 'hi gg 3';
$result = $smsGateway->sendMessageToNumber($number, $message, $deviceID);
print_r($result);
?>