u014154100
senjyuren
采纳率0%
2016-03-23 03: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条回答

  • oudoud oudoud 5年前

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

    点赞 评论 复制链接分享
  • gggidt gggidt 5年前

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

    点赞 评论 复制链接分享
  • gggidt gggidt 5年前

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

    点赞 评论 复制链接分享

为你推荐