我正在在线制作一个连接到肥皂网络服务的注册表单,并且应该能够通过它保存付款信息。 PHP是这样的
function create_member_fee()
{
$wsdl = 'WSDL LOCATION';
$client = new mySoap($wsdl, array('trace' => 1));
$request = array(
'obj'=>array(
'Member'=>array('Number'=>$NUMBER),
'Amount'=>$PRICE,
'CreditCard'=>array(
'TComboBox_ARCreditCardType'=>$_POST['CT'],
'CardNumber'=>$_POST['CN'],
'ExpDate'=>mktime(0,0,0,$_POST['CM'],1,$_POST['CY']),
'SSNumber'=>$NUMBER_PAYER
)
),
'opt'=>array('MemberAction'=>new SoapParam('_ActionInsert','ns1:TActionMethod'))
);
$result = $client->__call('CreateMemberFee',$request);
return $result;
}
这是 WSDL 函数和复杂类型。
<message name="CreateMemberFee85Request">
<part name="obj" type="ns1:TMemberFee"/>
<part name="opt" type="ns1:TMemberFeeOptions"/>
</message>
<xs:complexType name="TMemberFee">
<xs:sequence>
<xs:element name="Member" type="ns1:TMemberV2"/>
<xs:element name="Payer" type="ns1:TPerson"/>
<xs:element name="ItemCode" type="xs:string"/>
<xs:element name="Amount" type="xs:double"/>
<xs:element name="CreditCard" type="ns1:TCreditCard"/>
<xs:element name="Saleperson" type="xs:string"/>
<xs:element name="ContactName" type="xs:string"/>
<xs:element name="DiscountPercent" type="xs:double"/>
<xs:element name="ReductionPayment" type="xs:double"/>
<xs:element name="DiscountValidUntil" type="xs:dateTime"/>
<xs:element name="PaymentTerm" type="xs:string"/>
<xs:element name="PaymentMode" type="xs:string"/>
<xs:element name="Memo" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TMemberV2">
<xs:sequence>
<xs:element name="RecordID" type="xs:int"/>
<xs:element name="Number" type="xs:string"/>
<xs:element name="Name" type="xs:string"/>
<xs:element name="SSNumber" type="xs:string"/>
<xs:element name="Address1" type="xs:string"/>
<xs:element name="Address2" type="xs:string"/>
<xs:element name="Address3" type="xs:string"/>
<xs:element name="Address4" type="xs:string"/>
<xs:element name="ZipCode" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="CountryCode" type="xs:string"/>
<xs:element name="CountryName" type="xs:string"/>
<xs:element name="CountyCode" type="xs:string"/>
<xs:element name="Phone" type="xs:string"/>
<xs:element name="PhoneLocal" type="xs:string"/>
<xs:element name="PhoneMobile" type="xs:string"/>
<xs:element name="PhoneFax" type="xs:string"/>
<xs:element name="Telex" type="xs:string"/>
<xs:element name="Email" type="xs:string"/>
<xs:element name="Password" type="xs:string"/>
<xs:element name="Group" type="xs:string"/>
<xs:element name="Tag" type="xs:string"/>
<xs:element name="SalesPerson" type="xs:string"/>
<xs:element name="Discount" type="xs:double"/>
<xs:element name="ItemReceivers" type="ns1:ArrayOfItemReceiver"/>
<xs:element name="Contacts" type="ns1:ArrayOfContacts"/>
<xs:element name="PaymentType" type="xs:string"/>
<xs:element name="CurrencyCode" type="xs:string"/>
<xs:element name="NoVat" type="xs:boolean"/>
<xs:element name="LedgerCode" type="xs:string"/>
<xs:element name="RecordCreated" type="xs:dateTime"/>
<xs:element name="RecordModified" type="xs:dateTime"/>
<xs:element name="Blocked" type="xs:boolean"/>
<xs:element name="Dead" type="xs:boolean"/>
<xs:element name="Retierd" type="xs:boolean"/>
<xs:element name="Disabled" type="xs:boolean"/>
<xs:element name="Points" type="xs:double"/>
<xs:element name="BankCode" type="xs:string"/>
<xs:element name="BankAccGroup" type="xs:string"/>
<xs:element name="BankAccount" type="xs:string"/>
<xs:element name="MemberSubGroups" type="ns1:ArrayOfMemberSubGroups"/>
<xs:element name="Carrer" type="ns1:ArrayOfMemberCarrer"/>
<xs:element name="Membership" type="ns1:ArrayOfMemberMemberships"/>
<xs:element name="Education" type="ns1:ArrayOfMemberEducations"/>
<xs:element name="Applications" type="ns1:ArrayOfMemberApplication"/>
<xs:element name="Funds" type="ns1:ArrayOfMemberFunds"/>
<xs:element name="CreditCard" type="ns1:TCreditCard"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TPerson">
<xs:sequence>
<xs:element name="Number" type="xs:string"/>
<xs:element name="Name" type="xs:string"/>
<xs:element name="SSNumber" type="xs:string"/>
<xs:element name="Address1" type="xs:string"/>
<xs:element name="Address2" type="xs:string"/>
<xs:element name="Address3" type="xs:string"/>
<xs:element name="Address4" type="xs:string"/>
<xs:element name="ZipCode" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="CountryCode" type="xs:string"/>
<xs:element name="CountryName" type="xs:string"/>
<xs:element name="CountyCode" type="xs:string"/>
<xs:element name="Phone" type="xs:string"/>
<xs:element name="PhoneLocal" type="xs:string"/>
<xs:element name="PhoneMobile" type="xs:string"/>
<xs:element name="PhoneFax" type="xs:string"/>
<xs:element name="Email" type="xs:string"/>
<xs:element name="RecordCreated" type="xs:dateTime"/>
<xs:element name="RecordModified" type="xs:dateTime"/>
<xs:element name="Blocked" type="xs:boolean"/>
<xs:element name="Gender" type="ns1:TGender"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TCreditCard">
<xs:sequence>
<xs:element name="CardType" type="ns2:TComboBox_ARCreditCardType"/>
<xs:element name="CardNumber" type="xs:string"/>
<xs:element name="ExpDate" type="xs:dateTime"/>
<xs:element name="SSNumber" type="xs:string"/>
<xs:element name="Name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TMemberFeeOptions">
<xs:sequence>
<xs:element name="MemberAction" type="ns1:TActionMethod"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="TActionMethod">
<xs:restriction base="xs:string">
<xs:enumeration value="_ActionUse"/>
<xs:enumeration value="_ActionInsert"/>
<xs:enumeration value="_ActionEdit"/>
<xs:enumeration value="_ActionInsertEdit"/>
<xs:enumeration value="_ActionInsertMerge"/>
<xs:enumeration value="_ActionUseInsert"/>
</xs:restriction>
</xs:simpleType>
调用create_member_fee()时产生的错误是这样的
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no 'RecordID' property in...
我在 PHP 方面相对较新,我被要求在周末之前完成这项艰巨的任务,坦率地说,我不知所措,如果有人可以帮助并告诉我为什么会生成此错误,我将不胜感激。 $client->__getLastRequest() 不起作用,所以我不知道请求中的 xml 是什么样子,这让我的生活变得更加困难。
我刚刚解决了这个问题,这是一个使用对象而不是庞大且令人困惑的数组的问题。但是,您一定不要忘记按照 wsdl 中显示的方式准确映射对象。并且您必须为实例中的所有这些值赋值,如果为空,则只需使用 ''。这是我的代码。
class TMemberV2
{
public $RecordID;
public $Number;
public $Name;
public $SSNumber;
public $Address1;
public $Address2;
public $Address3;
public $Address4;
public $ZipCode;
public $City;
public $CountryCode;
public $CountryName;
public $CountyCode;
public $Phone;
public $PhoneLocal;
public $PhoneMobile;
public $PhoneFax;
public $Telex;
public $Email;
public $Password;
public $Group;
public $Tag;
public $SalesPerson;
public $Discount;
public $ItemReceivers;
public $Contacts;
public $PaymentType;
public $CurrencyCode;
public $NoVat;
public $LedgerCode;
public $RecordCreated;
public $RecordModified;
public $Blocked;
public $Dead;
public $Retierd;
public $Disabled;
public $Points;
public $BankCode;
public $BankAccGroup;
public $BankAccount;
public $MemberSubGroups;
public $Carrer;
public $Membership;
public $Education;
public $Applications;
public $Funds;
public $CreditCard;
}
class TCreditCard
{
public $CardType;
public $CardNumber;
public $ExpDate;
public $SSNumber;
public $Name;
}
class TMemberFee
{
public $Member;
public $Payer;
public $ItemCode;
public $Amount;
public $CreditCard;
public $Saleperson;
public $ContactName;
public $DiscountPercent;
public $DiscountValidUntil;
public $PaymentTerm;
public $PaymentMode;
public $Memo;
}
$member = new TMemberV2();
$member->RecordID = $id;
$member->Number = $kennitala;
$member->Name = $nafn;
$member->SSNumber = $kennitala;
$member->Address1 = $heimilisfang;
$member->Address2 = '';
$member->Address3 = '';
$member->Address4 = '';
$member->ZipCode = $postnumer;
$member->City = $sveitarfelag;
$member->CountryCode = 'IS';
$member->CountryName = 'Ísland';
$member->CountryCode = 'IS';
$member->Phone = $simanumer;
$member->PhoneLocal = '';
$member->PhoneMobile = $farsimi;
$member->PhoneFax = '';
$member->Telex = '';
$member->Email = $netfang;
$member->Password = '';
$member->Group = '';
$member->Tag = '';
$member->SalesPerson = '';
$member->Discount = '$';
$member->ItemReceivers = '';
$member->Contacts = '';
$member->PaymentType = 'test';
$member->CurrencyCode = '';
$member->NoVat = '';
$member->LedgerCode = '';
$member->RecordCreated = '';
$member->RecordModified = '';
$member->Blocked = '';
$member->Dead = '';
$member->Retierd = '';
$member->Disabled = '';
$member->Points = '';
$member->BankCode = '';
$member->BankAccGroup = '';
$member->BankAccount = '';
$member->MemberSubGroups = '';
$member->Carrer = '';
$member->Membership = '';
$member->Education = '';
$member->Applications = '';
$member->Funds = '';
$member->CreditCard = '';
$creditCard = new TCreditCard();
$creditCard->CardType = $_POST['CT'];
$creditCard->CardNumber = $_POST['CN'];
$creditCard->ExpDate = mktime(0,0,0,$_POST['CM'],1,$_POST['CY']);
$creditCard->SSNumber = $kt_forradamanns;
$memberFee = new TMemberFee();
$memberFee->Member = $member;
$memberFee->Payer = '';
$memberFee->ItemCode = '';
$memberFee->Amount = $namskeid_verd;
$memberFee->CreditCard = $creditCard;
$memberFee->Saleperson = '';
$memberFee->ContactName = '';
$memberFee->DiscountPercent = '';
$memberFee->ReductionPayment = '';
$memberFee->DiscountValidUntil = strtotime("now");
$memberFee->PaymentTerm = '';
$memberFee->PaymentMode = '';
$memberFee->Memo = '';
$wsdl = 'SOME WSDL';
$client = new mySoap($wsdl, array('trace' => 1));
$param = new SoapParam($memberFee, 'ns1:TMemberFee');
$param1 = new SoapParam('_ActionInsertEdit', 'ns1:TMemberFeeOptions');
$result = $client->__call('CreateMemberFee',array('obj'=>$param, 'opt'=>$param1));
将他声称的所有字段定义为“缺失财产”
因此,如果您使用的是数组,并且它说缺少属性“GetData”,请执行以下操作:
$requestArray['GetData'] = '';
每个字段依此类推,直到它正常工作。
无需声明类的最佳方法是使用 stdClass。为了使其正常工作,请保留对象和对象属性中的字段名称。
$TMemberFee = new stdClass();
$TMemberV2 = new stdClass();
...
$TMemberV2->RecordID = $id_holder_var;
...
$TMemberFee->Member = $TMemberV2;
...
这对我有用,我希望它对你有用。
我曾经对这样的错误感到困惑。事实证明,该属性并未在请求中丢失,而是在响应中丢失。错误消息不包含任何说明。
另请参阅 https://bugs.php.net/bug.php?id=50997 - 看起来您遇到了该错误 - 即 PHP 在不使用对象时似乎在序列方面存在问题。