hpyer / node-easywechat

EasyWeChat for Node.js
MIT License
123 stars 16 forks source link

3.x 模式微信支付如何使用.p12证书 #53

Closed ValueLan closed 6 months ago

hpyer commented 6 months ago

发送post请求的时候,第二个参数增加httpsAgent就行,参考 axios 的配置

示例代码:

const app = new Pay({});
const client = app.getClient();
const res = await client.post('/xxx', {
  xml: {},
  httpsAgent: {
    pfx: Fs.readFileSync('/path/to/cert'),
    passphrase: app.getConfig().get('mch_id'),
  },
})
ValueLan commented 6 months ago
const app = new Pay({});
app.getMerchant().getCertificate()
这些信息就没法获取了,
能否加个配置,主要有点菜 
hpyer commented 6 months ago

为啥要获取证书信息?请求的时候是会自动计算签名的,不需要开发者去自行计算的

ValueLan commented 6 months ago

我试试

ValueLan commented 6 months ago
    const app = new Pay({
      mch_id: 'xxx', // 商户ID
      secret_key: 'xxxxx', 
      v2_secret_key: "xxx",
    });
  app.getClient()  这一行就报错了
hpyer commented 6 months ago

还要配置 certificateprivate_key 这两个商户证书的,填绝对路径就行

如果要用 v3 的支付API的话,还要配置 secret_keyplatform_certs,platform_certs 要用工具下载,工具地址:下载工具:https://github.com/wechatpay-apiv3/CertificateDownloader

参考php版的文档:https://easywechat.com/6.x/pay/index.html

ValueLan commented 6 months ago

微信支付调用V2 /pay/unifiedorder 返回是XML,需要自己解析成object吗 resp.toObject() 我看了下底层实现 is('xml') == false 导致无法解析xml /pay/unifiedorder 返回头如下

{
  server: 'nginx',
  date: 'Sat, 16 Dec 2023 15:36:20 GMT',
  'content-type': 'text/plain',
  'content-length': '456',
  connection: 'close',
  'cache-control': 'no-cache, must-revalidate',
  'x-content-type-options': 'nosniff',
  'request-id': '08F487F7AB0610DD0518A3D4EEA30620DEFA2228FA5D-0, 08F487F7AB0610D40518E0DAEEA30620CB990628C8CA05-0'
} 
hpyer commented 6 months ago

已修复,更新到 v3.5.6

ValueLan commented 6 months ago

我在使用v2 版本的时候,是可以直接用p12证书的 但是V3版本无法使用,按照咱们方法也无法使用 能否新增个字段