代码娱乐者 2017-06-21 10:23 采纳率: 50%
浏览 2404
已采纳

沙盒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的账户设置不正确

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条