Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加下载账单功能 #7

Closed
WalleV opened this issue Sep 5, 2021 · 1 comment
Closed

增加下载账单功能 #7

WalleV opened this issue Sep 5, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@WalleV
Copy link
Contributor

WalleV commented Sep 5, 2021

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

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

希望能够实现特性:

  • 使用Stream流下载,避免大文件账单直接全部读取导致内存占用过高。
  • 增加自动hash校验功能,如果因为被篡改或者网络错误原因导致hash不对直接抛错。

参考特性:

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",
})

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

@WalleV WalleV added the enhancement New feature or request label Sep 5, 2021
@Matrix-X
Copy link
Contributor

Matrix-X commented Sep 14, 2021

增加到功能 已提到 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 的文件校验

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants