php soap client添加信息

时间:2016-05-18 18:05:34

标签: php soap

尝试向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消息,但是电子邮件地址或电话号码都没有存储,你能帮我解决我做错的事吗?

Link to the soap structure

1 个答案:

答案 0 :(得分:0)

最后我发现了如何做,这是添加电子邮件的行

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