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

PHP基于SOAP调用短信网关及实现notifySmsDeliveryReceipt操作咨询

PHP实现Parlay X 3短信网关SOAP请求及回执接口方案

Hey there, based on your requirements, here's a step-by-step implementation plan for sending SMS requests via SOAP in PHP and setting up the delivery receipt callback interface:

1. Sending SMS Requests via SOAP

First, make sure the PHP SOAP extension is enabled (check your php.ini for extension=soap and restart your server if needed).

Step 1: Initialize the SOAP Client

Load the provided WSDL file to create a SOAP client instance. Enabling trace helps with debugging by letting you inspect the raw request/response XML, and exceptions ensures SOAP errors throw exceptions for easier handling:

$wsdlFile = '/path/to/your/sms-gateway.wsdl'; // Replace with your actual WSDL path
try {
    $soapClient = new SoapClient($wsdlFile, [
        'trace' => true,
        'exceptions' => true,
        // Add any additional options like authentication if required by the gateway
        // 'login' => 'your-username',
        // 'password' => 'your-password'
    ]);
} catch (SoapFault $e) {
    die("Failed to initialize SOAP client: " . $e->getMessage());
}

Step 2: Build the Request Parameters

Map the fields from your provided request example into a PHP array, matching the structure defined in the WSDL:

$requestData = [
    'senderAddress' => 'your-sender-id-or-number',
    'address' => ['recipient-phone-number-1', 'recipient-phone-number-2'], // Array for multiple recipients
    'message' => 'Your SMS content goes here',
    'correlator' => 'unique-id-to-track-this-request', // Use this to match delivery receipts later
    // Include any other required parameters from your request example/WSDL
];

Step 3: Call the SOAP Method and Handle Response

Invoke the relevant SOAP method (check your WSDL for the exact method name, e.g., sendSms) and process the response:

try {
    $response = $soapClient->sendSms($requestData); // Replace with the actual method name from WSDL
    // Process the successful response
    echo "SMS sent successfully! Response: ";
    print_r($response);

    // For debugging, you can view raw XML
    // echo "Request XML: " . $soapClient->__getLastRequest();
    // echo "Response XML: " . $soapClient->__getLastResponse();
} catch (SoapFault $e) {
    echo "SOAP Request Error: " . $e->getMessage();
    // Debug with raw request/response
    echo "\nRequest XML: " . $soapClient->__getLastRequest();
    echo "\nResponse XML: " . $soapClient->__getLastResponse();
}

2. Implementing the notifySmsDeliveryReceipt Callback Interface

To receive delivery receipts, you need to set up a SOAP server endpoint that Parlay X 3 can call. Here's how to build it with PHP's SoapServer:

Step 1: Define the Service Class

Create a class with the notifySmsDeliveryReceipt method, matching the parameter structure specified in the Parlay X 3 documentation:

class SmsDeliveryReceiptService {
    /**
     * Handle incoming delivery receipt notifications
     * @param string $correlator The unique ID you sent with the original SMS request
     * @param string $address The recipient's phone number
     * @param object $deliveryStatus The delivery status details (structure depends on WSDL)
     * @return array Response as per the interface requirements
     */
    public function notifySmsDeliveryReceipt($correlator, $address, $deliveryStatus) {
        // Process the receipt: log to database, trigger alerts, etc.
        $logMessage = sprintf(
            "Delivery Receipt - Correlator: %s, Recipient: %s, Status: %s",
            $correlator,
            $address,
            print_r($deliveryStatus, true)
        );
        error_log($logMessage); // Log to server error log or your own system

        // Return a valid response as defined by the interface (check WSDL for required structure)
        return ['status' => 'received'];
    }
}

Step 2: Set Up the SOAP Server

Create a PHP script (e.g., sms-receipt-callback.php) that acts as the endpoint:

// Load the WSDL for the receipt interface (if provided by Parlay X 3)
$receiptWsdl = '/path/to/notify-sms-delivery-receipt.wsdl';

try {
    $soapServer = new SoapServer($receiptWsdl);
    $soapServer->setClass('SmsDeliveryReceiptService');
    $soapServer->handle(); // Process incoming SOAP requests
} catch (SoapFault $e) {
    die("Receipt Service Error: " . $e->getMessage());
}

Step 3: Configure the Endpoint

Deploy this script to your web server (e.g., https://your-app-domain.com/sms-receipt-callback.php), then provide this URL to your Parlay X 3 service provider so they can send delivery receipts to it.

Key Notes

  • WSDL Compliance: Ensure all parameters and method names strictly match the definitions in the provided WSDL files—mismatches will cause SOAP errors.
  • Security: If the gateway requires authentication, add the login and password options to the SoapClient. For the callback endpoint, consider using HTTPS and IP whitelisting to restrict access.
  • Debugging: Use __getLastRequest() and __getLastResponse() to inspect raw XML when troubleshooting issues.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 09:15:00