第三方api接口
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1年前
1年前
8 个月前
1年前
11 个月前
1年前
1年前
11 个月前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
8 个月前
1年前
8 个月前
1年前
8 个月前
1年前
8 个月前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. package taobao
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md"
  4. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  5. "encoding/json"
  6. "errors"
  7. "fmt"
  8. "github.com/syyongx/php2go"
  9. "strings"
  10. "time"
  11. "xorm.io/xorm"
  12. )
  13. //TaoBaoArgs is args
  14. type TaoBaoArgs struct {
  15. Keyword string
  16. PageIndex string
  17. PageSize string
  18. Sort string
  19. StartPrice string
  20. EndPrice string
  21. IsTmall string
  22. IsCoupon string
  23. StartCommissionRate string
  24. EndCommissionRate string
  25. }
  26. func TaoBaoFeaturedList(eg *xorm.Engine, dbName, Platform string, AccTaobaoShareId int, postData map[string]string) []map[string]string {
  27. var goods = make([]map[string]string, 0)
  28. sdk, err := NewTaobaoSDK(eg, dbName, Platform, AccTaobaoShareId, "")
  29. if err != nil {
  30. return goods
  31. }
  32. list, err := sdk.TaoBaoFeaturedList(postData)
  33. if list != nil {
  34. for _, v := range *list {
  35. var tmp = map[string]string{
  36. "gid": zhios_third_party_utils.AnyToString(v.ItemID),
  37. "title": v.Title,
  38. "img": v.PictURL,
  39. "sales": zhios_third_party_utils.IntToStr(v.Volume),
  40. "price": zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(v.ZkFinalPrice) - float64(v.CouponAmount)),
  41. "cost_price": v.ZkFinalPrice,
  42. "coupon": zhios_third_party_utils.IntToStr(v.CouponAmount),
  43. "commission_rate": zhios_third_party_utils.AnyToString(zhios_third_party_utils.StrToFloat64(v.CommissionRate) / 100),
  44. "commission": zhios_third_party_utils.Float64ToStr((zhios_third_party_utils.StrToFloat64(v.ZkFinalPrice) - float64(v.CouponAmount)) * (zhios_third_party_utils.StrToFloat64(v.CommissionRate) / 100 / 100)),
  45. "pvd": md.PVD_TB,
  46. "share_content": "",
  47. }
  48. goods = append(goods, tmp)
  49. }
  50. }
  51. return goods
  52. }
  53. func TaoBaoSearchList(eg *xorm.Engine, dbName, Platform string, AccTaobaoShareId int, postData map[string]string) []map[string]string {
  54. var goods = make([]map[string]string, 0)
  55. sdk, err := NewTaobaoSDK(eg, dbName, Platform, AccTaobaoShareId, "")
  56. if err != nil {
  57. return goods
  58. }
  59. list, err := sdk.TaoBaoSearchList(postData)
  60. if list != nil {
  61. for _, v := range *list {
  62. imgList := make([]string, 0)
  63. if len(v.SmallImages.String) == 0 {
  64. imgList = append(imgList, v.PictURL)
  65. } else {
  66. for _, v1 := range v.SmallImages.String {
  67. imgList = append(imgList, v1)
  68. }
  69. }
  70. var tmp = map[string]string{
  71. "img_list": zhios_third_party_utils.SerializeStr(imgList),
  72. "gid": zhios_third_party_utils.AnyToString(v.ItemID),
  73. "title": v.Title,
  74. "img": v.PictURL,
  75. "sales": zhios_third_party_utils.IntToStr(v.Volume),
  76. "price": zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(v.ZkFinalPrice) - zhios_third_party_utils.StrToFloat64(v.CouponAmount)),
  77. "cost_price": v.ZkFinalPrice,
  78. "coupon": v.CouponAmount,
  79. "commission_rate": zhios_third_party_utils.AnyToString(zhios_third_party_utils.StrToFloat64(v.CommissionRate) / 100),
  80. "commission": zhios_third_party_utils.Float64ToStr((zhios_third_party_utils.StrToFloat64(v.ZkFinalPrice) - zhios_third_party_utils.StrToFloat64(v.CouponAmount)) * (zhios_third_party_utils.StrToFloat64(v.CommissionRate) / 100 / 100)),
  81. "pvd": md.PVD_TB,
  82. "share_content": "",
  83. }
  84. goods = append(goods, tmp)
  85. }
  86. }
  87. return goods
  88. }
  89. // TaoBaoSearchList is return taobao search list
  90. func (t *TB) TaoBaoFeaturedList(args map[string]string) (*[]md.TBFeatureStruct, error) {
  91. list, err := t.FeaturedList(
  92. args,
  93. )
  94. if err != nil {
  95. return nil, err
  96. }
  97. return list, nil
  98. }
  99. func (t *TB) TaoBaoSearchList(args map[string]string) (*[]Material, error) {
  100. list, err := t.SearchList(
  101. args,
  102. )
  103. if err != nil {
  104. return nil, err
  105. }
  106. return list, nil
  107. }
  108. // 商品详情
  109. func (t *TB) ItemDetailById(id, bizSceneId string) (*Material, error) {
  110. if php2go.IsNumeric(id) {
  111. return t.ItemDetailByLink("https://item.taobao.com/item.htm?id="+id, "2")
  112. }
  113. return t.ItemDetailByLink("https://uland.taobao.com/item/edetail?id="+id, "")
  114. }
  115. func (t *TB) ItemDetailByLink(l, bizSceneId string) (*Material, error) {
  116. args := map[string]string{
  117. "q": l,
  118. "adzone_id": AdZoneId(t.SelfPromoIdWeb), // 默认使用安卓, 转链时候才要针对不同的渠道
  119. "session": t.SID,
  120. "page_size": "1",
  121. "page_no": "1",
  122. }
  123. if bizSceneId == "2" {
  124. args["biz_scene_id"] = "2"
  125. }
  126. method := TBK_DG_MTL_OPT
  127. //判断是否跟随官方 需要换接口
  128. if t.AuthType == 1 {
  129. method = TBK_SC_MTL_OPT
  130. Sid := t.UserSID
  131. args["session"] = Sid
  132. _, args["site_id"], args["adzone_id"] = SplitPid(t.SelfPromoIdWeb)
  133. }
  134. resp, err := send(args, method, t.Web_AK, t.Web_SK)
  135. if err != nil {
  136. return nil, err
  137. }
  138. fmt.Println("淘宝", args)
  139. fmt.Println("淘宝", string(resp))
  140. // todo 可能还需返回的说明, 里面包含详细介绍的图片
  141. // "https://mdetail.tmall.com/templates/pages/desc?id=" + id
  142. // "https://h5.m.taobao.com/app/detail/desc.html?type=1&f=&sellerType=B&_isH5Des=true#!id=" + id
  143. // 如果是跟随官方 结构不一样
  144. if t.AuthType == 1 {
  145. var tmp scTbkScMaterialOptionalUpgradeResponse
  146. if err = json.Unmarshal(resp, &tmp); err != nil {
  147. return nil, err
  148. }
  149. if len(tmp.TbkScMaterialOptionalUpgradeResponse.ResultList.MapData) == 0 {
  150. return nil, err
  151. }
  152. data := tmp.TbkScMaterialOptionalUpgradeResponse.ResultList.MapData[0]
  153. tmp1 := Material{
  154. CategoryID: data.ItemBasicInfo.CategoryId,
  155. CategoryName: data.ItemBasicInfo.CategoryName,
  156. CommissionRate: zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(data.PublishInfo.IncomeRate) * 100),
  157. ItemID: data.ItemId,
  158. Nick: data.ItemBasicInfo.ShopTitle,
  159. PictURL: data.ItemBasicInfo.PictUrl,
  160. SellerID: int(data.ItemBasicInfo.SellerId),
  161. ShopTitle: data.ItemBasicInfo.ShopTitle,
  162. ShortTitle: data.ItemBasicInfo.ShortTitle,
  163. Title: data.ItemBasicInfo.Title,
  164. ZkFinalPrice: data.PricePromotionInfo.ZkFinalPrice,
  165. ReservePrice: data.PricePromotionInfo.ReservePrice,
  166. Volume: data.ItemBasicInfo.Volume,
  167. UserType: data.ItemBasicInfo.UserType,
  168. TkTotalSales: zhios_third_party_utils.IntToStr(data.ItemBasicInfo.Volume),
  169. }
  170. tmp1.SmallImages = data.ItemBasicInfo.SmallImages
  171. if len(data.ItemBasicInfo.SmallImages.String) == 0 {
  172. tmp1.SmallImages.String = []string{tmp1.PictURL}
  173. }
  174. if zhios_third_party_utils.StrToFloat64(data.PricePromotionInfo.FinalPromotionPrice) > 0 {
  175. for _, v1 := range data.PricePromotionInfo.FinalPromotionPathList.FinalPromotionPathMapData {
  176. tmp1.CouponAmount = zhios_third_party_utils.Float64ToStrByPrec(zhios_third_party_utils.StrToFloat64(v1.PromotionFee)+zhios_third_party_utils.StrToFloat64(tmp1.CouponAmount), 2)
  177. tmp1.CouponStartTime = zhios_third_party_utils.IntToStr(zhios_third_party_utils.StrToInt(v1.PromotionStartTime) / 1000)
  178. tmp1.CouponEndTime = zhios_third_party_utils.IntToStr(zhios_third_party_utils.StrToInt(v1.PromotionEndTime) / 1000)
  179. tmp1.CouponID = v1.PromotionId
  180. if v1.PromotionTitle == "商品券" || v1.PromotionTitle == "店铺券" {
  181. if zhios_third_party_utils.StrToInt64(v1.PromotionEndTime)/1000 > time.Now().Unix() {
  182. tmp1.GoodsCoupon = "1"
  183. }
  184. }
  185. }
  186. }
  187. return &tmp1, nil
  188. } else {
  189. var tmp wrapperStruct
  190. if err = json.Unmarshal(resp, &tmp); err != nil {
  191. return nil, err
  192. }
  193. if len(tmp.TbkDgMaterialOptionalResponse.ResultList.MapData) == 0 {
  194. return nil, err
  195. }
  196. data := tmp.TbkDgMaterialOptionalResponse.ResultList.MapData[0]
  197. itemID, ok := data.ItemID.(float64)
  198. if ok {
  199. data.ItemID = int64(itemID)
  200. }
  201. return &data, nil
  202. }
  203. }
  204. func (t *TB) ItemDetailByIdKey(l, bizSceneId string) (*Material, error) {
  205. l += "&"
  206. l = strings.ReplaceAll(l, "?", "&")
  207. ex := php2go.Explode("&id=", l)
  208. id := ""
  209. if len(ex) > 1 {
  210. ex1 := php2go.Explode("&", ex[1])
  211. if len(ex1) > 0 {
  212. id = ex1[0]
  213. }
  214. }
  215. if id == "" || id == "622130940777" {
  216. return nil, errors.New("找不到商品")
  217. }
  218. args := map[string]string{
  219. "num_iids": id,
  220. "session": t.SID,
  221. "platform": "2",
  222. }
  223. if bizSceneId == "2" {
  224. //args["biz_scene_id"] = "2"
  225. }
  226. method := "taobao.tbk.item.info.get"
  227. //判断是否跟随官方 需要换接口
  228. if t.AuthType == 1 {
  229. Sid := t.UserSID
  230. args["session"] = Sid
  231. }
  232. resp, err := send(args, method, t.Web_AK, t.Web_SK)
  233. if err != nil {
  234. return nil, err
  235. }
  236. var tmp tbDetailStruct
  237. if err = json.Unmarshal(resp, &tmp); err != nil {
  238. return nil, err
  239. }
  240. if len(tmp.TbkItemInfoGetResponse.Results.NBbkItem) == 0 {
  241. return nil, err
  242. }
  243. data := tmp.TbkItemInfoGetResponse.Results.NBbkItem[0]
  244. data.ItemID = data.InputNumIid
  245. itemID, ok := data.ItemID.(float64)
  246. if ok {
  247. data.ItemID = int64(itemID)
  248. }
  249. return &data, nil
  250. }