$res中的以下数据是cURL的输出,我试图使用它来使以下脚本工作。但它根本不处理数据。我已经检查过了,$lines[0]作为第一行有SUCCESS。它应该输出其余的数据,但它没有。任何人有任何想法,如何解决这个问题。还是因为我没有通过cURL处理数据来测试它。我想让剧本工作完美之前,我让它直播。cURL从PayPal提取数据作为pdt,而PayPal的沙盒是垃圾
$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');
}
}
这是一个已知的paypal问题,你需要从第一个响应行删除一些空白,像这样:
if (strcmp (trim($lines[0]), "SUCCESS") == 0) {