- 真香:一行命令即可体验「微信支付」全系接口能力
你没看错,这款唯二的「Play the OpenAPI requests over command line」——「以命令行方式与微信支付接口交互」姗姗来了,旨在提供一种简洁高效的接入方式,希望能对开发者有所帮助。 nodejs版的 [代码]wechatpay-axios-plugin[代码] 已经进入[代码]v0.5[代码]版,v0.5做了这些改变: 全部代码(包括265条测试用例)使用 [代码]eslint-config-airbnb-base[代码] 代码风格校验; 使用 [代码]yargs[代码] 包替换了 [代码]commander[代码],重构了「平台证书下载器」工具,使其降级为此命令行一个特殊方法; 降级 [代码]form-data[代码] 及 [代码]yargs[代码] 包为 [代码]peerDependencies[代码],没有这俩包,90%+ 的接口是可以正常工作的,缩减依赖; 新增 [代码]bin/cli.js[代码],开发可以仅用一条命令就能跑得欢实不要不要的了; 使用 开始使用前,需要开发者自行安装[代码]cli[代码]模式依赖的npm包,即 [代码]npm i yargs[代码] 帮助手册 [代码]./node_modules/.bin/wxpay --help[代码] [代码]wxpay <command> Commands: wxpay crt The WeChatPay APIv3s Certificate Downloader wxpay req <uri> Play the OpenAPI requests over command line Options: --version Show version number [boolean] --help Show help [boolean] -u, --baseURL The baseURL [string] [default: "https://api.mch.weixin.qq.com/"] for more information visit "https://github.com/TheNorthMemory/wechatpay-axios-plugin" [代码] [代码]./node_modules/.bin/wxpay crt --help[代码] [代码]wxpay crt The WeChatPay APIv3s Certificate Downloader cert -m, --mchid The merchants ID. [string] [required] -s, --serialno The serial number. [string] [required] -f, --privatekey Path of the merchants private key certificate. [string] [required] -k, --key The secret key string of the merchants APIv3. [string] [required] -o, --output Path to output the platform certificate(s) [string] [default: "/tmp"] Options: --version Show version number [boolean] --help Show help [boolean] -u, --baseURL The baseURL [string] [default: "https://api.mch.weixin.qq.com/"] [代码] [代码]./node_modules/.bin/wxpay req --help[代码] [代码]wxpay req <uri> Play the WeChatPay OpenAPI requests over command line request <uri> -c, --config The configuration [required] -b, --binary Point out the response as `arraybuffer` [boolean] -m, --method The request HTTP verb [default: "POST"] -h, --headers Special request HTTP header(s) -d, --data The request HTTP body -p, --params The request HTTP query parameter(s) Options: --version Show version number [boolean] --help Show help [boolean] -u, --baseURL The baseURL [string] [default: "https://api.mch.weixin.qq.com/"] [代码] 证书下载 [代码]wxpay crt -m N -s S -f F.pem -k K -o .[代码] [代码]The WeChatPay Platform Certificate#0 serial=HEXADECIAL notBefore=Wed, 22 Apr 2020 01:43:19 GMT notAfter=Mon, 21 Apr 2025 01:43:19 GMT Saved to: wechatpay_HEXADECIAL.pem You may confirm the above infos again even if this library already did(by Rsa.verify): openssl x509 -in wechatpay_HEXADECIAL.pem -noout -serial -dates [代码] v3版Native下单 [代码]wxpay req v3/pay/transactions/native \ -c.mchid 1230000109 \ -c.serial HEXADECIAL \ -c.privateKey /path/your/merchant/mchid.key \ -c.certs.HEXADECIAL /path/the/platform/certificates/HEXADECIAL.pem \ -d.appid wxd678efh567hg6787 \ -d.mchid 1230000109 \ -d.description 'Image形象店-深圳腾大-QQ公仔' \ -d.out_trade_no '1217752501201407033233368018' \ -d.notify_url 'https://www.weixin.qq.com/wxpay/pay.php' \ -d.amount.total 100 \ -d.amount.currency CNY [代码] v3版查询订单 [代码]wxpay req v3/pay/transactions/id/1217752501201407033233368018 \ -c.mchid 1230000109 \ -c.serial HEXADECIAL \ -c.privateKey /path/your/merchant/mchid.key \ -c.certs.HEXADECIAL /path/the/platform/certificates/HEXADECIAL.pem \ -m get \ -p.mchid 1230000109 [代码] v3版关闭订单 [代码]wxpay req v3/pay/transactions/out-trade-no/1217752501201407033233368018 \ -c.mchid 1230000109 \ -c.serial HEXADECIAL \ -c.privateKey /path/your/merchant/mchid.key \ -c.certs.HEXADECIAL /path/the/platform/certificates/HEXADECIAL.pem \ -d.mchid 1230000109 [代码] v3版申请对账单 [代码]wxpay req v3/bill/tradebill \ -c.mchid 1230000109 \ -c.serial HEXADECIAL \ -c.privateKey /path/your/merchant/mchid.key \ -c.certs.HEXADECIAL /path/the/platform/certificates/HEXADECIAL.pem \ -m get \ -p.bill_date '2021-02-12' \ -p.bill_type 'ALL' [代码] v2版付款码付 [代码]wxpay req v2/pay/micropay \ -c.mchid 1230000109 \ -c.serial any \ -c.privateKey any \ -c.certs.any \ -c.secret your_merchant_secret_key_string \ -d.appid wxd678efh567hg6787 \ -d.mch_id 1230000109 \ -d.device_info 013467007045764 \ -d.nonce_str 5K8264ILTKCH16CQ2502SI8ZNMTM67VS \ -d.detail 'Image形象店-深圳腾大-QQ公仔' \ -d.spbill_create_ip 8.8.8.8 \ -d.out_trade_no '1217752501201407033233368018' \ -d.total_fee 100 \ -d.fee_type CNY \ -d.auth_code 120061098828009406 [代码] [代码]auth_code[代码] 输入配合扫码枪,体验就飞起来了~ v2版付款码查询openid [代码]wxpay req v2/tools/authcodetoopenid \ -c.mchid 1230000109 \ -c.serial any \ -c.privateKey any \ -c.certs.any \ -c.secret your_merchant_secret_key_string \ -d.appid wxd678efh567hg6787 \ -d.mch_id 1230000109 \ -d.nonce_str 5K8264ILTKCH16CQ2502SI8ZNMTM67VS \ -d.auth_code 120061098828009406 [代码] 设计 主程序 [代码]bin/cli.js[代码] 上,加入了一个中间件,代码如下: [代码].middleware((argv) => { if (argv.c && argv.c.privateKey && argv.c.privateKey !== 'any') { /* eslint-disable-next-line no-param-reassign */ argv.config.privateKey = readFileSync(argv.c.privateKey); } if (argv.c && argv.c.certs && Object.keys(argv.c.certs)[0] !== 'any') { /* eslint-disable-next-line no-return-assign, no-param-reassign, no-sequences */ argv.config.certs = Object.entries(argv.config.certs).reduce((o, [k, v]) => (o[k] = readFileSync(v), o), {}); } if (argv.c && argv.c.merchant) { if (argv.c.merchant.cert && argv.c.merchant.cert !== 'any') { /* eslint-disable-next-line no-param-reassign */ argv.config.merchant.cert = readFileSync(argv.c.merchant.cert); } if (argv.c.merchant.key && argv.c.merchant.key !== 'any') { /* eslint-disable-next-line no-param-reassign */ argv.config.merchant.key = readFileSync(argv.c.merchant.key); } if (argv.c.merchant.pfx && argv.c.merchant.pfx !== 'any') { /* eslint-disable-next-line no-param-reassign */ argv.config.merchant.pfx = readFileSync(argv.c.merchant.pfx); } } }, true) [代码] 其作用就是,把v3所需的证书以文件形式自动加载,供后续 [代码]cli/request.js[代码]方法直接使用,[代码]req[代码]方法核心代码也就10行! [代码]handler(argv) { const { baseURL, uri, config, method, data, params, headers, } = argv; const responseType = argv.binary ? 'arraybuffer' : undefined; const structure = [{ params, headers, responseType }]; if (data) { structure.unshift(data); } (new Wechatpay({ baseURL, ...config }))[uri][method](...structure) /* eslint-disable-next-line no-console */ .then(console.info).catch(console.error); }, [代码] 代码以 MIT 开放源码公开在 https://github.com/TheNorthMemory/wechatpay-axios-plugin ,如果喜欢,就来个 Star 。 后记 Q: 哇!这么简单? A: 不就是为了简单么。。。
2021-06-10 - 首页开发实战
带你实战腾讯课堂首页开发,详解布局王者flex。 本节结束代码:https://share.weiyun.com/5Eqz7TV [视频]
2021-11-26 - 小程序开发进阶之前端开发
4 节课,教你快速入门小程序前端。本系列视频,由腾讯课堂NEXT学院、微信学堂联合出品。
2021-12-14