2 u014154100 u014154100 于 2016.03.23 11:58 提问

关于支付宝接口alipay.trade.precreate的签名,我总是验证错误
 private void pay() throws Exception{
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date=new Date();
        HttpURLConnection u=(HttpURLConnection) new URL(SettingEntiry.getOpenApiDomain()).openConnection();
        u.setRequestMethod("POST");
        u.setDoInput(true);
        u.setDoOutput(true);

        String sign=URLEncoder.encode(SignUtils.sign(Entity.inputEntity(SettingEntiry.getAPPID(),"ALIPAY.TRADE.PRECREATE","UTF-8","RSA",sdf.format(date),"1.0",BizContentEntiry.intputBizContentEntity("1000000","0.01","这是外卖")).toString2(),SettingEntiry.getPrivateKey()),"utf-8");

        PrintWriter pw=new PrintWriter(u.getOutputStream());
        pw.print(Entity.inputEntity(SettingEntiry.getAPPID(),"ALIPAY.TRADE.PRECREATE","UTF-8","RSA",sign.toUpperCase(),sdf.format(date),"1.0",BizContentEntiry.intputBizContentEntity("1000000","0.01","这是外卖")).toString());
        pw.flush();
        pw.close();

        System.out.println(URLEncoder.encode(SignUtils.sign("timestamp=2016-03-22%2018:05:30&method=alipay.trade.precreate&app_id=2015051100069126&sign_type=RSA&version=1.0&biz_content=%20{%20\"out_trade_no\":\"20150320010101001\",%20\"seller_id\":\"2088102146225135\",%20\"total_amount\":88.88,%20\"discountable_amount\":8.88,%20\"undiscountable_amount\":80,%20\"buyer_logon_id\":\"15901825620\",%20\"subject\":\"Iphone6%2016G\",%20\"body\":\"Iphone6%2016G\",%20\"goods_detail\":[{%20\"goods_id\":\"apple-01\",%20\"alipay_goods_id\":\"20010001\",%20\"goods_name\":\"ipad\",%20\"quantity\":1,%20\"price\":2000,%20\"goods_category\":\"34543238\",%20\"body\":\"特价手机\"%20}],%20\"operator_id\":\"yx_001\",%20\"store_id\":\"NJ_001\",%20\"terminal_id\":\"NJ_T_001\",%20\"extend_params\":{%20\"sys_service_provider_id\":\"2088511833207846\"%20},%20\"timeout_express\":\"90m\",%20\"royalty_info\":{%20\"royalty_type\":\"ROYALTY\",%20\"royalty_detail_infos\":[{%20\"serial_no\":1,%20\"trans_in_type\":\"userId\",%20\"batch_no\":\"123\",%20\"out_relation_id\":\"20131124001\",%20\"trans_out_type\":\"userId\",%20\"trans_out\":\"2088101126765726\",%20\"trans_in\":\"2088101126708402\",%20\"amount\":0.1,%20\"desc\":\"分账测试1\"%20}]%20}%20}",SettingEntiry.getPrivateKey()),"Utf-8"));
        System.out.println(Entity.inputEntity(SettingEntiry.getAPPID(),"ALIPAY.TRADE.PRECREATE","UTF-8","RSA",sign.toUpperCase(),sdf.format(date),"1.0",BizContentEntiry.intputBizContentEntity("1000000","0.01","这是外卖")).toString());
        System.out.println(sign);

        BufferedInputStream bis=new BufferedInputStream(u.getInputStream());
        byte[] b=new byte[32*1024];
        int r=0;
        while((r=bis.read(b))!=-1){
            System.out.println(new String(b,0,r));
        }
        bis.close();
    }

返回的是
{"ALIPAY_TRADE_PRECREATE_response":{"code":"40002","msg":"Invalid Arguments","sub_code":"isv.invalid-signature","sub_msg":"无效签名"},"sign":"pKAZjddvi+mJDIJnopTjVuwG3yoNc8JKW6HvjZ9v5GQ551NAhuIIJjL1cvAm6Llxxbjm9bYRNWRR0LJsXLaxYKzpymJNOZ0WcZtqcHmTaBzdII/G5boGLQaSl347pywft04Vb/0oeKBuEekqzPXQIma+iBXbK9GP0i5qghxTGHg="}

是签名算法的问题吗,我用的是支付宝demo WS_MOBILE_PAY_SDK_BASE里面看到 的签名算法

支付宝demo

我的程序:https://yunpan.cn/cYNsy3DbDib2Q (提取码:ae5b)

3个回答

gggidt
gggidt   2016.05.05 15:59

我的也是这个问题, 你的解决了吗?

gggidt
gggidt   2016.05.06 10:14

楼主,? 这个问题, 你是怎么解决的?

lovezwlhjj
lovezwlhjj 回复senjyuren: 楼主,请教下支付宝生成二维码字符串是哪个接口?入参是什么?我看了支付宝API文档有点蒙
一年多之前 回复
u014154100
u014154100 解决了,把post字段从a-z排序下就行了
一年多之前 回复
oudoud
oudoud   2016.06.22 15:12

支付宝有sdk已经封装好了,为何要自已实现?密钥不对

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!