微信支付对接(nodejs)

1. 微信支付对接

  1.1 准备工作:

  以公司名义申请商户账号,需要获取到如下信息

    • appid: 应用id
    • mchid: 商户id
    • private_key: 私钥证书(apiclient_key.pem)
    • serial_no: 证书序列号,通过命令 openssl x509 -in apiclient_cert.pem -noout -serial  即可查看序列号
    • apiv3_private_key: 私钥

  1.2 安装nodejs SDK

    npm intall wxpay-v3 -S

  1.3 使用  

const Payment = require('wxpay-v3');

const paymnet = new Payment({
    appid: '应用id',
    mchid: '商户id',
    private_key: require('fs').readFileSync('*_key.pem证书文件路径').toString(),//或者直接复制证书文件内容
    serial_no:'证书序列号',
    apiv3_private_key:'api v3密钥',
    notify_url: '支付退款结果通知的回调地址',
})

   下单:

  

const result = await payment.native({
    description:'商品名称',
    out_trade_no:Date.now().toString(),
    amount:{
        total:1
    }
})
console.log(result)    


  其他接口请查看:https://www.npmjs.com/package/wxpay-v3

 

posted @ 2024-07-12 14:55  学海无涯学吧  阅读(345)  评论(0)    收藏  举报