Giter Club home page Giter Club logo

Comments (3)

xy-peng avatar xy-peng commented on May 23, 2024 1

user-agent不用,有默认的。

accpet需要调用方主动设置,主要是账单下载的场景并非一定是application/json。

from wechatpay-apache-httpclient.

CrossLee avatar CrossLee commented on May 23, 2024

现在请求报401,是不是哪里设置有问题?
我用的这个代码:


try {
            PrivateKey merchantPrivateKeyObj = PemUtil.loadPrivateKey(
                    new ByteArrayInputStream(merchantPrivateKey.getBytes("utf-8")));

            //不需要传入微信支付证书,将会自动更新
            AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
                    new WechatPay2Credentials(merchantId, new PrivateKeySigner(merchantSerialNumber, merchantPrivateKeyObj)),
                    apiv3Secret.getBytes("utf-8"));

            WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create()
                    .withMerchant(merchantId, merchantSerialNumber, merchantPrivateKeyObj)
                    .withValidator(new WechatPay2Validator(verifier));

            HttpClient httpClient = builder.build();

            String jsonStr= JSON.toJSONString(pojo);
            logger.debug("jsonStr is : %s", jsonStr);

            HttpEntity entity = new ByteArrayEntity(jsonStr.getBytes());
            HttpPost post = new HttpPost(combinPayUrl);
            post.setEntity(entity);
            post.setHeader("Content-Type", "application/json");
            post.setHeader("Accept", "application/json");

            Header[] headers = post.getAllHeaders();
            logger.debug("headers length is %s", headers.length);
            for(Header header : headers) {
                logger.debug("post headers [%s=%s]",header.getName(), header.getValue());
            }

            HttpResponse response = httpClient.execute(post);
            result = response.toString();
            logger.debug(result);
        } catch (IOException e) {
            e.printStackTrace();
        }

请求返回:
HttpResponseProxy{HTTP/1.1 401 Unauthorized [Server: nginx, Date: Thu, 06 Aug 2020 05:20:56 GMT, Content-Type: application/json; charset=utf-8, Content-Length: 385, Connection: keep-alive, Keep-Alive: timeout=8, Cache-Control: no-cache, must-revalidate, X-Content-Type-Options: nosniff, Request-ID: atjy7o, Content-Language: zh-CN] ResponseEntityProxy{[Content-Type: application/json; charset=utf-8,Content-Length: 385,Chunked: false]}}

from wechatpay-apache-httpclient.

xy-peng avatar xy-peng commented on May 23, 2024

你把应答报文打印贴出来看看,里面有具体的错误码和错误消息

from wechatpay-apache-httpclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.