获取Warframe市场的售价表,并进行排序,cn_name为物品中文名称,onlyMaxRank表示只取最高等级的物品,返回物品售价表,物品信息,物品英文
(cnName string, onlyMaxRank bool)
| 30 | |
| 31 | // 获取Warframe市场的售价表,并进行排序,cn_name为物品中文名称,onlyMaxRank表示只取最高等级的物品,返回物品售价表,物品信息,物品英文 |
| 32 | func getitemsorder(cnName string, onlyMaxRank bool) (od orders, it *itemsInSet, n string, err error) { |
| 33 | var wfapiio wfAPIItemsOrders |
| 34 | data, err := web.RequestDataWithHeaders(&http.Client{Transport: &http.Transport{ |
| 35 | TLSClientConfig: &tls.Config{ |
| 36 | MinVersion: tls.VersionTLS12, |
| 37 | }, |
| 38 | }}, fmt.Sprintf("https://api.warframe.market/v1/items/%s/orders?include=item", cnName), "GET", func(request *http.Request) error { |
| 39 | request.Header.Add("Accept", "application/json") |
| 40 | request.Header.Add("Platform", "pc") |
| 41 | return nil |
| 42 | }, nil) |
| 43 | if err != nil { |
| 44 | return |
| 45 | } |
| 46 | err = json.Unmarshal(data, &wfapiio) |
| 47 | if len(wfapiio.Payload.Orders) == 0 { |
| 48 | err = errors.New("no such name") |
| 49 | } |
| 50 | od = make(orders, 0, len(wfapiio.Payload.Orders)) |
| 51 | // 遍历市场物品列表 |
| 52 | for _, v := range wfapiio.Payload.Orders { |
| 53 | // 取其中类型为售卖,且去掉不在线的玩家 |
| 54 | if v.OrderType == "sell" && v.User.Status != "offline" { |
| 55 | if !onlyMaxRank { |
| 56 | od = append(od, v) |
| 57 | continue |
| 58 | } |
| 59 | if v.ModRank == wfapiio.Include.Item.ItemsInSet[0].ModMaxRank { |
| 60 | od = append(od, v) |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | // 对报价表进行排序,由低到高 |
| 65 | sort.Sort(od) |
| 66 | // 获取物品信息 |
| 67 | for i, v := range wfapiio.Include.Item.ItemsInSet { |
| 68 | if v.URLName == cnName { |
| 69 | it = &wfapiio.Include.Item.ItemsInSet[i] |
| 70 | n = v.En.ItemName |
| 71 | return |
| 72 | } |
| 73 | } |
| 74 | it = &wfapiio.Include.Item.ItemsInSet[0] |
| 75 | n = wfapiio.Include.Item.ItemsInSet[0].En.ItemName |
| 76 | return |
| 77 | } |
| 78 | |
| 79 | type wmdata struct { |
| 80 | wmitems map[string]items |