因此,我遵循PHP的Pushover常见问题示例:
<?php
curl_setopt_array($ch = curl_init(), array(
CURLOPT_URL => "https://api.pushover.net/1/messages.json",
CURLOPT_POSTFIELDS => array(
"token" => "APP_TOKEN",
"user" => "USER_KEY",
"message" => "hello world",
)));
curl_exec($ch);
curl_close($ch);
?>这个示例运行得很好,但是如果我尝试将消息作为变量发送,比如:
"message" => $variable,它会给我一个错误,告诉我不能发送空白消息。我猜这是一个与语言相关的问题。如何将变量赋值给数组"message"?
谢谢。
发布于 2017-02-23 15:35:43
也许Curl有问题,你可以使用这个函数将数组数据post到api.pushover中。
function sendApiPushover(){
$url = 'https://api.pushover.net/1/messages.json';
$data = array(
"token" => "APP_TOKEN",
"user" => "USER_KEY",
"title" => "John",
"message" => "hello world"
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}发布于 2014-01-17 22:31:02
您的变量$message似乎为空。在运行此脚本之前,最好通过以下方式进行检查:
<?php
if(!empty($message)){
curl_setopt_array($ch = curl_init(), array(
CURLOPT_URL => "https://api.pushover.net/1/messages.json",
CURLOPT_POSTFIELDS => array(
"token" => "APP_TOKEN",
"user" => "USER_KEY",
"message" => $message,
)));
curl_exec($ch);
curl_close($ch);
}
?>https://stackoverflow.com/questions/21188213
复制相似问题