wechatpay-apiv3 / wechatpay-go

微信支付 APIv3 的官方 Go Library
https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/index.shtml
Apache License 2.0
1.07k stars 145 forks source link

/v3/ecommerce/account/cancel-applications/media 图片Content-Type非法 #221

Closed githubzhaoqian closed 7 months ago

githubzhaoqian commented 7 months ago

/v3/ecommerce/account/cancel-applications/media 电商平台服务商调用注销申请接口时,需要先调用本接口上传相关的资料图片,获取图片ID后,再填写到注销申请请求中。 文档

func (c *ClientV3) CancelApplicationsMedia(ctx context.Context, fileName, fileSha256 string, img *gopay.File) (wxRsp *CancelApplicationsMediaRsp, err error) {
    bmFile := make(gopay.BodyMap)
    //bmFile.SetBodyMap("meta", func(bmFile gopay.BodyMap) {
    //  bmFile.Set("file_name", fileName).Set("file_digest", fileSha256)
    //})
    bmFile.Set("file_name", fileName).Set("file_digest", fileSha256)
    authorization, err := c.authorization(MethodPost, v3CancelApplicationsMedia, bmFile)
    if err != nil {
        return nil, err
    }
    bm := make(gopay.BodyMap)
    bm.SetBodyMap("meta", func(bm gopay.BodyMap) {
        bm.Set("file_name", fileName).Set("file_digest", fileSha256)
    }).SetFormFile("file", img)
    res, si, bs, err := c.doProdPostFile(ctx, bm, v3CancelApplicationsMedia, authorization)

}

按着文档修改了参数但是提示 {"code":"INVALID_REQUEST","message":"图片Content-Type非法"}试着其他修改也没有变化,也没看出来除参数外和其他上传有什么不同

githubzhaoqian commented 7 months ago
func TestCancelApplicationsMedia(t *testing.T) {
    fileName := "id_copy.jpg"
    fileContent, err := os.ReadFile("/Users/mac/Downloads/id_copy.jpg")
    if err != nil {
        logx.Error(err)
        return
    }
    h := sha256.New()
    h.Write(fileContent)
    sha256Str := hex.EncodeToString(h.Sum(nil))
    logx.Debug("sha256:", sha256Str)

    img := &gopay.File{
        Name:    fileName,
        Content: fileContent,
    }
    wxRsp, err := client.CancelApplicationsMedia(ctx, fileName, sha256Str, img)
    if err != nil {
        logx.Error(err)
        return
    }
    logx.Errorf("wxRsp:%v", wxRsp)
}

CancelApplicationsMedia换成包里的V3MediaUploadImage方法是可以成功的,也是复制V3MediaUploadImage方法改的CancelApplicationsMedia方法

githubzhaoqian commented 7 months ago

发错了