ArtisanCloud / PowerWeChat

PowerWechat是一款基于WeChat SDK for Golang,支持小程序、微信支付、企业微信、公众号等全微信生态
https://powerwechat.artisan-cloud.com
MIT License
1.35k stars 173 forks source link

增加下载账单功能 #7

Closed WalleV closed 3 years ago

WalleV commented 3 years ago

微信文档: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_8.shtml

因为申请交易账单申请资金账单只是返回一个download_urlhash,所以需要再封装一个download接口。

希望能够实现特性:

参考特性:

paymentService.Bill.Download("your/path/to/file-2021-09-01.csv", &power.HashMap{
   "download_url": "https://api.mch.weixin.qq.com/v3/billdownload/file?token=6XIv5TUPto7pByrTQKhd6kwvyKLG2uY2wMMR8cNXqaA_Cv_isgaUtBzp4QtiozLO",
  "hash_type": "SHA1",
  "hash_value": "8823044c286bea726f149bfcfce0b0318122d755",
})

基于上一个申请账单的数据,再下载可避免协程之间并发导致的数据冲突。

Matrix-X commented 3 years ago

增加到功能 已提到 feature/payment分支


// 下载账单API为通用接口,交易/资金账单都可以通过该接口获取到对应的账单
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_8.shtml
func APIBillDownloadURL(c *gin.Context) {

    requestDownload := &response.RequestDownload{
        "SHA1",
        "442c2363a7e014b7f7cf3e2c558375bcf385951d",
        "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg",
    }
    homePath, _ := os.UserHomeDir()
    filePath := path.Join(homePath, "Desktop/download-url")

    rs, err := services.PaymentService.Bill.DownloadBill(requestDownload, filePath)
    if err != nil {
        panic(err)
    }
    c.JSON(http.StatusOK, rs)

}

目前只做了,支持 sha1 的文件校验