第三方api接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
8.7 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" // 淘宝客-服务商-物料搜索
  25. TBK_DG_MTL_OPT = "taobao.tbk.dg.material.optional" // 淘宝客-推广者-物料搜索
  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. // 渠道 - 自购(会员)
  48. SelfInviteCode string // 邀请码,用户获取specialId,用于自购
  49. SelfPromoIdIOS string // 自购推广位, IOS , APP Key时可用
  50. SelfPromoIdAndroid string // 自购推广位, ANDROID , APP Key时可用
  51. SelfPromoIdWeb string // 自购推广位, web , Web Key时可用
  52. // 新人免单等推广位
  53. SelfPromoIdFree string // 免单推广位
  54. SelfPromoIdTljFree string // 免单淘礼金推广位
  55. SelfPromoIdTljRelationFree string // 免单淘礼金渠道推广位
  56. ActivitySelfPromoIdWeb string //活动的自购推广位
  57. ActivitySharePromoIdWeb string //活动的分享推广位
  58. WechatActivitySelfPromoIdWeb string //小程序活动的自购推广位
  59. WechatActivitySharePromoIdWeb string //小程序活动的分享推广位
  60. WebRelationSelfKey string //渠道网站自购
  61. AndroidRelationSelfKey string //渠道安卓自购
  62. IosRelationSelfKey string //渠道ios自购
  63. wechatSelfKey string //小程序自购
  64. AuthType int //返回授权类型用来判断
  65. AuthBuyType string //判断用哪种授权模式 纯渠道 或 会员+渠道 主要是转链不同
  66. ChannelUrl string //渠道邀请码
  67. ShareChannelUrl string //渠道邀请码
  68. AppletIsAuth string
  69. AppletPid string
  70. }
  71. // 旧
  72. // TB_AUTH_AK = "26302019" // 授权ak
  73. // TB_AUTH_SK = "ba877cfcdc64d3fbc1105d61d66dd1d7" // 授权sk
  74. // TB_AUTH_SID = "6202812d3c107786820ace47c9200f0cf7093e213f8ed45199979191" // 可以通过智盟获得
  75. // TB_AUTH_INVITER_CODE = "CAGGTZ"
  76. // TB_AK = "23430885" //业务ak
  77. // TB_SK = "8c90c716181852cabaabc8dc1bf59a23" //业务sk
  78. // TB_SID = "6201603b382ZZd3bc3f1737478521e8ae243a3245cbe6bd199979191" // 业务sid
  79. // TB_PID = "mm_13406079_15484476_59718997" // 业务PID
  80. // TB_ACC_ID = "13406079"
  81. // TB_SITE_ID = "15484476"
  82. // TB_ADZONE_ID = "59718997"
  83. func New(tb *TB) *TB {
  84. if tb != nil {
  85. return tb
  86. }
  87. return &TB{
  88. Web_AK: "23430885", // third_taobao_web_ak
  89. Web_SK: "8c90c716181852cabaabc8dc1bf59a23", // third_taobao_web_sk
  90. SID: "6200d02d5aceeec70abb05983156d4b8b4bf78cd6d8df69199979191", // third_taobao_sid
  91. Svc_AK: "26302019", // third_taobao_svc_ak
  92. Svc_SK: "ba877cfcdc64d3fbc1105d61d66dd1d7", // third_taobao_svc_sk
  93. Svc_SID: "6200f110dca5586962fhjf512d05f0cb731d43045fdd460199979191", // third_taobao_svc_sid
  94. ShareInviteCode: "CAGGTZ", //third_taobao_share_invite_code
  95. SharePromoIdIOS: "mm_13406079_36674309_97353600076", // third_taobao_share_pid_ios
  96. SharePromoIdAndroid: "mm_13406079_36776943_97352850438", //third_taobao_share_pid_android
  97. SharePromoIdWeb: "mm_13406079_15484476_97352900127", //third_taobao_share_pid_web
  98. SelfInviteCode: "JV4R57",
  99. SelfPromoIdIOS: "mm_13406079_36674309_110739250114", //third_taobao_self_invite_code
  100. SelfPromoIdAndroid: "mm_13406079_36776943_110740650068", // third_taobao_self_pid_ios
  101. SelfPromoIdWeb: "mm_13406079_15484476_110741150064", //third_taobao_self_pid_android
  102. SelfPromoIdFree: "mm_13406079_36776943_49998050236", //third_taobao_free_pid
  103. }
  104. // return &TB{
  105. // Web_AK: "32271226", // third_taobao_web_ak
  106. // Web_SK: "ad3e1f3ffc70578dac6d4f4b97e4caad", // third_taobao_web_sk
  107. // SID: "6200517d93f0e8396063188b6ZZb0c31d45b3c2311c4310670639499", //third_taobao_sid
  108. // Svc_AK: "26302019", // third_taobao_svc_ak
  109. // Svc_SK: "ba877cfcdc64d3fbc1105d61d66dd1d7", // third_taobao_svc_sk
  110. // Svc_SID: "6202812d3c107786820ace47c9200f0cf7093e213f8ed45199979191", // third_taobao_svc_sid
  111. // ShareInviteCode: "FtWw5E", //third_taobao_share_invite_code
  112. // // SharePromoIdIOS: "mm_13406079_36674309_97353600076", // third_taobao_share_pid_ios
  113. // // SharePromoIdAndroid: "mm_13406079_36776943_97352850438", //third_taobao_share_pid_android
  114. // SharePromoIdWeb: "mm_25640383_2182750388_111085150224", //third_taobao_share_pid_web
  115. // SelfInviteCode: "9N8LJE",
  116. // // SelfPromoIdIOS: "mm_13406079_36674309_110739250114", //third_taobao_self_invite_code
  117. // // SelfPromoIdAndroid: "mm_13406079_36776943_110740650068", // third_taobao_self_pid_ios
  118. // SelfPromoIdWeb: "mm_25640383_2182750388_111086100270", //third_taobao_self_pid_android
  119. // }
  120. }
  121. ///
  122. // {"SID":"6200d02d5aceeec70abb05983156d4b8b4bf78cd6d8df69199979191",
  123. // "Web_AK":"23430885",
  124. // "Web_SK":"8c90c716181852cabaabc8dc1bf59a23",
  125. // "Svc_AK":"26302019",
  126. // "Svc_SK":"ba877cfcdc64d3fbc1105d61d66dd1d7",
  127. // "Svc_SID":"6202812d3c107786820ace47c9200f0cf7093e213f8ed45199979191",
  128. // "ShareInviteCode":"CAGGTZ",
  129. // "SharePromoIdIOS":"mm_13406079_36674309_97353600076",
  130. // "SharePromoIdAndroid":"mm_13406079_36776943_97352850438",
  131. // "SharePromoIdWeb":"mm_13406079_15484476_97352900127",
  132. // "SelfInviteCode":"JV4R57",
  133. // "SelfPromoIdIOS":"mm_13406079_36674309_110739250114",
  134. // "SelfPromoIdAndroid":"mm_13406079_36776943_110740650068",
  135. // "SelfPromoIdWeb":"mm_13406079_15484476_110741150064"}
  136. ///
  137. // 拆分推广位, 分别返回 账户ID,网站ID,推广位ID
  138. func SplitPid(pid string) (AccID, SiteId, AdZoneId string) {
  139. s := strings.Split(pid, "_")
  140. if len(s) != 4 {
  141. return "", "", ""
  142. }
  143. return s[1], s[2], s[3]
  144. }
  145. func AccId(pid string) string {
  146. accId, _, _ := SplitPid(pid)
  147. return accId
  148. }
  149. func SiteId(pid string) string {
  150. _, siteId, _ := SplitPid(pid)
  151. return siteId
  152. }
  153. func AdZoneId(pid string) string {
  154. _, _, adZoneId := SplitPid(pid)
  155. return adZoneId
  156. }
  157. // 发送淘宝请求
  158. func send(args map[string]string, method, ak, sk string) ([]byte, error) {
  159. args["v"] = "2.0"
  160. args["method"] = method
  161. args["format"] = "json"
  162. args["app_key"] = ak
  163. args["sign_method"] = "md5"
  164. args["timestamp"] = time.Now().Format("2006-01-02 15:04:05")
  165. args["sign"] = sign(args, sk)
  166. urls := TB_HOST_HTTPS
  167. fmt.Println(args, "args")
  168. fmt.Println(urls)
  169. for k, v := range args {
  170. urls += k + "=" + url.QueryEscape(v) + "&"
  171. }
  172. urls = urls[:len(urls)-1]
  173. return zhios_third_party_utils.CurlGet(urls, nil)
  174. }
  175. func sign(m map[string]string, sk string) string {
  176. // key sort
  177. keys := make([]string, 0, len(m))
  178. for k := range m {
  179. keys = append(keys, k)
  180. }
  181. sort.Strings(keys)
  182. str := ""
  183. for _, k := range keys {
  184. str += k + m[k]
  185. }
  186. // merge string
  187. str = sk + str + sk
  188. return strings.ToUpper(zhios_third_party_utils.Md5(str))
  189. }