Giter VIP home page Giter VIP logo

Comments (6)

mozillazg avatar mozillazg commented on June 3, 2024

我这边测试了一下,没问题。麻烦提供可以复现问题的最简代码。

from go-cos.

nEdAy avatar nEdAy commented on June 3, 2024

使用的是您的auth.go
authTime := NewAuthTime(defaultAuthExpire)
return c.String(http.StatusOK, newAuthorization(secretID, secretKey, req, authTime))

小程序测试返回403
SignatureDoesNotMatch
The Signature you specified is invalid.

官方wx_sdk生成的authorization 是ok的
var authorization = COS.getAuthorization({
SecretId: config.SecretId,
SecretKey: config.SecretKey,
Method: params.Method,
Key: params.Key
});

对比生成的authorization只有q-signature不同,是不是算法实现上有问题
我晚上再仔细看看

from go-cos.

nEdAy avatar nEdAy commented on June 3, 2024

小程序部分逻辑我是参照 https://github.com/piscium2010/cos-wx-upload-file
您可以试试

from go-cos.

carsonxu avatar carsonxu commented on June 3, 2024

qcloud 出的 demo 有这个:
https://github.com/tencentyun/cos-wx-sdk-v5

from go-cos.

nEdAy avatar nEdAy commented on June 3, 2024

官方只有js和php的鉴权服务

from go-cos.

mozillazg avatar mozillazg commented on June 3, 2024

@nEdAy 你可以用你的 bucket、secret_id、secret_key 测试一下上传功能:

export COS_BUCKET_URL=https://<bucket>-<appid>.cos.<region>.myqcloud.com
export COS_SECRETID=xx
export COS_SECRETKEY=xxx
go run _example/object/uploadFile.go

我刚测试了一下没发现问题:

$ go run _example/object/uploadFile.go
5636484
PUT /test%2fuploadFile.go HTTP/1.1
Host: test-1253846586.cos.ap-beijing-1.myqcloud.com
User-Agent: go-cos/0.8.0
Content-Length: 5636484
Authorization: q-sign-algorithm=sha1&q-ak=AKIDxnW4SdORtFPU1We7B5n7LShsjW7WpkZB&q-sign-time=1527723637;1527727237&q-key-time=1527723637;1527727237&q-header-list=content-length&q-url-param-list=&q-signature=b4f3aec6bf7ab01988f67af3d682af45898c3a76
Accept-Encoding: gzip



HTTP/1.1 200 OK
Content-Length: 0
Connection: keep-alive
Content-Type: application/xml
Date: Wed, 30 May 2018 23:40:49 GMT
Etag: "cf6dbd9a4353245fa98707b9a5cc2e63"
Server: tencent-cos
X-Cos-Request-Id: NWIwZjM2NzdfMmZiNTM1MGFfMzczNl8yMjY0MTQ=

初步判断可能是你的 req 中的 url 不是你实际想请求的 cos api url 。
如果你的 req 是小程序客户端发起的 req ,那你需要手动构造一个新的 http.Request,这个新的req 应该包含 cos api 需要的一些信息(url(key), header等)。

from go-cos.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.