php - 不能在我的服务器上使用 file() 我必须改用 cURL,如何使这个 bulksms 代码工作?
问题描述
不能在我的服务器上使用 file() 我必须改用 cURL,如何使这个 bulksms 代码工作?不能使用文件();在我的服务器上,因为 allow_urlopen() 已关闭,可以使用什么 cURL 函数代替 file();这是一个群发短信 API
<?php
//Check if sms notification is enabled
if(isset($configInfo['sms_note'])
AND $configInfo['sms_note'] == 'Enabled'){
$newPhone = str_replace('+', '', $phone);
$SMSCode = $SMSCode;
$SMSsender = $configInfo['sms_sender'];
$SMSport = $configInfo['sms_port'];
$SMSurl = $configInfo['sms_gateway_url'];
$SMSusername = $configInfo['sms_gateway_user'];
$SMSpassword = $configInfo['sms_gateway_pass'];
$SMSsitename = $siteInfo['site_name'];
class Sender {
var $host;
var $port;
var $strUserName;
var $strPassword;
var $strSender;
var $strMessage;
var $strMobile;
var $strMessageType;
var $strDlr;
var $phoneCode;
var $newPhone;
var $SMSCode;
var $SMSsender;
var $SMSport;
var $SMSusername;
var $SMSpassword;
var $SMSsitename;
var $senderName;
private function sms__unicode($message) {
$hex1 = '';
if (function_exists('iconv')) {
$latin = @iconv('UTF-8', 'ISO-8859-1', $message);
if (strcmp($latin, $message)) {
$arr = unpack('H*hex', @iconv('UTF-8', 'UCS-2BE',$message));
$hex1 = strtoupper($arr['hex']);
}
if ($hex1 == '') {
$hex2 = '';
$hex = '';
for ($i = 0; $i < strlen($message); $i++) {
$hex = dechex(ord($message[$i]));
$len = strlen($hex);
$add = 4 - $len;
if ($len < 4) {
for ($j = 0; $j < $add; $j++) {
$hex = "0" . $hex;
}
}
$hex2.=$hex;
}
return $hex2;
} else {
return $hex1;
}
} else {
print 'iconv Function Not Exists !';
}
}
//Constructor..
public function Sender($host, $port, $username, $password, $sender, $message, $mobile, $msgtype, $dlr) {
global $phoneCode;
global $newPhone;
global $SMSCode;
global $SMSsender;
global $SMSport;
global $SMSurl;
global $SMSusername;
global $SMSpassword;
global $SMSsitename;
$this->host = $SMSurl;
$this->port = $SMSport;
$this->strUserName = $SMSusername;
$this->strPassword = $SMSpassword;
$this->strSender = $SMSsender;
$this->strMessage = $SMSsitename." Phone Verification Code: ".$SMSCode.". Thanks";
$this->strMobile = $newPhone;
$this->strMessageType = 0;
$this->strDlr = 0;
}
public function Submit() {
$port = "";
if($this->port == '') {
$port = ":" . $this->port;
}
if ($this->strMessageType == "2" || $this->strMessageType == "6") {
//Call The Function Of String To HEX.
$this->strMessage = $this->sms__unicode($this->strMessage);
try {
//Smpp http Url to send sms.
$live_url = "http://" . $this->host . ":" . $this->port . "/bulksms/bulksms?username=" . $this->strUserName . "&password=" . $this->strPassword . "&type=" . $this->strMessageType . "&dlr=" . $this->strDlr . "&destination=" . $this->strMobile . "&source=" . $this->strSender . "&message=" . $this->strMessage . "";
$parse_url = file($live_url):
echo $parse_url[0];
} catch (Exception $e) {
echo 'Message:' . $e->getMessage();
}
} else {
$this->strMessage = urlencode($this->strMessage);
try {
//Smpp http Url to send sms.
$live_url = "http://" . $this->host . ":" . $this->port. "/bulksms/bulksms?username=" . $this->strUserName . "&password=" . $this->strPassword . "&type=" . $this->strMessageType . "&dlr=" . $this->strDlr . "&destination=" . $this->strMobile . "&source=" . $this->strSender . "&message=" . $this->strMessage . "";
$parse_url = file($live_url);
echo $parse_url[0];
} catch (Exception $e) {
echo 'Message:' . $e->getMessage();
}
}
}
}
//Call The Constructor.
$obj = new Sender("IP/DOMAIN","PORT","USERNAME","PASSWORD","SENDER/SOURCE","MESSAGE","DESTINATION","MESSAGE TYPE","1");
$obj->Submit ();
}
?>
<?php
//Check if sms notification is enabled
if(isset($configInfo['sms_note'])
AND $configInfo['sms_note'] == 'Enabled'){
$newPhone = str_replace('+', '', $phone);
$SMSCode = $SMSCode;
$SMSsender = $configInfo['sms_sender'];
$SMSport = $configInfo['sms_port'];
$SMSurl = $configInfo['sms_gateway_url'];
$SMSusername = $configInfo['sms_gateway_user'];
$SMSpassword = $configInfo['sms_gateway_pass'];
$SMSsitename = $siteInfo['site_name'];
class Sender {
var $host;
var $port;
var $strUserName;
var $strPassword;
var $strSender;
var $strMessage;
var $strMobile;
var $strMessageType;
var $strDlr;
var $phoneCode;
var $newPhone;
var $SMSCode;
var $SMSsender;
var $SMSport;
var $SMSusername;
var $SMSpassword;
var $SMSsitename;
var $senderName;
private function sms__unicode($message) {
$hex1 = '';
if (function_exists('iconv')) {
$latin = @iconv('UTF-8', 'ISO-8859-1', $message);
if (strcmp($latin, $message)) {
$arr = unpack('H*hex', @iconv('UTF-8', 'UCS-2BE',$message));
$hex1 = strtoupper($arr['hex']);
}
if ($hex1 == '') {
$hex2 = '';
$hex = '';
for ($i = 0; $i < strlen($message); $i++) {
$hex = dechex(ord($message[$i]));
$len = strlen($hex);
$add = 4 - $len;
if ($len < 4) {
for ($j = 0; $j < $add; $j++) {
$hex = "0" . $hex;
}
}
$hex2.=$hex;
}
return $hex2;
} else {
return $hex1;
}
} else {
print 'iconv Function Not Exists !';
}
}
//Constructor..
public function Sender($host, $port, $username, $password, $sender, $message, $mobile, $msgtype, $dlr) {
global $phoneCode;
global $newPhone;
global $SMSCode;
global $SMSsender;
global $SMSport;
global $SMSurl;
global $SMSusername;
global $SMSpassword;
global $SMSsitename;
$this->host = $SMSurl;
$this->port = $SMSport;
$this->strUserName = $SMSusername;
$this->strPassword = $SMSpassword;
$this->strSender = $SMSsender;
$this->strMessage = $SMSsitename." Phone Verification Code: ".$SMSCode.". Thanks";
$this->strMobile = $newPhone;
$this->strMessageType = 0;
$this->strDlr = 0;
}
public function Submit() {
$port = "";
if($this->port == '') {
$port = ":" . $this->port;
}
if ($this->strMessageType == "2" || $this->strMessageType == "6") {
//Call The Function Of String To HEX.
$this->strMessage = $this->sms__unicode($this->strMessage);
try {
//Smpp http Url to send sms.
$live_url = "http://" . $this->host . ":" . $this->port . "/bulksms/bulksms?username=" . $this->strUserName . "&password=" . $this->strPassword . "&type=" . $this->strMessageType . "&dlr=" . $this->strDlr . "&destination=" . $this->strMobile . "&source=" . $this->strSender . "&message=" . $this->strMessage . "";
$parse_url = file($live_url):
echo $parse_url[0];
} catch (Exception $e) {
echo 'Message:' . $e->getMessage();
}
} else {
$this->strMessage = urlencode($this->strMessage);
try {
//Smpp http Url to send sms.
$live_url = "http://" . $this->host . ":" . $this->port. "/bulksms/bulksms?username=" . $this->strUserName . "&password=" . $this->strPassword . "&type=" . $this->strMessageType . "&dlr=" . $this->strDlr . "&destination=" . $this->strMobile . "&source=" . $this->strSender . "&message=" . $this->strMessage . "";
$parse_url = file($live_url);
echo $parse_url[0];
} catch (Exception $e) {
echo 'Message:' . $e->getMessage();
}
}
}
}
//Call The Constructor.
$obj = new Sender("IP/DOMAIN","PORT","USERNAME","PASSWORD","SENDER/SOURCE","MESSAGE","DESTINATION","MESSAGE TYPE","1");
$obj->Submit ();
}
?>
解决方案
我认为您应该使用 file_get_contents 而不是 file。根据您的代码所说,您只关心内容。
您的Sender
构造函数需要编辑,因此它实际上是在使用参数。现在它得到虚拟值。
推荐阅读
- ads - 如何预测广告展示次数以避免超卖?
- bash - 如何在没有sed的情况下替换csv文件中的一行
- java - Prometheus:如何收集临时进程的内存消耗指标?
- javascript - v-for 没有正确对齐内容?
- windows - 在 .idea/* 文件中强制使用 LF 行分隔符
- javascript - 带有文本框的 MvcGrid 复选框未显示正确的文本框值
- ios - 适用于 Android 和 iOS 平台的 Ionic 3 应用程序上的 PDF 到 Base64
- machine-learning - 从以前的交易中预测客户行为
- angular - 将 API 与 Angular Async 一起使用的最佳方式
- sql - 将 WITH 语句与 UNION 结合使用