将 xml 响应(来自 ZohoCRM)转换为简单的“key=value”使用 php 或 Zoho Creator 配对(对于 SurveyGizmo)
这涉及两个 Web 服务之间的数据交换。
我什至不知道从哪里开始。任何帮助、指示,甚至完整的解决方案:) 非常感谢。
我将用通俗易懂的语言描述...
SurveyGizmo 可以将数据发布(插入)到 ZohoCRM。
插入后,Zoho 将使用包含插入记录 ID 的 xml 响应进行响应。
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 是我需要以“Id=000000”形式返回到 Gizmo 的内容):
<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 解析器来将 ID 响应回显到发布 URL。
////
/////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;
This deals with exchanging data between two web services.
I'm stumped as to where to even start. Any assistance, pointers, or even complete solutions :) much appreciated.
I'll describe in plain language...
SurveyGizmo can post (insert) data to ZohoCRM.
After insert, Zoho responds with either an xml response that includes an ID of the inserted record.
Gizmo needs that ID for subsequent updates.
The problem is, Gizmo will only accept a response in a simple "key1=value1,key2=value2" format.
I'd like to have a php script on my server (or ZohoCreator deluge script) receive Gizmo's post, pass it through to ZohoCRM, receive the xml response from Zoho, convert it to key=value, and return it to Gizmo.
This is what Gizmo posts to 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>
This is what Zoho CRM responds after insert:
(the 00000 from Id is what I need to return to Gizmo as "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>
Thank you so much.
Below is a script I've been using elsewhere. I'm just not sure where to put the xml parser to echo the ID response back to the posting url.
////
/////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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在php中使用simplexml来读取并解析xml。如果您只需要检索 Id,您可以做的很简单:
您可以遍历整个 XML 结构。我建议您阅读文档: http://www.php.net/手册/en/book.simplexml.php
Use simplexml in php to read and parse the xml. If you just need to retrieve the Id, you can do as simple as:
You can traverse though the whole XML structure. I'd suggest you read the documentaion: http://www.php.net/manual/en/book.simplexml.php