测试的时候,PayPal一直返回invalid,求大神解答
public void ipn() throws IOException, DaoException {
String res ="";
Enumeration en = context.getRequest().getParameterNames();
String str = "cmd=_notify-validate";
while (en.hasMoreElements()) {
String paramName = (String) en.nextElement();
String paramValue = context.getRequest().getParameter(paramName);
str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue);
}
System.out.println(str);
URL u = new URL("https://www.sandbox.paypal.com/cgi-bin/webscr");
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()));
res = in.readLine();
in.close();
System.out.println(res);
// assign posted variables to local variables
String videoId = context.getRequest().getParameter("item_number");
String paymentAmount = context.getRequest().getParameter("mc_gross");
String paymentCurrency = context.getRequest().getParameter("mc_currency");
// check notification validation
if (res.equals("VERIFIED")) {
// check that paymentStatus=Completed
// check that txnId has not been previously processed
// check that receiverEmail is your Primary PayPal email
// check that paymentAmount/paymentCurrency are correct
// process payment
System.out.println("Success");
} else if (res.equals("INVALID")) {
// log for investigation
System.out.println("invalid Fail");
} else {
// error
System.out.println("Nothing");
}
}