【问题标题】:The value '2016-09-17' is invalid according to its datatype - how to fix?根据其数据类型,值“2016-09-17”无效 - 如何修复?
【发布时间】:2016-09-17 15:15:50
【问题描述】:

我正在使用 SOAP 将 API 集成到 E-conomic。此处列出了 SOAP 调用的文档:

https://api.e-conomic.com/secure/api1/EconomicWebService.asmx?op=CashBookEntry_CreateFromData

一切正常,除了使用 Date 参数时,我得到这个错误:

object(SoapFault)#3 (10) { ["message":protected]=> string(304) "Economic.Api.Exceptions.SchemaException(E00500): 'e-conomic.com:Date' 元素是无效 - 值“2016-09-17”根据其数据类型“w3.org/2001/XMLSchema:dateTime”无效 -字符串“2016-09-17”不是有效的 DateTime 值。(id=2bd3961a- 1c13-46c9-8b4c-5dacd58ac4d4)" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(34) "/Applications//index.php" ["line":protected]=> int(89) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(34) "/Applications//index.php" ["line"]=> int(89) [ "function"]=> string(6) "__call" ["class"]=> string(10) "SoapClient" ["type"]=> string(2) "->" ["args"]=> 数组(2) { [0]=> string(28) "CashBookEntry_CreateFromData" [1]=> array(1) { [0]=> array(1) { ["data"]=> array(10) { [" Type"]=> string(15) "CreditorPayment" ["CashBookHandle"]=> array(1) { ["Number"]=> int(1767) } ["Credito rHandle"]=> array(1) { ["Number"]=> int(6750) } ["ContraAccountHandle"]=> array(1) { ["Number"]=> int(6750) } ["Date" ]=> string(10) "2016-09-17" ["VoucherNumber"]=> int(1767) ["Text"]=> string(3) "API" ["AmountDefaultCurrency"]=> int(298) ["Amount"]=> int(298) ["CurrencyHandle"]=> array(1) { ["Code"]=> string(3) "DKK" } } } } } } ["previous":" Exception":private]=> NULL ["faultstring"]=> string(304) "Economic.Api.Exceptions.SchemaException(E00500): 'e-conomic.com:Date' 元素无效 - 值 '2016- 09-17' 根据其数据类型 '.w3.org/2001/XMLSchema:dateTime' 无效 - 字符串 '2016-09-17' 不是有效的 DateTime 值。 (id=2bd3961a-1c13-46c9-8b4c-5dacd58ac4d4)" ["faultcode"]=> string(11) "soap:Client" ["detail"]=> string(0) "" }

我在 SOAP 调用中传递了这个日期格式:

date("Y-m-d");

但它一直给我同样的错误。谁能看到我传递给电话的日期有什么问题?

【问题讨论】:

  • 你能View source 给我们看一个缩进的var_dump吗?
  • array(11) { ["Type"]=> string(15) "CreditorPayment" ["CashBookHandle"]=> array(1) { ["Number"]=> int(1767) } ["CreditorHandle"]=> array(1) { ["Number"]=> int(6750) } ["ContraAccountHandle"]=> array(1) { ["Number"]=> int(6750) } [ "日期"]=> 字符串(10) "2016-09-17" ["VoucherNumber"]=> int(1767) ["Text"]=> 字符串(3) "API" ["AmountDefaultCurrency"]=> int (298) ["Amount"]=> int(298) ["CurrencyHandle"]=> array(1) { ["Code"]=> string(3) "DKK" } ["CreditorInvoiceNumber"]=> string( 4)“1767”}
  • 你试过date("Y-m-d H:i:s"); 吗?
  • @jessie 是的,我试过了,还是一样的错误:'e-conomic.com:Date' 元素无效 - 值 '2016-09-17 17:22:32' 无效
  • 需要一个特定的格式(dateTime):w3.org/TR/xmlschema-2/#dateTime——用 PHP 的说法,格式是 Y-m-d\TH:i:sP 或使用 DATE_ATOM 常量(不是 DATE_8601 常量) .

标签: php soap


【解决方案1】:

问题已通过日期时间类修复:

$d = 新的 \DateTime();

$d->格式('c')

这为我们提供了标准的 W3 日期时间格式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多