golang 的 rabbitmq 消费项目
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.

api.go 8.9 KiB

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