这涉及在两个Web服务之间交换数据。
我对哪里开始感到难过。任何帮助,指针,甚至完整的解决方案:)非常感谢。
我会用简单的语言描述......
SurveyGizmo可以将数据发布(插入)到ZohoCRM。
插入后,Zoho以xml响应进行响应,该响应包含插入记录的ID。
Gizmo需要该ID才能进行后续更新。
问题是,Gizmo只接受简单的“key1 = value1,key2 = value2”格式的响应。
我希望在我的服务器上有一个php脚本(或ZohoCreator deluge脚本)接收Gizmo的帖子,将其传递给ZohoCRM,从Zoho接收xml响应,将其转换为key = value,然后将其返回给Gizmo
这是Gizmo向ZohoCRM发布的内容:
https://crm.zoho.com/crm/private/xml/Cases/insertRecords?newFormat=2&apikey=KEYGOESHERE&ticket=TICKETGOESHERE&duplicateCheck=2&xmlData=
<Cases>
<row no="1">
<FL val="WHOID">contactidrelatedtocasebeinginserted</FL>
<FL val="Subject">mysubject</FL>
<FL val="Project">myproject</FL>
<FL val="Case Owner">myemail</FL>
</row>
</Cases>
这是Zoho CRM在插入后响应的内容:
(来自Id的00000是我需要返回Gizmo的“Id = 000000”):
<response uri="/crm/private/xml/Cases/insertRecords">
<result>
<message>Record(s) inserted successfully</message>
<recorddetail>
<FL val="Id">00000</FL>
<FL val="Created Time">2011-11-03 20:14:44</FL>
<FL val="Modified Time">2011-11-03 21:34:39</FL>
<FL val="Created By">
<![CDATA[ Bamboo ]]>
</FL>
<FL val="Modified By">
<![CDATA[ Bamboo ]]>
</FL>
</recorddetail>
</result>
</response>
下面是我在其他地方使用过的脚本。我只是不确定将xml解析器放回到发送URL的ID响应的位置。
////
/////note: the whole point of the script was to fix the hyphen to underscore in smtp-id so zoho would accept sendgrid
////
define('POSTURL', 'https://creator.zoho.com/api/xml/USERNAME/test/add/');
define('POSTVARS', ''); // POST VARIABLES TO BE SENT
// INITIALIZE ALL VARS
$event='';
$email='';
$response='';
$attempt='';
$url='';
$status='';
$reason='';
$type='';
$category='';
$zoho_email_id='';
$smtp_id='';
$timestamp='';
$ch='';
$Rec_Data='';
$Temp_Output='';
if($_SERVER['REQUEST_METHOD']==='POST') { // REQUIRE POST OR DIE
if(isset($_POST['event'])) $event=$_POST['event']; // GET event INTO VAR
if(isset($_POST['email'])) $email=$_POST['email']; // GET email INTO VAR
if(isset($_POST['response'])) $response=$_POST['response']; // GET response INTO VAR
if(isset($_POST['attempt'])) $attempt=$_POST['attempt']; // GET attempt INTO VAR
if(isset($_POST['url'])) $url=$_POST['url']; // GET url INTO VAR
if(isset($_POST['status'])) $status=$_POST['status']; // GET status INTO VAR
if(isset($_POST['reason'])) $reason=$_POST['reason']; // GET reason INTO VAR
if(isset($_POST['type'])) $type=$_POST['type']; // GET type INTO VAR
if(isset($_POST['category'])) $category=$_POST['category']; // GET category INTO VAR
if(isset($_POST['zoho_email_id'])) $zoho_email_id=$_POST['zoho_email_id']; // GET zoho_email_id INTO VAR
if(isset($_POST['smtp-id'])) $smtp_id=$_POST['smtp-id']; // GET smtp-id INTO VAR
if(isset($_POST['timestamp'])) $timestamp=$_POST['timestamp']; // GET timestamp INTO VAR
$ch = curl_init(POSTURL);
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS ,'apikey=APIKEY&zc_ownername=USERNAME&event='.$event.'&email='.$email.'&response='.$response.'&attempt='.$attempt.'&url='.$url.'&status='.$status.'&reason='.$reason.'&type='.$type.'&category='.$category.'&zoho_email_id='.$zoho_email_id.'&smtp_id='.$smtp_id.'×tamp='.$timestamp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL
$Rec_Data = curl_exec($ch);
ob_start();
header("Content-Type: text/html");
$Temp_Output = ltrim(rtrim(trim(strip_tags(trim(preg_replace ( "/\s\s+/" , " " , html_entity_decode($Rec_Data)))),"\n\t\r\h\v\0 ")), "%20");
$Temp_Output = ereg_replace (' +', ' ', trim($Temp_Output));
$Temp_Output = ereg_replace("[\r\t\n]","",$Temp_Output);
$Temp_Output = substr($Temp_Output,307,200);
echo $Temp_Output;
$Final_Out=ob_get_clean();
echo $Final_Out;
curl_close($ch);
} else die('Blah! That didn't work!');
exit;
答案 0 :(得分:1)
在php中使用simplexml来读取和解析xml。如果您只需要检索Id,您可以这样做:
$xml = simplexml_load_string($xml_string);
$response = 'Id='.$xml->result->recorddetail->FL;
您可以遍历整个XML结构。我建议您阅读文档:http://www.php.net/manual/en/book.simplexml.php