处理来自cURL的数据输出

时间:2014-05-25 21:57:30

标签: php paypal

$ res语言中的以下数据是从cURL输出的,我正在尝试使用它来使以下脚本工作。但它根本不处理数据。我已经检查过$ lines [0]作为第一行有SUCCESS。它应该输出其余的数据,但它没有。任何机构都有任何想法如何解决这个问题。或者是因为我没有通过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');
    }
}

1 个答案:

答案 0 :(得分:1)

它是一个已知的贝宝问题,您需要从第一个响应行中删除一些空格,如下所示:

if (strcmp (trim($lines[0]), "SUCCESS") == 0) {
相关问题