使用 cURL 安装了本地服务器。
[![在此处输入图像描述][1]][1]
我想连接到第三方服务的 api。我正在使用以下脚本:
class Auth {
public $url = "https://xxxxxxxxxxxxxxxxx";
public $credentials = [
'user_name' => 'xxxxxxxxxxxx',
'user_pass' => 'xxxxxxxxxxxx',
'product_code' => 'xxx'
];
function moveaway () {
$access = json_encode($credentials);
$getting = curl_init($url);
curl_setopt($getting, CURLOPT_POST, 1);
curl_setopt($getting, CURLOPT_POSTFIELDS, $access);
curl_setopt($getting, CURLOPT_RETURNTRANSFER, true);
curl_setopt($getting, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($getting, CURLOPT_HEADER, false);
$output = curl_exec($getting);
curl_close($getting);
echo $output;
}
}
由于某种原因,此代码未连接到 api。控制台中没有服务器响应,但也没有错误:
[![在此处输入图像描述][2]][2]
请告诉我,我做错了什么!?
可以这样做。
你如何访问类属性?$url) $this->url 可能会更好。向方法 public function moveaway () {} 添加说明符,如果您不公开使用它们,则将属性设为私有,例如重新定义...
简而言之,错误在于您正在访问仅对该函数可见的类函数内的变量。改变
在
好吧,最好将类重写为更正确的版本。像这样的东西
通过
сеттеры暴露所有变量,然后调用moveAway