teacat / shopeego

🛒 Shopee API v1 written in Golang
https://godoc.org/github.com/teacat/shopeego
MIT License
15 stars 15 forks source link

shopeego.GetOrderDetailsResponse.Orders接口报错 #13

Open pylist opened 3 years ago

pylist commented 3 years ago
panic: shopeego.GetOrderDetailsResponse.Orders: []shopeego.GetOrderDetailsResponseOrder: shopeego.GetOrderDetailsResponseOrder.ActualShippingCost: readNumberAsString: invalid number, error found in #10 byte of ...|ng_cost":"","estimat|..., bigger context ...|ss":"24****************"},"actual_shipping_cost":""
,"estimated_shipping_fee":"120","escrow_tax":"0",|...

這個錯誤有時間方便修復一下

YamiOdymel commented 3 years ago

有發生錯誤的 Trace Stack 函式呼叫路徑可以看嗎?看起來是 jsoniter "github.com/json-iterator/go" 出問題

如果你可以修改原始碼,將 shopeego.json 的 L18 行改回原生的 encoding/json 也許可以修復…?

pylist commented 3 years ago

encoding/json

如果使用原生的encodeing/json会提示panic: json: invalid use of ,string struct tag, trying to unmarshal "" into float64

YamiOdymel commented 3 years ago

感覺又跟 GetOrderDetails方法解析JSON失败 #6 問題有關,

在你的問題裡,看起來回應的 actual_shipping_cost 欄位是 ""

但照理來說他應該要被 patchFloat 修正成 "0" 避免 Golang 解析型態出錯,

因為這個關鍵字已經被加到 replaces.go 清單有一段時間了

可能要請你確認一下 patchFloat 那段在你的程式裡有沒有正常執行

pylist commented 3 years ago
func (s *ShopeeClient) patchFloat(body []byte) []byte {
    log.Println(string(body))
    replaceConcat := strings.Join(replaces, "|")
    for _, v := range replaces {
        body = []byte(strings.ReplaceAll(string(body), fmt.Sprintf(`"%s": ""`, v), fmt.Sprintf(`"%s": "0"`, v)))
    }
    log.Println("----------------------------------------------------------------")
    log.Println(string(body))
    var r = regexp.MustCompile(fmt.Sprintf(`"(%s)": ([^"].*?)(,|})`, replaceConcat))
    return []byte(r.ReplaceAllString(string(body), `"$1": "$2"$3`))
}

有被正常执行了, 我打印了log日志, 被替换后"actual_shipping_cost":""

pylist commented 3 years ago

现在返回json字符串里面没用空格了, 我把fmt.Sprintf("%s":"", v)的空格去掉了, actual_shipping_cost匹配的"0", 但是依旧报错, 我猜测可能不止这一个字段

hpcslag commented 3 years ago

Thanks @pylist,

I have found that Shopee API is changed, the serialized json raw is currently removed all of space of "key": "value" to "key":"value" by Shopee.

PR #14 is temporary solution for fix the regexp.

Maybe later we can match with json included <space> and non <space>.

YamiOdymel commented 3 years ago

合併了 https://github.com/teacat/shopeego/pull/14 到 v1.3.3 版本,

基本上是 @hpcslag 完成了 @pylist 的作法,

但 @pylist 表示還是一樣有問題 🤔?

pylist commented 3 years ago

去掉Weightstring标签暂时能够跑起来, 这个项目要放弃维护了嘛! 定义了太多struct, 虽然使用起来方便了一些, 但是也很多弊端

YamiOdymel commented 3 years ago

我先加上暫停維護,避免太多人掉入 Shopee 這恐怖的 API 坑,

但目前 @hpcslag 還有在使用,先前跟他聊過有機會的話他仍會繼續維護這個專案,

如果有要繼續維護的話,會跟他討論是不是要拿掉那個字樣 🤔

我也先把你加入貢獻者權限,能夠寫入這個 Repo,如果你有意願修整的話也可以考慮把那個字樣拿掉