支付宝接口

1.抱空指针错误
java.lang.NullPointerException
at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:89)
at com.alipay.sign.RSA.decrypt(RSA.java:100)
原因很诡异 有时候是长度问题
我看了一下 是因为执行2次decrypt原因
看支付宝提供的DEMO里面的notify_url.jsp
第44行
Map<String,String> decrypt_params = AlipayNotify.decrypt(params); 

第59行
	if(AlipayNotify.verifyNotify(params))

在verifyNotify里面也是调用了
if(AlipayConfig.sign_type.equals("0001")) {
    params = decrypt(params);
    }

所以我对这个进行修改 只用
String out_trade_no = AlipayNotify.verifyNotify(params); 修改这个方法让他返回订单号 方便后面修改订单付款状态
2.mysign和sign不相等
注意第一点// 交易安全检验码,由数字和字母组成的32位字符串
    // 如果签名方式设置为“MD5”时,请设置该参数
    public static String key = "";

问题已解决,demo的有问题.那个AlipayCore类的createLinkStringNoSort没什么用的
Map<String, String> sParaSort = new HashMap<String, String>();
        sParaSort.put("service", params.get("service"));
        sParaSort.put("v", params.get("v"));
        sParaSort.put("sec_id", params.get("sec_id"));
        sParaSort.put("notify_data", params.get("notify_data"));
for (String key : sParaSort.keySet()) {
             prestr = prestr + key + "=" + sParaSort.get(key) + "&";
}
prestr = prestr.substring(0,prestr.length()-1);


把for里面的自己重组装一下
prestr = prestr + "service" + "=" + params.get("service") + "&";
         prestr = prestr + "v" + "=" + params.get("v") + "&";
         prestr = prestr + "sec_id" + "=" + params.get("sec_id") + "&";
         prestr = prestr + "notify_data" + "=" + params.get("notify_data") + "&";

3.添加支付宝安全支付功能时候,遇到以下问题:
java.security.InvalidKeyException:IOException: algid parse error, not a sequence
出现这种错误,
It means your key is not in PKCS#8 format. The easiest thing to do is to use the openssl pkcs8 -topk8 <...other options...> command to convert the key once. Alternatively you can use the PEMReader class of the Bouncycastle lightweight API.

原来是openssl生成密钥后,没有转换成PKCS8格式,而直接用密钥..所以导致了;

猜你喜欢

转载自gghaomm.iteye.com/blog/1973576