第三方api接口
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

216 rindas
8.8 KiB

  1. package taobao
  2. import (
  3. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  4. "fmt"
  5. "net/url"
  6. "sort"
  7. "strings"
  8. "time"
  9. )
  10. /*
  11. sc 代表服务商, 工具商
  12. dg 代表推广者, 站长
  13. 工具商: 为站长服务, 当站长有些权限不足登陆时候, 例如:授权登陆等,可以使用工具商的服务, 工具商每次调用淘宝必须传入站长的session,以便于区分不同站长
  14. 站 长: 在一般情况下可以使用自己的自己的key, 包括物料搜索等
  15. 邀请码: 用于区分不同的渠道, 淘宝不同渠道有不同的邀请链接, 例如:渠道管理, 会员运营管理 这两种
  16. 推广位: 用于区分不同的位置, 不同推广位区分如IOS,android,web,applet不同
  17. */
  18. const (
  19. // 淘宝基础host
  20. TB_HOST_HTTP = "http://gw.api.taobao.com/router/rest?"
  21. TB_HOST_HTTPS = "https://eco.taobao.com/router/rest?"
  22. // TODO 物料id查找 https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10628875?_k=gpov9a
  23. // 淘宝业务, op for operation 操作, tbk for taobaoke,
  24. TBK_SC_MTL_OPT = "taobao.tbk.sc.material.optional.upgrade" // 淘宝客-服务商-物料搜索
  25. TBK_DG_MTL_OPT = "taobao.tbk.dg.material.optional.upgrade" // 淘宝客-推广者-物料搜索
  26. TB_SVC_AK = "33970476"
  27. TB_SVC_SK = "2d46abef05a0d05d7ddcd3af2d540d2b"
  28. TB_SVC_TIME = "2022-08-09 10:58:00"
  29. )
  30. type TB struct {
  31. // 站长web key, 用于查询订单,搜索等
  32. SID string
  33. UserSID string //用户的session
  34. Web_AK string
  35. Web_SK string
  36. User_Web_AK string
  37. User_Web_SK string
  38. // 服务商 service key, 如智盟, SVC = service 授权服务
  39. Svc_AK string
  40. Svc_SK string
  41. Svc_SID string
  42. // 渠道 - 分享(会员外)
  43. ShareInviteCode string // 邀请码,用户获取relationId,用于分享
  44. SharePromoIdIOS string // 分享推广位, IOS , APP Key时可用
  45. SharePromoIdAndroid string // 分享推广位, ANDROID , APP Key时可用
  46. SharePromoIdWeb string // 分享推广位, web , Web Key时可用
  47. CloudPromoIdWeb string // 分享推广位, web , Web Key时可用
  48. // 渠道 - 自购(会员)
  49. SelfInviteCode string // 邀请码,用户获取specialId,用于自购
  50. SelfPromoIdIOS string // 自购推广位, IOS , APP Key时可用
  51. SelfPromoIdAndroid string // 自购推广位, ANDROID , APP Key时可用
  52. SelfPromoIdWeb string // 自购推广位, web , Web Key时可用
  53. // 新人免单等推广位
  54. SelfPromoIdFree string // 免单推广位
  55. SelfPromoIdTljFree string // 免单淘礼金推广位
  56. SelfPromoIdTljRelationFree string // 免单淘礼金渠道推广位
  57. ActivitySelfPromoIdWeb string //活动的自购推广位
  58. ActivitySharePromoIdWeb string //活动的分享推广位
  59. WechatActivitySelfPromoIdWeb string //小程序活动的自购推广位
  60. WechatActivitySharePromoIdWeb string //小程序活动的分享推广位
  61. WebRelationSelfKey string //渠道网站自购
  62. AndroidRelationSelfKey string //渠道安卓自购
  63. IosRelationSelfKey string //渠道ios自购
  64. wechatSelfKey string //小程序自购
  65. AuthType int //返回授权类型用来判断
  66. AuthBuyType string //判断用哪种授权模式 纯渠道 或 会员+渠道 主要是转链不同
  67. ChannelUrl string //渠道邀请码
  68. ShareChannelUrl string //渠道邀请码
  69. AppletIsAuth string
  70. AppletPid string
  71. }
  72. // 旧
  73. // TB_AUTH_AK = "26302019" // 授权ak
  74. // TB_AUTH_SK = "ba877cfcdc64d3fbc1105d61d66dd1d7" // 授权sk
  75. // TB_AUTH_SID = "6202812d3c107786820ace47c9200f0cf7093e213f8ed45199979191" // 可以通过智盟获得
  76. // TB_AUTH_INVITER_CODE = "CAGGTZ"
  77. // TB_AK = "23430885" //业务ak
  78. // TB_SK = "8c90c716181852cabaabc8dc1bf59a23" //业务sk
  79. // TB_SID = "6201603b382ZZd3bc3f1737478521e8ae243a3245cbe6bd199979191" // 业务sid
  80. // TB_PID = "mm_13406079_15484476_59718997" // 业务PID
  81. // TB_ACC_ID = "13406079"
  82. // TB_SITE_ID = "15484476"
  83. // TB_ADZONE_ID = "59718997"
  84. func New(tb *TB) *TB {
  85. if tb != nil {
  86. return tb
  87. }
  88. return &TB{
  89. Web_AK: "23430885", // third_taobao_web_ak
  90. Web_SK: "8c90c716181852cabaabc8dc1bf59a23", // third_taobao_web_sk
  91. SID: "6200d02d5aceeec70abb05983156d4b8b4bf78cd6d8df69199979191", // third_taobao_sid
  92. Svc_AK: "26302019", // third_taobao_svc_ak
  93. Svc_SK: "ba877cfcdc64d3fbc1105d61d66dd1d7", // third_taobao_svc_sk
  94. Svc_SID: "6200f110dca5586962fhjf512d05f0cb731d43045fdd460199979191", // third_taobao_svc_sid
  95. ShareInviteCode: "CAGGTZ", //third_taobao_share_invite_code
  96. SharePromoIdIOS: "mm_13406079_36674309_97353600076", // third_taobao_share_pid_ios
  97. SharePromoIdAndroid: "mm_13406079_36776943_97352850438", //third_taobao_share_pid_android
  98. SharePromoIdWeb: "mm_13406079_15484476_97352900127", //third_taobao_share_pid_web
  99. SelfInviteCode: "JV4R57",
  100. SelfPromoIdIOS: "mm_13406079_36674309_110739250114", //third_taobao_self_invite_code
  101. SelfPromoIdAndroid: "mm_13406079_36776943_110740650068", // third_taobao_self_pid_ios
  102. SelfPromoIdWeb: "mm_13406079_15484476_110741150064", //third_taobao_self_pid_android
  103. SelfPromoIdFree: "mm_13406079_36776943_49998050236", //third_taobao_free_pid
  104. }
  105. // return &TB{
  106. // Web_AK: "32271226", // third_taobao_web_ak
  107. // Web_SK: "ad3e1f3ffc70578dac6d4f4b97e4caad", // third_taobao_web_sk
  108. // SID: "6200517d93f0e8396063188b6ZZb0c31d45b3c2311c4310670639499", //third_taobao_sid
  109. // Svc_AK: "26302019", // third_taobao_svc_ak
  110. // Svc_SK: "ba877cfcdc64d3fbc1105d61d66dd1d7", // third_taobao_svc_sk
  111. // Svc_SID: "6202812d3c107786820ace47c9200f0cf7093e213f8ed45199979191", // third_taobao_svc_sid
  112. // ShareInviteCode: "FtWw5E", //third_taobao_share_invite_code
  113. // // SharePromoIdIOS: "mm_13406079_36674309_97353600076", // third_taobao_share_pid_ios
  114. // // SharePromoIdAndroid: "mm_13406079_36776943_97352850438", //third_taobao_share_pid_android
  115. // SharePromoIdWeb: "mm_25640383_2182750388_111085150224", //third_taobao_share_pid_web
  116. // SelfInviteCode: "9N8LJE",
  117. // // SelfPromoIdIOS: "mm_13406079_36674309_110739250114", //third_taobao_self_invite_code
  118. // // SelfPromoIdAndroid: "mm_13406079_36776943_110740650068", // third_taobao_self_pid_ios
  119. // SelfPromoIdWeb: "mm_25640383_2182750388_111086100270", //third_taobao_self_pid_android
  120. // }
  121. }
  122. ///
  123. // {"SID":"6200d02d5aceeec70abb05983156d4b8b4bf78cd6d8df69199979191",
  124. // "Web_AK":"23430885",
  125. // "Web_SK":"8c90c716181852cabaabc8dc1bf59a23",
  126. // "Svc_AK":"26302019",
  127. // "Svc_SK":"ba877cfcdc64d3fbc1105d61d66dd1d7",
  128. // "Svc_SID":"6202812d3c107786820ace47c9200f0cf7093e213f8ed45199979191",
  129. // "ShareInviteCode":"CAGGTZ",
  130. // "SharePromoIdIOS":"mm_13406079_36674309_97353600076",
  131. // "SharePromoIdAndroid":"mm_13406079_36776943_97352850438",
  132. // "SharePromoIdWeb":"mm_13406079_15484476_97352900127",
  133. // "SelfInviteCode":"JV4R57",
  134. // "SelfPromoIdIOS":"mm_13406079_36674309_110739250114",
  135. // "SelfPromoIdAndroid":"mm_13406079_36776943_110740650068",
  136. // "SelfPromoIdWeb":"mm_13406079_15484476_110741150064"}
  137. ///
  138. // 拆分推广位, 分别返回 账户ID,网站ID,推广位ID
  139. func SplitPid(pid string) (AccID, SiteId, AdZoneId string) {
  140. s := strings.Split(pid, "_")
  141. if len(s) != 4 {
  142. return "", "", ""
  143. }
  144. return s[1], s[2], s[3]
  145. }
  146. func AccId(pid string) string {
  147. accId, _, _ := SplitPid(pid)
  148. return accId
  149. }
  150. func SiteId(pid string) string {
  151. _, siteId, _ := SplitPid(pid)
  152. return siteId
  153. }
  154. func AdZoneId(pid string) string {
  155. _, _, adZoneId := SplitPid(pid)
  156. return adZoneId
  157. }
  158. // 发送淘宝请求
  159. func send(args map[string]string, method, ak, sk string) ([]byte, error) {
  160. args["v"] = "2.0"
  161. args["method"] = method
  162. args["format"] = "json"
  163. args["app_key"] = ak
  164. args["sign_method"] = "md5"
  165. args["timestamp"] = time.Now().Format("2006-01-02 15:04:05")
  166. args["sign"] = sign(args, sk)
  167. urls := TB_HOST_HTTPS
  168. fmt.Println(args, "args")
  169. fmt.Println(urls)
  170. for k, v := range args {
  171. urls += k + "=" + url.QueryEscape(v) + "&"
  172. }
  173. urls = urls[:len(urls)-1]
  174. return zhios_third_party_utils.CurlGet(urls, nil)
  175. }
  176. func sign(m map[string]string, sk string) string {
  177. // key sort
  178. keys := make([]string, 0, len(m))
  179. for k := range m {
  180. keys = append(keys, k)
  181. }
  182. sort.Strings(keys)
  183. str := ""
  184. for _, k := range keys {
  185. str += k + m[k]
  186. }
  187. // merge string
  188. str = sk + str + sk
  189. return strings.ToUpper(zhios_third_party_utils.Md5(str))
  190. }