Skip to content

(营销)图片上传

通过本接口上传图片后可获得图片url地址。图片url可在微信支付营销相关的API使用,包括商家券、代金券、支付有礼等。 官方文档

js
const { 
Multipart
} =
require
('wechatpay-axios-plugin')
const {
createReadStream
} =
require
('fs')
const {
basename
} =
require
('path')
const
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
.
marketing
.
favor
.
media
.
imageUpload
.
post
(
media
)
.
then
(
({
data
: {
media_url
,
}, }) => ({
media_url
,
}) )

Released under the MIT License. (SITEMAP)