You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Zabbix监控系统PHP短信发送脚本报错求助:SOAP Action参数缺失问题及修正咨询

Fixing Zabbix SMS API PHP Script SOAP Error

Let's break down the issues with your script and fix them step by step to resolve that SOAP error:

Key Issues Identified

  • Missing SOAP Action Header: The error message explicitly states you need a valid soap action. SOAP APIs require this header to know which operation to execute—you'll need to add the correct SOAPAction value (check your SMS API docs for the exact string).
  • Incorrect XML Variable Interpolation: You used single quotes for your XML string, so PHP won't parse variables like .$param["senderid"].—this leaves literal text in the XML instead of actual values. A heredoc string makes this cleaner and avoids parsing issues.
  • Hardcoded Content-Length: Setting a fixed Content-Length:250 will break requests where the message/number length varies. Let curl calculate this automatically by removing this header.
  • Commented Authentication Parameter: You commented out $param["accpass"] = "pass";, leaving the accpass field empty in your XML. This will fail API authentication, so uncomment and set your actual password.
  • Invalid SOAP Body Structure: Most SOAP APIs expect parameters to be wrapped inside an operation-specific node (e.g., <SendSMS>) within the <soap12:Body>, not directly under it. You'll need to match your API's required structure.

Fixed Script Code

#!/usr/bin/php 
<?php 
// $debug= false; 
$numbers = $argv[1]; 
$msg = $argv[2]; 

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

// Configure your API credentials
$param["accname"] = "user"; 
$param["accpass"] = "pass"; // Uncommented and set your actual password
$param["msg"] = $msg; 
$param["numbers"] = $numbers; 
$param["senderid"] = "ID"; 

// Use heredoc for clean XML with proper variable interpolation
$xml_data = <<<XML
<?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>
<!-- Replace <SendSMS> with the actual operation name from your API documentation -->
<SendSMS>
<senderid>{$param["senderid"]}</senderid> 
<numbers>{$param["numbers"]}</numbers> 
<accname>{$param["accname"]}</accname> 
<accpass>{$param["accpass"]}</accpass> 
<msg>{$param["msg"]}</msg> 
</SendSMS>
</soap12:Body> 
</soap12:Envelope>
XML;

$url = "API URL"; // Replace with your actual API endpoint
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); // Use PHP constant instead of literal value
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 

// Add required SOAPAction header - update with your API's actual action value
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/soap+xml; charset=utf-8',
    'SOAPAction: "http://your-api-domain.com/your-soap-action"' // Adjust this to match API docs
)); 

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) {
    // Add success handling logic here if needed
} else { 
    // Log both curl error and API response for better debugging
    file_put_contents("/tmp/smsapi_error_".date("YmdHis"), curl_error($ch) . "\nFull Response: " . $response); 
    die(curl_error($ch)."\n"); 
} 

curl_close($ch); 
?>

Additional Notes

  • SOAP Action Value: Replace "http://your-api-domain.com/your-soap-action" with the exact SOAP action string from your SMS provider's docs (this is often listed under request header requirements).
  • SOAP Operation Node: Swap <SendSMS> with the operation name your API expects (e.g., <SubmitMessage>, <SendSMSRequest>).
  • Debugging: Uncomment the debug line to log incoming arguments if you still have issues—this helps confirm Zabbix is passing $numbers and $msg correctly.
  • SSL Security: Disabling CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER is not recommended for production. Once the script works, enable these and ensure your server trusts the API's SSL certificate.

内容的提问来源于stack exchange,提问作者Aysar Alqudah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 20:17:46