$ res语言中的以下数据是从cURL输出的,我正在尝试使用它来使以下脚本正常工作。但是它根本不处理数据。我已经检查了它作为第一行的$ lines [0]具有成功。它应该输出其余数据,但不能输出。任何机构都对如何解决此问题有任何想法。还是因为我没有通过cURL处理数据来对此进行测试。在使脚本生效之前,我该如何使脚本完美运行。 cURL将数据从PayPal中抽取,因为pdt和PayPals沙箱被废弃了
$res = "SUCCESS
transaction_subject=Subscribe+to+Notary+Accounting
payment_date=16%3A29%3A09+May+24%2C+2014+PDT
txn_type=subscr_payment
subscr_id=S-01T86772CP0815034
last_name=Kurth
option_selection1=1+month
residence_country=US
item_name=Subscribe+to+Notary+Accounting
payment_gross=0.05
mc_currency=USD
business=rdkurth%40live.com
payment_type=instant
protection_eligibility=Ineligible
payer_status=unverified
payer_email=rich%40notaryaccounting.com
txn_id=94V17846W2603332N
receiver_email=rdkurth%40live.com
first_name=Richard
option_name1=Payment+options
payer_id=AAAE8FMAK2TH2
receiver_id=5GZ34FDY49A64
recur_times=4146841749
payment_status=Completed
payment_fee=0.05
mc_fee=0.05
btn_id=81809415
mc_gross=0.05
charset=windows-1252";
if(!$res){
//HTTP ERROR
}else{
// parse the data
$lines = explode("\n", $res);
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0) {
for ($i=1; $i<count($lines);$i++){
list($key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
$firstname = $keyarray['first_name'];
$lastname = $keyarray['last_name'];
$itemname = $keyarray['item_name'];
$amount = $keyarray['payment_gross'];
echo ("<p><h3>Thank you for your purchase!</h3></p>");
echo ("<b>Payment Details</b><br>\n");
echo ("<li>Name: $firstname $lastname</li>\n");
echo ("<li>Item: $itemname</li>\n");
echo ("<li>Amount: $amount</li>\n");
echo ("");
}
else if (strcmp ($lines[0], "FAIL") == 0) {
echo(' log for manual investigation');
}
}
最佳答案
这是一个已知的贝宝问题,您需要从第一条响应行中删除一些空白,如下所示:
if (strcmp (trim($lines[0]), "SUCCESS") == 0) {