代码娱乐者
2017-06-21 10:23
采纳率: 81.3%
浏览 2.4k
已采纳

沙盒paypal在线支付成功后返回非法参数invalid

测试的时候,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");
    }

}
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 代码娱乐者 2017-11-27 09:09
    已采纳

    后来发现是PayPal的账户设置不正确

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • qq_34021602 2017-11-30 08:34

    我沙盒的时候返回是正确的,但正式充值时,一直返回invalid,请问你的paypal账户是什么设置问题呢?

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题