Skip to content

商户图片上传

部分微信支付业务指定商户需要使用图片上传API来上报图片信息,从而获得必传参数的值:图片MediaID 。 官方文档

js
const { 
Multipart
} =
require
('wechatpay-axios-plugin')
const {
createReadStream
} =
require
('fs')
const {
basename
} =
require
('path');
let
localFilePath
= '/path/to/merchant-image-file.jpg'
const
stream
=
createReadStream
(
localFilePath
)
const
media
= new
Multipart
()
.
append
('meta',
JSON
.
stringify
({
filename
:
basename
(
localFilePath
),
sha256
: 'from upstream or local calculated',
})) .
append
('file',
stream
,
basename
(
localFilePath
))
wxpay
.
v3
.
merchant
.
media
.
upload
.
post
(
media
)
.
then
(
({
data
: {
media_id
,
}, }) => ({
media_id
,
}) )

Released under the MIT License. (SITEMAP)