2
我有一個用於PayPal IPN消息的Java接收器,它在沙箱中完美工作。但是,在將其設置爲真正的Paypal環境後,我注意到它獲得了大部分消息的「INVALID」響應(儘管一些付款獲得了VERIFIED響應)。我有認爲它可能是一個編碼問題。我讀到編碼出現在正確的消息中(我已經看到它有一個叫做「charset」的參數)和其他地方的編碼應該設置爲「windows-1252」。所以我正在從正確的消息中讀取字符集,並用該字符集編碼參數。在所有收到的編碼信息中都是「windows-1252」,但只有少數的響應爲「VERIFIED」(其餘均無效)。如果我重新發送帳戶中的IPN歷史記錄中的「無效」消息,它們將再次被視爲無效。對PayPal中的一些IPN消息的INVALID響應
Doe任何人都知道可能發生什麼?
謝謝。
String paypalURL = "https://www.paypal.com/cgi-bin/webscr";
// read post from PayPal system and add 'cmd'
Enumeration en = request.getParameterNames();
String str = "cmd=_notify-validate";
String charset = request.getParameter("charset"); //this gets windows-1252
while(en.hasMoreElements()){
String paramName = (String)en.nextElement();
String paramValue = request.getParameter(paramName);
str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue, charset);
}
// post back to PayPal system to validate
// NOTE: change http: to https: in the following URL to verify using SSL (for increased security).
// using HTTPS requires either Java 1.4 or greater, or Java Secure Socket Extension (JSSE)
// and configured for older versions.
URL u;
u = new URL(paypalURL);
URLConnection uc = u.openConnection();
uc.setDoOutput(true);
uc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
PrintWriter pw = new PrintWriter(uc.getOutputStream());
pw.println(str);
pw.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(uc.getInputStream()));
String res = in.readLine(); //It's always INVALID - It should be "VERIFIED"
in.close();
// assign posted variables to local variables
//String itemName = request.getParameter("item_name");
//String itemNumber = request.getParameter("item_number");
//String quantity = request.getParameter("quantity");
String paymentStatus = request.getParameter("payment_status");
String paymentAmount = request.getParameter("mc_gross");
String paymentCurrency = request.getParameter("mc_currency");
String txnId = request.getParameter("txn_id");
String receiverEmail = request.getParameter("receiver_email");
//String payerEmail = request.getParameter("payer_email");
String username = request.getParameter("custom");
//check notification validation
if(res.equals("VERIFIED")) { //It's always INVALID - It should be "VERIFIED"