这是一个 PHP 示例,说明如何实现这一点。本质上,您循环遍历 IPN 值,然后将它们添加回您自己的名称/值对字符串中。但是在将每个值添加到您的字符串之前,您会检查它是名字还是姓氏,如果是,则将其设置为等于您已经设置的某个变量。
$modified_first_name = "Bob";
$modified_last_name = "Smith";
foreach ($_POST as $key => $value) { // Loop through the notification NV pairs
//Check if is first or last name, and modify the name
switch ($key) {
case 'first_name':
$value = $modified_first_name;
break;
case 'last_name':
$value = $modified_last_name;
break;
} //end switch $key
//Add to NV pairs
$value = urlencode(stripslashes($value)); // Encode these values
$req .= "&$key=$value"; // Add the NV pairs to the acknowledgement
}
编辑:至于您问题的第二部分(将通知发送到 3rd 方软件),您根本不应该将 IPN 发送到 3rd 方软件。相反,使用从我上面粘贴的脚本派生的数据,使用 POST 将数据发送到您自己的第 3 方软件。你可以这样做:
// post to third party software //
$header .= "POST /script.php HTTP/1.0\r\n";
$header .= "Host: www.thirdpartysoftwaresite.com\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$port = 123; //replace this with actual port on server
// Open a socket for the 3rd party software
$fp = fsockopen('http://www.thirdpartysoftwaresite.com/', $port, $errno, $errstr, 30);
// Send the HTTP POST request
fputs($fp, $header . $req);