我构建了一个 IPN 侦听器来验证 PayPal 通知。所有通知都验证良好,当参数 item_name 具有特殊字符时例外。项目名称示例:“Um mes”
我曾尝试在一些字符集中对 url 进行编码,但没有人工作。如果我删除 item_name 的特殊字符,IPN 验证将返回 VALID,但是当只放置一个简单的特殊字符时,我总是得到 INVALID 作为返回。
在执行请求之前我必须使用什么正确的编码?
这是我的代码:` public void verificaIPN(FacesContext fc) throws FalseINPException, IOException { ExternalContext externalContext = fc.getExternalContext(); 迭代器 requestParameterNames = externalContext .getRequestParameterNames();
String requestUrl = Messages.getString("PayPalUtil.paypalURL"); //$NON-NLS-1$
while (requestParameterNames.hasNext()) {
String chave = requestParameterNames.next();
String valor = externalContext.getRequestParameterMap().get(chave);
//is this below right?
requestUrl += "&" + chave + "=" + URLEncoder.encode(valor, "UTF-8");
}
URL urlConPayPal = new URL(requestUrl);
URLConnection yc = urlConPayPal.openConnection();
yc.setDoOutput(true);
yc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
if (inputLine.equals("VERIFIED")) {
} else {
throw new FalseINPException("O paypal não confirma esta transação: "
+ inputLine);
}
}
in.close();
}