Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何向请求的Http Header中添加信息? #17

Closed
lovebaonvwu opened this issue Mar 25, 2021 · 2 comments
Closed

如何向请求的Http Header中添加信息? #17

lovebaonvwu opened this issue Mar 25, 2021 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@lovebaonvwu
Copy link

lovebaonvwu commented Mar 25, 2021

”特约商户进件API“中要求

商户上送敏感信息时使用微信支付平台公钥加密,证书序列号包含在请求HTTP头部的Wechatpay-Serial,

请问可以从哪里进行这一步操作,向http header 中添加自定义的内容?
我在./lib/interceptor.js中找到的一部分代码

    config.headers = {
      ...config.headers,
      'User-Agent': utils.userAgent(),
      'Content-Type': `application/json`,
      Accept: `application/json`,
      // @see {fmt.authorization} APIv3 `Authorization` schema
      Authorization: fmt.authorization(mchid, nonce, signature, timestamp, serial),
    }

直接添加字段是可以的。

    config.headers = {
      ...config.headers,
      'User-Agent': utils.userAgent(),
      'Content-Type': `application/json`,
      Accept: `application/json`,
      // @see {fmt.authorization} APIv3 `Authorization` schema
      Authorization: fmt.authorization(mchid, nonce, signature, timestamp, serial),
      'wechatpay-serial': '1234567890',
    }

不过我如何在应用程序中做这个添加的动作?

        this.wxapi = new Wechatpay({
            mchid: '1270921201',
            serial: '623FFEC95EF4B583D2157DFE81E66FFA15DE88C3',
            certs: {
                '1C38E366EE3D40AF84E321A2B2A371B8CED57255': '-----BEGIN CERTIFICATE-----\n' + `...` + '\n-----END CERTIFICATE-----',
            },
            privateKey: '-----BEGIN PRIVATE KEY-----\n' + `...` + '\n-----END PRIVATE KEY-----',
        
        });

初始化的时候提供了平台证书,是否应该自己在需要的时候在interceptor.js中自行添加?
还是有其他的配置,可以在接口调用的时候通过配置来添加?
谢谢。

@TheNorthMemory
Copy link
Owner

#16 为例:

try {
  const result = await this.wxapi.v3.applyment4sub.applyment.$noop$({}, { noop: '', headers: { 'Wechatpay-Serial': '123456' } });
  return console.log(result);
} catch (err) {
  return console.error(err)
}

@TheNorthMemory TheNorthMemory added the documentation Improvements or additions to documentation label Mar 25, 2021
@lovebaonvwu
Copy link
Author

非常感谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants