收藏
回答

普通商户调用单次分账接口一直报错,使用工具校验签名是校验正确通过的,请问这是什么问题?

问题描述:

普通商户调用单次分账接口一直报错,使用工具校验签名是校验正确通过的,请问这是什么问题?请求需要双向证书,请问是我代码加载p12证书有问题吗?还是证书加载错误了?

错误提示:

{"chunked":false,"contentLength":476,"contentType":{"buffer":{"empty":false,"full":false},"elements":[{"name":"text/plain","parameterCount":1,"parameters":[{"name":"charset","value":"UTF-8"}]}],"name":"Content-Type","value":"text/plain;charset=UTF-8","valuePos":13},"repeatable":false,"streaming":true}

具体代码如下:

        // 调用请求单次分账接口必需传的参数        
        jsonArray.add(jsonObject);
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();     
        nvps.add(new BasicNameValuePair("appid",APPID));   //服务商商户号对应服务号的appid
        nvps.add(new BasicNameValuePair("mch_id",mchId));//服务商商户号
        nvps.add(new BasicNameValuePair("nonce_str",nonceStr));
        nvps.add(new BasicNameValuePair("out_order_no",profitSharingUuid));//商户系统内部的分账单号
        nvps.add(new BasicNameValuePair("receivers",jsonArray.toJSONString()));
        nvps.add(new BasicNameValuePair("transaction_id",profit.getTransaction_id()));
        StringBuffer sb = new StringBuffer();
        for (NameValuePair nvp : nvps) {
            sb.append(nvp.getName() + "=" + nvp.getValue() + "&");
        }
        String signA = sb.toString(); 
        String stringSignTemp = signA + "key="+apiV3Key; // key是服务商商户号的密钥  
        String sign = HMACSHA256(stringSignTemp, apiV3Key);//校验通过
        nvps.add(new BasicNameValuePair("sign", sign)); // 把签名后的数据组装成参数

        //加载P12证书并POST调用单次请求接口
        CloseableHttpResponse response=null;
        try {
            KeyStore clientStore = KeyStore.getInstance("PKCS12");
            // 读取本机存放的PKCS12证书文件
            FileInputStream inputStream =new FileInputStream(certPath);
            try {
            // 指定PKCS12的密码(商户ID)
                clientStore.load(inputStream, certPass.toCharArray());
            }finally {
                inputStream.close();
            }
            SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(clientStore,
                    certPass.toCharArray()).build();
            // 指定TLS版本
            SSLConnectionSocketFactory sslsf =new SSLConnectionSocketFactory(sslcontext, new
                    String[]{"TLSv1"}, null,
                    SSLConnectionSocketFactory.getDefaultHostnameVerifier());
            // 设置httpclient的SSLSocketFactory
            CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
            try {
                HttpPost httpost =new HttpPost(url); // 设置响应头信息
                httpost.addHeader("Connection", "keep-alive");
                httpost.addHeader("Accept", "*/*");
                httpost.addHeader("Content-Type", "text/xml");
                httpost.addHeader("X-Requested-With", "XMLHttpRequest");
                httpost.addHeader("Cache-Control", "max-age=0");
                httpost.addHeader("User-Agent", "*");
                httpost.setEntity(new StringEntity(data, "UTF-8"));
                 response = httpclient.execute(httpost);
            }finally {
                httpclient.close();
            }
   


回答关注问题邀请回答
收藏

2 个回答

  • Memory (私信不回复)
    Memory (私信不回复)
    2021-04-18

    你分账请求的哪个文档的接口,发一下,虽然V3接口当前可以打分账标识了,但是分账请求接口还是V2

    2021-04-18
    有用
    回复
  • peng
    peng
    2021-04-16

    这错误信息不是官方返回吧?

    java不知道怎么加载证书。。

    另外分账也不是v3key.

    2021-04-16
    有用
    回复 3
    • fikr
      fikr
      2021-04-16
      {"allHeaders":[{"buffer":{"empty":false,"full":false},"elements":[{"name":"nginx","parameterCount":0,"parameters":[]}],"name":"Server","value":"nginx","valuePos":7},{"buffer":{"empty":false,"full":false},"elements":[{"name":"Fri","parameterCount":0,"parameters":[]},{"name":"16 Apr 2021 11:32:12 GMT","parameterCount":0,"parameters":[]}],"name":"Date","value":"Fri, 16 Apr 2021 11:32:12 GMT","valuePos":5},{"buffer":{"empty":false,"full":false},"elements":[{"name":"text/plain","parameterCount":1,"parameters":[{"name":"charset","value":"UTF-8"}]}],"name":"Content-Type","value":"text/plain;charset=UTF-8","valuePos":13},{"buffer":{"empty":false,"full":false},"elements":[{"name":"476","parameterCount":0,"parameters":[]}],"name":"Content-Length","value":"476","valuePos":15},{"buffer":{"empty":false,"full":false},"elements":[{"name":"keep-alive","parameterCount":0,"parameters":[]}],"name":"Connection","value":"keep-alive","valuePos":11},{"buffer":{"empty":false,"full":false},"elements":[{"name":"timeout","parameterCount":0,"parameters":[],"value":"8"}],"name":"Keep-Alive","value":"timeout=8","valuePos":11},{"buffer":{"empty":false,"full":false},"elements":[{"name":"no-cache","parameterCount":0,"parameters":[]},{"name":"must-revalidate","parameterCount":0,"parameters":[]}],"name":"Cache-Control","value":"no-cache, must-revalidate","valuePos":14}],"entity":{"chunked":false,"contentLength":476,"contentType":{"$ref":"$.allHeaders[2]"},"repeatable":false,"streaming":true},"locale":"en","params":{"names":[]},"protocolVersion":{"major":1,"minor":1,"protocol":"HTTP"},"statusLine":{"protocolVersion":{"$ref":"$.protocolVersion"},"reasonPhrase":"OK","statusCode":200}}
      2021-04-16
      回复
    • fikr
      fikr
      2021-04-16
      名字是v3key而已我实际使用的是商户平台设置的密钥key;
      2021-04-16
      回复
    • fikr
      fikr
      2021-04-16
      官方返回的是这个,这种返回是不是说明自身post请求代码错误?
      2021-04-16
      回复
登录 后发表内容
问题标签