php-soap客户端添加信息


php soap client add information

试图向soap服务器执行请求,需要添加电子邮件地址,这是所需的格式:

          <EmailAddresses>
        <Home xsi:nil="true" />
        <Invoice xsi:nil="true" />
        <Primary xsi:nil="true" />
        <Work xsi:nil="true" />
        <Alternative xsi:nil="true" />
        </EmailAddresses>
          <PhoneNumbers>
        <Home xsi:nil="true" />
        <Fax xsi:nil="true" />
        <Mobile xsi:nil="true" />
        <Primary xsi:nil="true" />
        <Work xsi:nil="true" />
      </PhoneNumbers>

我有一段代码来创建参数:

$username = "www;
$password = "ddd"; 
$applicationid = "ggg"; 
$options = array('trace' => true);
$params ["credential"]["Username"] = $username;
$encodedPassword = md5(mb_convert_encoding($password, 'utf-16le', 'utf-8'));
$params ["credential"]["Password"] = $encodedPassword;
$params ["credential"]["ApplicationId"] = $applicationid;
$params ["credential"]["IdentityId"] = "xxx";
try {
$authentication = new SoapClient("https://api.24sevenoffice.com/authenticate/v001/authenticate.asmx?wsdl", $options);
$login = true;
if (!empty($_SESSION['ASP.NET_SessionId'])) {
    $authentication->__setCookie("ASP.NET_SessionId",     $_SESSION['ASP.NET_SessionId']);
    try {
        $login = !($authentication->HasSession()->HasSessionResult);
    } catch (SoapFault $fault) {
        $login = true;
    }
  }
  if ($login) {
    $result = ($temp = $authentication->Login($params));
    $_SESSION['ASP.NET_SessionId'] = $result->LoginResult;
    $authentication->__setCookie("ASP.NET_SessionId", $_SESSION['ASP.NET_SessionId']);
    // throw an error if the login is unsuccessful
    if ($authentication->HasSession()->HasSessionResult == false)
        throw new SoapFault("0", "Invalid credential information.");
   }
 $superService = new SoapClient("https://api.24sevenoffice.com/CRM/Company/V001/CompanyService.asmx?wsdl", $options);
$superService->__setCookie("ASP.NET_SessionId", $_SESSION['ASP.NET_SessionId']);    
$datosCompania = array("Type" => "Business",
                   "Name" => "Trying with all parameters again 4",
                   "Address" => "Libertad 1320, Vicente Lopez, Buenos Aires, Argentina",
                   "PhoneNumbers" => array("Primary" =>"41771296","Work"=>"47910936","Home"=>"47955678"),
                   "EmailAddresses" => array("Primary" =>"gutibs@gmail.com"),
                   "OrganizationNumber" => "987987654");
  $result =  $superService->SaveCompanies(array("companies" =>array("Company"=>$datosCompania)));
} catch (SoapFault $fault) {
echo 'Exception: ' . $fault->getMessage();
}
echo "<pre>";
print_r($result);

这是我得到的回应:

stdClass Object
(
[SaveCompaniesResult] => stdClass Object
    (
        [Company] => stdClass Object
            (
                [Id] => 90036
                [OrganizationNumber] => 987987654
                [Name] => Trying with all parameters again 4
                [PhoneNumbers] => stdClass Object
                    (
                        [Home] => stdClass Object
                            (
                            )
                        [Primary] => stdClass Object
                            (
                            )
                        [Work] => stdClass Object
                            (
                            )
                    )
                [EmailAddresses] => stdClass Object
                    (
                        [Primary] => stdClass Object
                            (
                            )
                    )
                [Type] => Business
            )
    )
)

当我运行请求时,我会收到一条OK消息,但既没有存储电子邮件地址也没有存储电话号码,你能帮我解决我做错了什么吗?

链接到soap结构

最后我找到了如何做到这一点,这是添加电子邮件的行

"EmailAddresses" => array("Work" => array("Description" => "this is test","Name" =>"name",  "Value" => "dddd@gmail.com")),