php脚本发送Zabbix的短信

发布于 2025-01-27 06:25:48 字数 2387 浏览 1 评论 0原文

我有PHP脚本将向Zabbix监视系统发送按摩的API,但是它无效,任何人都可以帮助我解决

#!/usr/bin/php
<?php

#$debug= false;

$numbers = $argv[1];
$msg = $argv[2];



#if ( $debug ) file_put_contents("/tmp/smsapi_debug_".date("YmdHis"), serialize($argv));

$param["accname"] = "user";    //
$param["accpass"] = "pass";      
$param["msg"] = $msg;
$param["numbers"] = $numbers; 
$param["senderid"] = "ID";    


$xml_data =
'<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<senderid>.$param["senderid"].</senderid>
<numbers>.$param["numbers"].</numbers>
<accname>.$param["accname"].</accname>
<accpass>.$param["accpass"].</accpass>
<msg>.$param["msg"].</msg>
</soap12:Body>
</soap12:Envelope>';



$url = "API URL";    

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_HTTP_VERSION,1.1); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/soap+xml; charset=utf-8','Content-Length:250'));
curl_setopt($ch, CURLOPT_POSTFIELDS,$xml_data); 


$response = curl_exec($ch); 
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

 
print $response;
if ($httpCode >= 200 && $httpCode < 300) {

}else {
        file_put_contents("/tmp/smsapi_error_".date("YmdHis"), curl_error($ch));
    die(curl_error($ch)."\n");
}

curl_close($ch);

?>

的错误。

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Sender</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">Unable to handle request without a valid action parameter. Please supply a valid soap action.</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>

下面 发送消息

谢谢

I have PHP script that will be sending massage's to API for zabbix monitoring system but it not working any one can help me with the error below

#!/usr/bin/php
<?php

#$debug= false;

$numbers = $argv[1];
$msg = $argv[2];



#if ( $debug ) file_put_contents("/tmp/smsapi_debug_".date("YmdHis"), serialize($argv));

$param["accname"] = "user";    //
$param["accpass"] = "pass";      
$param["msg"] = $msg;
$param["numbers"] = $numbers; 
$param["senderid"] = "ID";    


$xml_data =
'<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<senderid>.$param["senderid"].</senderid>
<numbers>.$param["numbers"].</numbers>
<accname>.$param["accname"].</accname>
<accpass>.$param["accpass"].</accpass>
<msg>.$param["msg"].</msg>
</soap12:Body>
</soap12:Envelope>';



$url = "API URL";    

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_HTTP_VERSION,1.1); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/soap+xml; charset=utf-8','Content-Length:250'));
curl_setopt($ch, CURLOPT_POSTFIELDS,$xml_data); 


$response = curl_exec($ch); 
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

 
print $response;
if ($httpCode >= 200 && $httpCode < 300) {

}else {
        file_put_contents("/tmp/smsapi_error_".date("YmdHis"), curl_error($ch));
    die(curl_error($ch)."\n");
}

curl_close($ch);

?>

every time I run the code I got the below error

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Sender</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">Unable to handle request without a valid action parameter. Please supply a valid soap action.</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>

what is the correct syntax for the code to be able to send messages

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文