Paypal IPN消息格式很奇怪,其中空格是“&”,@变成“%40”等等,我不知道你称之为那种格式。
我尝试替换这样的字符:
var set0 = receipt.split('&').join(',&');
var set1 = set0.replace(/&/g,'\n');
var set2 = set1.replace(/%40/g,'@');
var set3 = set2.replace(/%2C/g,',');
var set4 = set3.replace(/%3A/g,':');
var set5 = set4.split('+').join(' ');
var set6 = set5.split('=').join(': ');
var test = JSON.parse(JSON.stringify(set6));
console.log(test);
我通过替换这些字符得到了我想要的确切安排:
amount1: 1.00,
amount3: 14.99,
address_status: confirmed,
subscr_date: 17:41:18 Aug 07, 2016 PDT,
payer_id: NZKP3G9KN3Y5G,
address_street: 1 Main St,
mc_amount1: 1.00,
mc_amount3: 14.99
但问题是我无法得到值说:
console.log(test.amount1);
它表示无效。请指教,谢谢。
这是我从Paypal沙箱获得的样本IPN Post back:
amount1=1.00&amount3=14.99&address_status=confirmed&subscr_date=17%3A41%3A18+Aug+07%2C+2016+PDT&payer_id=NZKP3G9KN3Y5G&address_street=1+Main+St&mc_amount1=1.00&mc_amount3=14.99&charset=windows-1252&address_zip=95131&first_name=test&reattempt=1&address_country_code=US&address_name=test+buyer¬ify_version=3.8&subscr_id=I-LYDJAAW6R5J0&custom=QuQHkL8EQ2XLYD6Tz&payer_status=verified&business=billing-facilitator%40testmail.com&address_country=United+States&address_city=San+Jose&verify_sign=AiPC9BjkCyDFQXbSkoZcgqH3hpacAm05VARKo4Q3kMeDNMwELG8cel.7&payer_email=billing-buyer-2%40testmail.com&btn_id=3394935&last_name=buyer&address_state=CA&receiver_email=billing-facilitator%40testmail.com&recurring=1&txn_type=subscr_signup&item_name=Premium+with+Trial&mc_currency=USD&residence_country=US&test_ipn=1&period1=1+D&period3=1+M&ipn_track_id=1e857dd5b422e
我使用替换方法(上面的代码)来获得所需的格式。