我想将xml请求作为php中的变量传递
我的xml请求看起来像
$XPost ="<ENVELOPE>
<HEADER>
<VERSION>1</VERSION>
<REQVERSION>1</REQVERSION>
<TALLYREQUEST>EXPORT</TALLYREQUEST>
<TYPE>COLLECTION</TYPE>
<SESSIONID>" .$session. "</SESSIONID>
<TOKEN>" .$token. "</TOKEN>
<ID>GetProfitnLossColl</ID>
</HEADER>
<BODY>
<DESC>
<STATICVARIABLES>
<SVCURRENTCOMPANY>" .$company. "</SVCURRENTCOMPANY>
<SVEXPORTFORMAT> $$SysName:XML </SVEXPORTFORMAT>
</STATICVARIABLES>
<TDL>
<TDLMESSAGE>
<COLLECTION NAME= \" GetProfitnLossColl \" ISMODIFY= \" No \" ISFIXED= \" No \" ISINITIALIZE= \" No \" ISOPTION= \" No \" ISINTERNAL= \" No \">
<TYPE>Group</TYPE>
<CHILDOF> Primary</CHILDOF>
<NATIVEMETHOD>parent, MasterID</NATIVEMETHOD>
<NATIVEMETHOD>BSDrClosing</NATIVEMETHOD>
<NATIVEMETHOD>BSCrClosing</NATIVEMETHOD>
<Method>VSPLName : $$Name</Method>
<Method>isGroup : $$IsGroup</Method>
<Method>cmpName : ##SVCurrentCompany</Method>
<Filters>CLDrBalNotZero</Filters>
</COLLECTION>
<SYSTEM TYPE= \" Formulae \" NAME= \" CLDrBalNotZero \" ISMODIFY= \" No \" ISFIXED= \" No \" ISINTERNAL= \" No \">$BSDrClosing != 0 Or $BSCrClosing != 0 </SYSTEM>
</TDLMESSAGE>
</TDL>
</DESC>
</BODY>
</ENVELOPE>";
我在php中使用此请求将Tally Server连接为
<?php
$response = array("error" => FALSE);
if(isset($_REQUEST['session1']) && isset($_REQUEST['token']) && isset($_REQUEST['company']) ){ //&& !empty($_POST['session1']) && !empty($_POST['token']) && !empty($_POST['company']) ){
$url = "https://dev1.tallyenterprise.com";
//$url = "https://tallynet.tallyenterprise.com";
$session = $_REQUEST['session1'];
$token = $_REQUEST['token'];
$company = $_REQUEST['company']; ///_POST['company'];
$XPost = "above xml request"
$headers = array();
$headers[] = 'ID:GETPROFITNLOSSCOLL'; //GetProfitnLossColl
$headers[] = 'SOURCE:VISIONSERVER';
$headers[] = 'TARGET: TALLY';
$headers[] = 'CONTENT-TYPE:text/xml;charset=utf-8';
$headers[] = 'Accept-Encoding:identity';
$headers[] = 'TARGETACCOUNTINTERNALID:201214173';
//$headers[] = 'TARGETCOMPANYNAME:Vision Solutions App';
$headers[] = 'TARGETCOMPANYNAME:'.$company;
// http://www.hackingwithphp.com/15/10/2/your-first-curl-scripts
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $XPost);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
$data = curl_exec($ch);
curl_close($ch);
echo $data;
}
else{
$response["error"] = TRUE;
$response["error_msg"] = "Required parameters (session or token) is missing!";
echo json_encode($response);
}
?>
它在浏览器中给我警告 注意:未定义的变量:第36行的C:\ wamp64 \ www \ VisionServer \ TallyPhp \ Req \ getProfitnLoss.php中的SysName
和Name,IsGroup,BSCrClosing
并作为无效请求回复
请帮帮我.....
答案 0 :(得分:0)
PHP正在解析$ SysName:XML作为变量。如果要发送文字字符串'$$ SysName:XML',则需要转义XML字符串中的每个美元符号,如下所示:
<SVEXPORTFORMAT> \$\$SysName:XML </SVEXPORTFORMAT>