简体   繁体   English

如何将Webhook数据转换成查询字符串以由自定义php脚本读取?

[英]How to get webhook data into query string to be read by a custom php script?

I have a custom script in php that is intended to receive a webhook from a 3rd party CMS (specifically FLG360), search the source for records that match a given field name in the query string (using $_GET), and return/display the results. 我在php中有一个自定义脚本,该脚本旨在接收来自第三方CMS(特别是FLG360)的Webhook,在源中搜索与查询字符串中给定字段名称匹配的记录(使用$ _GET),然后返回/显示结果。

When going to the full URL (including the query string) manually, the query string is read by the script and the correct actions are performed. 手动进入完整的URL(包括查询字符串)时,脚本将读取查询字符串并执行正确的操作。

However, when sending the webhook from the CMS, it does not seem to be able to find or read the query string. 但是,从CMS发送Webhook时,似乎无法找到或读取查询字符串。

Here's the part of my script that I expected to be reading and actioning the webhook via simple $_GET requests: 这是我脚本的一部分,我希望通过简单的$ _GET请求来阅读和操作webhook:

$IDtoSearch = $_GET['company'];
$status = $_GET['status'];

Is pulling data from a webhook via php as simple as performing some $_GET requests? 通过php从webhook提取数据是否像执行一些$ _GET请求一样简单? I have confirmation from the CMS support team that the webhook is definitely formatted as a query string. 我已经CMS支持团队确认,Webhook的格式肯定是查询字符串。

I have added this to the script, in order to record any existing query string to the server's error log: 我已将此添加到脚本中,以便将任何现有查询字符串记录到服务器的错误日志中:

//capture the webhook and save to error log
$webhookContent = "";
$webhook = fopen('php://input' , 'rb');
while (!feof($webhook)) {
    $webhookContent .= fread($webhook, 4096);
}
fclose($webhook);
error_log($webhookContent);

...which is doing its job. ...正在做它的工作。 Here's what I find in the logs after firing a webhook from the CMS: 这是从CMS触发Webhook后在日志中找到的内容:

eventtype=workflow&eventdatetime=2016-07-29+15%3A16%3A06&eventuserid=&eventusername=&id=109355632&subid=&ipaddress=217.33.80.130&received=2016-06-17+15%3A50%3A37&leadgroupid=49625&leadgroupname=zzALEX+TEST+Applicants+collections&leadtype=FIDOR+Applicant&status=Pre+Default+Applicant+%2336731&progress=Accepted&siteid=16515&sitename=FIDOR+Applicant&userid=32197&username=Aimee+Davies&buyerid=&buyername=&buyerreference=&introducerid=46437&introducername=Alex+Test+cases&reference=&source=FIDOR&medium=&term=&cost=0.00&value=0.00&transferdatetime=0000-00-00+00%3A00%3A00&transfersuccessful=No&xmldatetime=0000-00-00+00%3A00%3A00&xmlfails=0&xmlresult=&xmlreference=&appointmentdatetime=&appointmentnotes=&lastnotedatetime=0000-00-00+00%3A00%3A00&lastnote=&taskexists=No&workflowexists=Yes&dropbox=l109355632.d675cdbf4f75f7d9c6ee99a6b7034b7c%40msrvr.net&fullname=Mr.+Alex+Connor&title=Mr.&firstname=Alex&lastname=Connor&company=TFS9876543&jobtitle=&phone1=&phone2=&fax=&email=&address=&address2=&address3 eventtype = workflow&eventdatetime = 2016-07-29 + 15%3A16%3A06&eventuserid =&eventusername =&id = 109355632&subid =&ipaddress = 217.33.80.130&received = 2016-06-17 + 15%3A50%3A37&leadgroupid = 49625&leadgroupname = zzALEX + TEST + Applicants + collections&leadtype = FIDOR +申请人&状态= Pre +默认+申请人+%2336731&progress =已接受&站点ID = 16515&站点名称= FIDOR +申请人&用户ID = 32197&用户名= Aimee + Davies&buyerid =&买方名称=&buyerreference =&introducerid = med&0.00 =&&== &value = 0.00&transferdatetime = 0000-00-00 + 00%3A00%3A00&transfersuccessful =否&xmldatetime = 0000-00-00 + 00%3A00%3A00&xmlfails = 0&xmlresult =&xmlreference =&appointmentdatetime =&appointmentnotes =&lastnotedatetime = 0000-00-00 + 00%3A %3A00&lastnote =&taskexists =否&workflowexists =是&dropbox = l109355632.d675cdbf4f75f7d9c6ee99a6b7034b7c%40msrvr.net&fullname = Mr. + Alex + Connor&title = Mr.&firstname = Alex&lastname = Connor&company = 2&fa = 2&fa = 2&fa = =&towncity=&postcode=&dob=&dobday=&dobmonth=&dobyear=&contacttime=&contactphone=Unknown&contactfax=Unknown&contactemail=Unknown&contactmail=Unknown&data1=&data2=&data3=&data4=&data5=&data6=&data7=&data8=&data9=&data10=&data11=&data12=&data13=&data14=&data15=&data16=&data17=&data18=&data19=&data20=&data21=&data22=&data23=&data24=&data25=&data26=&data27=&data28=&data29=&data30=&data31=&data32=&data33=&data34=&data35=&data36=&data37=&data38=&data39=&data40=&data41=&data42=&data43=&data44=&data45=&data46=&data47=&data48=&data49=&data50=&type1=Work+Telephone+Number&type2=TFS+Number&type3=Current+loan+balance&type4=Contracted+Monthly+Payment+Amount&type5=Last+payment+date+received&type6=Last+amount+received&type7=Next+scheduled+payment+date&type8=Current+Arrears+figure+incl+Legals%2FCharges&type9=Current+Payment+method&type10=Guarantor+is+deceased&type11=Guarantor+has+entered+DMP%2FBKO%2FIVA+&type12=Spare&type13=Actual+receipts+to+date&type14=Applicant+flat+number&type15=Applicant+house+name =&towncity =&postcode =&dob =&dobday =&dobmonth =&dobyear =&contacttime =&contactphone = Unknown&contactfax = Unknown&contactemail = Unknown&contactmail = Unknown&data1 =&data2 =&data3 =&data4 =&data5 =&data6 =&data7 =&data8 =&data9 =&data9 =&data = 9 =&data15 =&data16 =&data17 =&data18 =&data19 =&data20 =&data21 =&data22 =&data23 =&data24 =&data25 =&data26 =&data27 =&data28 =&data29 =&data30 =&data31 =&data32 =&data33 =&data33 =&data34 =&data35 =&data36 =&data37 =&data37 =&data38 = =&data40 =&data41 =&data42 =&data43 =&data44 =&data45 =&data46 =&data47 =&data48 =&data49 =&data50 =&type1 =工作+电话+电话号码&类型2 = TFS +号码&类型3 =当前+贷款+余额&类型4 =合同+每月+付款+金额+金额&类型5 = L +付款+日期+已接收&类型6 =最后+金额+已接收&类型7 =下一个+预定的+付款+日期&类型8 =当前+欠款+数字+含+法律+%2FCharges&类型9 =当前+付款+方法和类型10 =担保人+是+已故&类型11 =担保人+已+ DMP%2FBKO%2FIVA +&type12 =备件&type13 =实际+收据+至+ date&type14 =申请人+单位+编号&type15 =申请人+房屋+名称 &type16=Applicant+house+number&type17=Guarantor+relationship+to+main+applicant&type18=Guarantor+First+Name&type19=Guarantor+Last+Name&type20=Joint+App+First+Name&type21=Joint+App+Last+Name&type22=Applicant+has+entered+DMP%2FBKO%2FIVA&type23=Current+Vienna+Status&type24=Solicitors&type25=Legal+Status&type26=Number+of+Months+in+Arrears&type27=Promise+To+Pay+DATE+%28dd%2Fmm%2Fyyyy%29&type28=Promise+To+Pay+AMOUNT&type29=Loan+Final+payment+date+%28dd%2Fmm%2Fyyyy%29&type30=Agreement+signed+date+%28FOR+DEFAULT%29+-+dd%2Fmm%2Fyyyy&type31=Default+expiry+date+%28dd%2Fmm%2Fyyyy%29&type32=Less+Rebate+of+interest+%28amount+from+settlement+letter%29&type33=Sum+Required+to+repay+loan+%28Amount+from+settlement+letter%29&type34=Default+ISSUED+date+%28dd%2Fmm%2Fyyyy%29&type35=Arrangement+Amount&type36=Arrangement+Start+Date+%28dd%2Fmm%2Fyyyy%29&type37=Arrangement+Type&type38=Arrangement+Term&type39=Arrangement+Monthly+Shortfall&type40=spare&type41=spare&type42=spare&type43=spare&type44=spare&type45=DMP% &type16 =申请人+房屋+编号&类型17 =担保人+关系+至+主要+申请人+类型18 =担保人+名字+名称&类型19 =担保人+姓氏+名称&类型20 =联合+应用程序+姓氏+名称&类型21 =联合人+应用程序+姓氏+名称+类型22 =申请人+ has +输入的+ DMP%2FBKO%2FIVA&type23 =当前+维也纳+状态&类型24 =律师和类型25 =法律+状态&类型26 =数量+月数+中+欠款和类型27 =承诺+至+付款+日期+日期+%28dd%2Fmm%2Fyyyy%29&类型28 =承诺+ Pay + AMOUNT&type29 =贷款+最终+付款+日期+%28dd%2Fmm%2Fyyyy%29&type30 =协议+签名+日期+%28FOR + DEFAULT%29 +-++ dd%2Fmm%2Fyyyy&type31 =默认+到期+日期+%28dd%2Fmm% 2Fyyyy%29&type32 =减+返利+利息+%28金额+来自+结算+信%29&type33 =总和+要求+偿还+贷款+贷款+%28金额+来自+结算+信%29&type34 =默认值+发行+日期+%28dd% 2Fmm%2Fyyyy%29&type35 =安排+金额&类型36 =安排+开始+日期+%28dd%2Fmm%2Fyyyy%29&type37 =安排+类型&类型38 =安排+期限&类型39 =安排+类型+每月+短缺&类型40 =备件&类型= 44 =备件&类型41 =备件&类型41 =备用 2FIVA+offer+of+Repayment&type46=Reasons+for+Arrears&type47=OFS+LETTER+3+DATE+%28dd%2Fmm%2Fyyyy%29&type48=IBC+Referance&type49=Restriction+or+Charging+order&type50=IMPORTANT+NOTES 2FIVA +要约+还款和类型46 =原因+欠款和欠款&类型47 = OFS +字母+ 3 + DATE +%28dd%2Fmm%2Fyyyy%29&type48 = IBC + Referance&type49 =限制+或+收费+订单+类型50 =重要+注释

All the information from the CMS record seems to be coming in, just not being read or recognised as a query string by my script. CMS记录中的所有信息似乎都进入了,只是我的脚本没有读取或将其识别为查询字符串。

Here's what I get when manually entering a query string on the URL: 这是在URL上手动输入查询字符串时得到的信息:

, referer: https://www.domain.com/flg/index.php/?company=cream&status=cheese

Not sure what the ", referer:" part means, or why this error is being logged with the full URL as opposed to the above. 不知道“,引荐来源:”部分的含义是什么,或者不确定为什么使用完整URL(而不是上面的URL)记录此错误。

Hope somebody can help with this, I'm tearing my hair out. 希望有人能帮上忙,我正在撕头发。

Please let me know if you need any additional information. 如果您需要任何其他信息,请告诉我。

Many thanks. 非常感谢。

您可以在$ webhookContent上使用parse_str()

Credit to @Aleksej in the comments for this - it was as simple as changing the GET to POST. 为此,请在评论中使用@Aleksej-就像将GET更改为POST一样简单。 Problem solved, the script is now doing its job. 问题已解决,脚本现在正在执行其工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM