fileuploader

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2021 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ImageUploadResponse

type ImageUploadResponse struct {
	MediaId *string `json:"media_id"`
}

ImageUploadResponse 图片上传API返回结果

type ImageUploader

type ImageUploader services.Service

ImageUploader 图片上传API

部分微信支付业务指定商户需要使用图片上传 API来上报图片信息,从而获得必传参数的值:图片MediaID 。 接口文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter2_1_1.shtml

func (*ImageUploader) Upload

func (u *ImageUploader) Upload(ctx context.Context, fileReader io.Reader, filename, contentType string) (*ImageUploadResponse, *core.APIResult, error)

Upload 上传图片至微信支付

Example
package main

import (
	"context"
	"os"

	"github.com/wechatpay-apiv3/wechatpay-go/core"
	"github.com/wechatpay-apiv3/wechatpay-go/core/consts"
	"github.com/wechatpay-apiv3/wechatpay-go/services/fileuploader"
)

func main() {
	var (
		ctx    context.Context
		client *core.Client
	)
	// 假设已获得初始化后的 core.Client

	file, err := os.Open("picture.jpg")
	if err != nil {
		return
	}
	defer file.Close()

	svc := fileuploader.ImageUploader{Client: client}
	resp, result, err := svc.Upload(ctx, file, "picture.jpg", consts.ImageJPG)

	// TODO: 处理返回结果
	_, _, _ = resp, result, err
}
Output:

type MarketingImageUploadResponse

type MarketingImageUploadResponse struct {
	MediaUrl *string `json:"media_url"`
}

MarketingImageUploadResponse 图片上传API(营销专用)返回结果

type MarketingImageUploader

type MarketingImageUploader services.Service

MarketingImageUploader 图片上传API(营销专用)

通过本接口上传图片后可获得图片url地址。图片url可在微信支付营销相关的API使用, 包括商家券、代金券、支付有礼等。 接口文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter9_0_1.shtml

func (*MarketingImageUploader) Upload

func (u *MarketingImageUploader) Upload(ctx context.Context, fileReader io.Reader, filename string, contentType string) (*MarketingImageUploadResponse, *core.APIResult, error)

Upload 上传图片至微信支付营销系统

Example
package main

import (
	"context"
	"os"

	"github.com/wechatpay-apiv3/wechatpay-go/core"
	"github.com/wechatpay-apiv3/wechatpay-go/core/consts"
	"github.com/wechatpay-apiv3/wechatpay-go/services/fileuploader"
)

func main() {
	var (
		ctx    context.Context
		client *core.Client
	)
	// 假设已获得初始化后的 core.Client

	file, err := os.Open("picture.jpg")
	if err != nil {
		return
	}
	defer file.Close()

	svc := fileuploader.MarketingImageUploader{Client: client}
	resp, result, err := svc.Upload(ctx, file, "picture.jpg", consts.ImageJPG)

	// TODO: 处理返回结果
	_, _, _ = resp, result, err
}
Output:

type MchBizUploadResponse

type MchBizUploadResponse struct {
	MediaId *string `json:"media_id"`
}

MchBizUploadResponse 商户上传反馈图片API返回结果

type MchBizUploader

type MchBizUploader services.Service

MchBizUploader 商户上传反馈图片API

将媒体图片进行二进制转换,得到的媒体图片二进制内容,在请求body中上传此二进制内容。 媒体图片只支持jpg、png、bmp格式,文件大小不能超过2M。 接口文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter10_2_10.shtml

func (*MchBizUploader) Upload

func (u *MchBizUploader) Upload(ctx context.Context, fileReader io.Reader, filename, contentType string) (*MchBizUploadResponse, *core.APIResult, error)

Upload 上传反馈图片至微信支付

Example
package main

import (
	"context"
	"os"

	"github.com/wechatpay-apiv3/wechatpay-go/core"
	"github.com/wechatpay-apiv3/wechatpay-go/core/consts"
	"github.com/wechatpay-apiv3/wechatpay-go/services/fileuploader"
)

func main() {
	var (
		ctx    context.Context
		client *core.Client
	)
	// 假设已获得初始化后的 core.Client

	file, err := os.Open("picture.jpg")
	if err != nil {
		return
	}
	defer file.Close()

	svc := fileuploader.MchBizUploader{Client: client}
	resp, result, err := svc.Upload(ctx, file, "picture.jpg", consts.ImageJPG)

	// TODO: 处理返回结果
	_, _, _ = resp, result, err
}
Output:

type VideoUploadResponse

type VideoUploadResponse struct {
	MediaId *string `json:"media_id"`
}

VideoUploadResponse 视频上传API返回结果

type VideoUploader

type VideoUploader services.Service

VideoUploader 视频上传API

部分微信支付业务指定商户需要使用视频上传 API来上报视频信息,从而获得必传参数的值:视频MediaID 。 接口文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter2_1_1.shtml

func (*VideoUploader) Upload

func (u *VideoUploader) Upload(ctx context.Context, fileReader io.Reader, filename, contentType string) (*VideoUploadResponse, *core.APIResult, error)

Upload 上传视频至微信支付

Example
package main

import (
	"context"
	"os"

	"github.com/wechatpay-apiv3/wechatpay-go/core"
	"github.com/wechatpay-apiv3/wechatpay-go/core/consts"
	"github.com/wechatpay-apiv3/wechatpay-go/services/fileuploader"
)

func main() {
	var (
		ctx    context.Context
		client *core.Client
	)
	// 假设已获得初始化后的 core.Client

	file, err := os.Open("video.mp4")
	if err != nil {
		return
	}
	defer file.Close()

	svc := fileuploader.VideoUploader{Client: client}
	resp, result, err := svc.Upload(ctx, file, "video.mp4", consts.VideoMP4)

	// TODO: 处理返回结果
	_, _, _ = resp, result, err
}
Output:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL