我正在尝试使用业务中心 POST API 将从 PHP 网页收到的付款状态更新到业务中心。
这是我正在尝试的代码:
<?php
$username="username";
$password="password";
$url="API_URL";
$postData = '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<UpdateSalesOrderPaymentStatus xmlns="urn:microsoft-dynamics-schemas/codeunit/WebServiceUpdate">
<sONo>101007</sONo>
</UpdateSalesOrderPaymentStatus>
</Body>
</Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"Authorization: Basic ".base64_encode("$username:$password")
);
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => $headers,
'content' => $postData
)
));
$response = file_get_contents($url, false , $context);
if($response === FALSE){
die('Error');
}
else
{
echo $response;
}
我得到一个带有 to 框的空白页。当我执行检查元素时,页面有一些 XML 内容作为代码。
我已经在 Chrome 中尝试了带有 Wizdler 扩展的 API,它运行良好。但是,如果我尝试使用邮递员使用相同的 API,它会返回相同的 XML 内容作为输出。
输出XML内容如下:
<definitions targetNamespace="urn:microsoft-dynamics-schemas/codeunit/WebServiceUpdate" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:microsoft-dynamics-schemas/codeunit/WebServiceUpdate">
<types>
<schema elementFormDefault="qualified" targetNamespace="urn:microsoft-dynamics-schemas/codeunit/WebServiceUpdate" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="UpdateSalesOrderPaymentStatus">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="sONo" type="string"/>
</sequence>
</complexType>
</element>
<element name="UpdateSalesOrderPaymentStatus_Result">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="return_value" type="string"/>
</sequence>
</complexType>
</element>
</schema>
</types>
<message name="UpdateSalesOrderPaymentStatus">
<part name="parameters" element="tns:UpdateSalesOrderPaymentStatus"/>
</message>
<message name="UpdateSalesOrderPaymentStatus_Result">
<part name="parameters" element="tns:UpdateSalesOrderPaymentStatus_Result"/>
</message>
<portType name="WebServiceUpdate_Port">
<operation name="UpdateSalesOrderPaymentStatus">
<input name="UpdateSalesOrderPaymentStatus" message="tns:UpdateSalesOrderPaymentStatus"/>
<output name="UpdateSalesOrderPaymentStatus_Result" message="tns:UpdateSalesOrderPaymentStatus_Result"/>
</operation>
</portType>
<binding name="WebServiceUpdate_Binding" type="tns:WebServiceUpdate_Port">
<binding transport="http://schemas.xmlsoap.org/soap/http" xmlns="http://schemas.xmlsoap.org/wsdl/soap/"/>
<operation name="UpdateSalesOrderPaymentStatus">
<operation soapAction="urn:microsoft-dynamics-schemas/codeunit/WebServiceUpdate:UpdateSalesOrderPaymentStatus" style="document" xmlns="http://schemas.xmlsoap.org/wsdl/soap/"/>
<input name="UpdateSalesOrderPaymentStatus">
<body use="literal" xmlns="http://schemas.xmlsoap.org/wsdl/soap/"/>
</input>
<output name="UpdateSalesOrderPaymentStatus_Result">
<body use="literal" xmlns="http://schemas.xmlsoap.org/wsdl/soap/"/>
</output>
</operation>
</binding>
<service name="WebServiceUpdate">
<port name="WebServiceUpdate_Port" binding="tns:WebServiceUpdate_Binding">
<address location="https://api.businesscentral.dynamics.com/v2.0/e95a69fe-37bd-407a-a394-45d3aa91f45a/Sandbox/WS/Hickey%20Metal%20Fabrication/Codeunit/WebServiceUpdate?tenant=msocna4832t93425692&aid=FIN" xmlns="http://schemas.xmlsoap.org/wsdl/soap/"/>
</port>
</service>
</definitions>
请帮助我在哪里做错了,我是第一次与业务中心 API 交互。
提前致谢。