我在PHP中创建SOAP请求以连接到Campaigner(电子邮件营销工具)并上传联系人时遇到问题,但我可以使用一些帮助。我正在使用的API不断响应一个Null对象。这里是我工作过的XML(工作时,我使用了SoapUI):PHP SOAP请求问题
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="https://ws.campaigner.com/2013/01">
<soapenv:Header/>
<soapenv:Body>
<ns:ImmediateUpload>
<!--Optional:-->
<ns:authentication>
<!--Optional:-->
<ns:Username>username</ns:Username>
<!--Optional:-->
<ns:Password>password</ns:Password>
</ns:authentication>
<ns:UpdateExistingContacts>true</ns:UpdateExistingContacts>
<ns:TriggerWorkflow>false</ns:TriggerWorkflow>
<!--Optional:-->
<ns:contacts>
<ns:ContactData>
<ns:ContactKey>
<ns:ContactId>0</ns:ContactId>
<ns:ContactUniqueIdentifier>[email protected]</ns:ContactUniqueIdentifier>
</ns:ContactKey>
<ns:EmailAddress>[email protected]</ns:EmailAddress>
<ns:FirstName>Steve</ns:FirstName>
<ns:LastName>Rogers</ns:LastName>
<ns:Status>Subscribed</ns:Status>
<ns:MailFormat>Both</ns:MailFormat>
<ns:IsTestContact>0</ns:IsTestContact>
</ns:ContactData>
</ns:contacts>
</ns:ImmediateUpload>
这是我的PHP代码:
<?php
$wsdl = "https://ws.campaigner.com/2013/01/contactmanagement.asmx?wsdl";
$trace = true;
$exceptions = true;
$Username = "username";
$Password = "password";
$UpdateExistingContacts = true;
$TriggerWorkflow = false;
$ContactId = 0;
$ContactUniqueIdentifier= "[email protected]";
$EmailAddress = "[email protected]";
$FirstName = "Steve";
$LastName = "Rogers";
$Status = "Subscribed";
$MailFormat = "Both";
$IsTestContact = 0;
$params = array (
"Username" => $Username,
"Password" => $Password,
"UpdateExistingContacts" => $UpdateExistingContacts,
"TriggerWorkflow" => $TriggerWorkflow,
"ContactId" => $ContactId,
"ContactUniqueIdentifier" => $ContactUniqueIdentifier,
"EmailAddress" => $EmailAddress,
"FirstName" => $FirstName,
"LastName" => $LastName,
"Status" => $Status,
"MailFormat" => $MailFormat,
"IsTestContact" => $IsTestContact
);
try{
$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
$response = $client->__call("ImmediateUpload", array($params));
} catch (Exception $e){
echo "error";
echo $e ->getMessage();
echo 'Last Response: '.$client->__getLastResponse();
}
var_dump($response);
?>
这里是我回来的响应:
object(stdClass)#2 (0) {}
这绝对是我的一个格式问题,因为我得到了一个成功的回应使用SoapUI写入Campaigner,并且只有在尝试通过PHP执行操作时才会出现此错误。我感谢您提供的任何帮助!
谢谢 洛根
更新: 我能弄清楚,它是我的构建请求的方式......下面是实际的响应回:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header><ResponseHeader xmlns="https://ws.campaigner.com/2013/01">
<ErrorFlag>true</ErrorFlag>
<ReturnCode>U_4.5.1.3_USERNAME-AND-PASSWORD-REQUIRED</ReturnCode>
<ReturnMessage>Username and Password is required.</ReturnMessage>
</ResponseHeader>
</soap:Header><soap:Body><ImmediateUploadResponse xmlns="https://ws.campaigner.com/2013/01" />
</soap:Body>
</soap:Envelope>