|
- package taobao
-
- import (
- "fmt"
- "net/url"
- "sort"
- "strings"
- "time"
-
- "applet/app/utils"
- )
-
- /*
- sc 代表服务商, 工具商
- dg 代表推广者, 站长
-
- 工具商: 为站长服务, 当站长有些权限不足登陆时候, 例如:授权登陆等,可以使用工具商的服务, 工具商每次调用淘宝必须传入站长的session,以便于区分不同站长
- 站 长: 在一般情况下可以使用自己的自己的key, 包括物料搜索等
-
- 邀请码: 用于区分不同的渠道, 淘宝不同渠道有不同的邀请链接, 例如:渠道管理, 会员运营管理 这两种
- 推广位: 用于区分不同的位置, 不同推广位区分如IOS,android,web,applet不同
- */
-
- const (
- // 淘宝基础host
- TB_HOST_HTTP = "http://gw.api.taobao.com/router/rest?"
- TB_HOST_HTTPS = "https://eco.taobao.com/router/rest?"
-
- // TODO 物料id查找 https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10628875?_k=gpov9a
- // 淘宝业务, op for operation 操作, tbk for taobaoke,
- TBK_SC_MTL_OPT = "taobao.tbk.sc.material.optional.upgrade" // 淘宝客-服务商-物料搜索
- TBK_DG_MTL_OPT = "taobao.tbk.dg.material.optional.upgrade" // 淘宝客-推广者-物料搜索
- TB_SVC_AK = "33970476"
- TB_SVC_SK = "2d46abef05a0d05d7ddcd3af2d540d2b"
- TB_SVC_TIME = "2022-08-09 10:58:00"
- )
-
- type TB struct {
- UnionId string
- // 站长web key, 用于查询订单,搜索等
- AuthLevel string
- SID string
- UserSID string //用户的session
- Web_AK string
- Web_SK string
- User_Web_AK string
- User_Web_SK string
-
- // 服务商 service key, 如智盟, SVC = service 授权服务
- Svc_AK string
- Svc_SK string
- Svc_SID string
- CloudPromoIdWeb string // 分享推广位, web , Web Key时可用
-
- // 渠道 - 分享(会员外)
- ShareInviteCode string // 邀请码,用户获取relationId,用于分享
- SharePromoIdIOS string // 分享推广位, IOS , APP Key时可用
- SharePromoIdAndroid string // 分享推广位, ANDROID , APP Key时可用
- SharePromoIdWeb string // 分享推广位, web , Web Key时可用
- // 渠道 - 自购(会员)
- SelfInviteCode string // 邀请码,用户获取specialId,用于自购
- SelfPromoIdIOS string // 自购推广位, IOS , APP Key时可用
- SelfPromoIdAndroid string // 自购推广位, ANDROID , APP Key时可用
- SelfPromoIdWeb string // 自购推广位, web , Web Key时可用
- // 新人免单等推广位
-
- SelfPromoIdFree string // 免单推广位
- SelfPromoIdTljFree string // 免单淘礼金推广位
- SelfPromoIdRelationFree string // 免单推广位
- SelfPromoIdRelationTljFree string // 免单淘礼金推广位
- SelfPromoIdTljRelationFree string // 免单淘礼金渠道推广位
- ActivitySelfPromoIdWeb string //活动的自购推广位
- ActivitySharePromoIdWeb string //活动的分享推广位
- WechatActivitySelfPromoIdWeb string //小程序活动的自购推广位
- WechatActivitySharePromoIdWeb string //小程序活动的分享推广位
- WebRelationSelfKey string //渠道网站自购
- AndroidRelationSelfKey string //渠道安卓自购
- IosRelationSelfKey string //渠道ios自购
- wechatSelfKey string //小程序自购
- AuthType int //返回授权类型用来判断
- AuthBuyType string //判断用哪种授权模式 纯渠道 或 会员+渠道 主要是转链不同
- ChannelUrl string //渠道邀请码
- ShareChannelUrl string //渠道邀请码
- AppletIsAuth string
- AppletPid string
- }
-
- // 旧
- // TB_AUTH_AK = "26302019" // 授权ak
- // TB_AUTH_SK = "ba877cfcdc64d3fbc1105d61d66dd1d7" // 授权sk
- // TB_AUTH_SID = "6202812d3c107786820ace47c9200f0cf7093e213f8ed45199979191" // 可以通过智盟获得
- // TB_AUTH_INVITER_CODE = "CAGGTZ"
-
- // TB_AK = "23430885" //业务ak
- // TB_SK = "8c90c716181852cabaabc8dc1bf59a23" //业务sk
- // TB_SID = "6201603b382ZZd3bc3f1737478521e8ae243a3245cbe6bd199979191" // 业务sid
- // TB_PID = "mm_13406079_15484476_59718997" // 业务PID
- // TB_ACC_ID = "13406079"
- // TB_SITE_ID = "15484476"
- // TB_ADZONE_ID = "59718997"
-
- func New(tb *TB) *TB {
- if tb != nil {
- return tb
- }
- return &TB{
- Web_AK: "23430885", // third_taobao_web_ak
- Web_SK: "8c90c716181852cabaabc8dc1bf59a23", // third_taobao_web_sk
- SID: "6200d02d5aceeec70abb05983156d4b8b4bf78cd6d8df69199979191", // third_taobao_sid
-
- Svc_AK: "26302019", // third_taobao_svc_ak
- Svc_SK: "ba877cfcdc64d3fbc1105d61d66dd1d7", // third_taobao_svc_sk
- Svc_SID: "6200f110dca5586962fhjf512d05f0cb731d43045fdd460199979191", // third_taobao_svc_sid
-
- ShareInviteCode: "CAGGTZ", //third_taobao_share_invite_code
- SharePromoIdIOS: "mm_13406079_36674309_97353600076", // third_taobao_share_pid_ios
- SharePromoIdAndroid: "mm_13406079_36776943_97352850438", //third_taobao_share_pid_android
- SharePromoIdWeb: "mm_13406079_15484476_97352900127", //third_taobao_share_pid_web
-
- SelfInviteCode: "JV4R57",
- SelfPromoIdIOS: "mm_13406079_36674309_110739250114", //third_taobao_self_invite_code
- SelfPromoIdAndroid: "mm_13406079_36776943_110740650068", // third_taobao_self_pid_ios
- SelfPromoIdWeb: "mm_13406079_15484476_110741150064", //third_taobao_self_pid_android
-
- SelfPromoIdFree: "mm_13406079_36776943_49998050236", //third_taobao_free_pid
- }
- // return &TB{
- // Web_AK: "32271226", // third_taobao_web_ak
- // Web_SK: "ad3e1f3ffc70578dac6d4f4b97e4caad", // third_taobao_web_sk
- // SID: "6200517d93f0e8396063188b6ZZb0c31d45b3c2311c4310670639499", //third_taobao_sid
-
- // Svc_AK: "26302019", // third_taobao_svc_ak
- // Svc_SK: "ba877cfcdc64d3fbc1105d61d66dd1d7", // third_taobao_svc_sk
- // Svc_SID: "6202812d3c107786820ace47c9200f0cf7093e213f8ed45199979191", // third_taobao_svc_sid
-
- // ShareInviteCode: "FtWw5E", //third_taobao_share_invite_code
- // // SharePromoIdIOS: "mm_13406079_36674309_97353600076", // third_taobao_share_pid_ios
- // // SharePromoIdAndroid: "mm_13406079_36776943_97352850438", //third_taobao_share_pid_android
- // SharePromoIdWeb: "mm_25640383_2182750388_111085150224", //third_taobao_share_pid_web
-
- // SelfInviteCode: "9N8LJE",
- // // SelfPromoIdIOS: "mm_13406079_36674309_110739250114", //third_taobao_self_invite_code
- // // SelfPromoIdAndroid: "mm_13406079_36776943_110740650068", // third_taobao_self_pid_ios
- // SelfPromoIdWeb: "mm_25640383_2182750388_111086100270", //third_taobao_self_pid_android
- // }
- }
-
- ///
- // {"SID":"6200d02d5aceeec70abb05983156d4b8b4bf78cd6d8df69199979191",
- // "Web_AK":"23430885",
- // "Web_SK":"8c90c716181852cabaabc8dc1bf59a23",
- // "Svc_AK":"26302019",
- // "Svc_SK":"ba877cfcdc64d3fbc1105d61d66dd1d7",
- // "Svc_SID":"6202812d3c107786820ace47c9200f0cf7093e213f8ed45199979191",
- // "ShareInviteCode":"CAGGTZ",
- // "SharePromoIdIOS":"mm_13406079_36674309_97353600076",
- // "SharePromoIdAndroid":"mm_13406079_36776943_97352850438",
- // "SharePromoIdWeb":"mm_13406079_15484476_97352900127",
- // "SelfInviteCode":"JV4R57",
- // "SelfPromoIdIOS":"mm_13406079_36674309_110739250114",
- // "SelfPromoIdAndroid":"mm_13406079_36776943_110740650068",
- // "SelfPromoIdWeb":"mm_13406079_15484476_110741150064"}
- ///
- // 拆分推广位, 分别返回 账户ID,网站ID,推广位ID
- func SplitPid(pid string) (AccID, SiteId, AdZoneId string) {
- s := strings.Split(pid, "_")
- if len(s) != 4 {
- return "", "", ""
- }
- return s[1], s[2], s[3]
- }
-
- func AccId(pid string) string {
- accId, _, _ := SplitPid(pid)
- return accId
- }
- func SiteId(pid string) string {
- _, siteId, _ := SplitPid(pid)
- return siteId
- }
-
- func AdZoneId(pid string) string {
- _, _, adZoneId := SplitPid(pid)
- return adZoneId
- }
-
- // 发送淘宝请求
- func send(args map[string]string, method, ak, sk string) ([]byte, error) {
- args["v"] = "2.0"
- args["method"] = method
- args["format"] = "json"
- args["app_key"] = ak
- args["sign_method"] = "md5"
- args["timestamp"] = time.Now().Format("2006-01-02 15:04:05")
- args["sign"] = sign(args, sk)
- urls := TB_HOST_HTTPS
- fmt.Println(args, "args")
- fmt.Println(urls)
- for k, v := range args {
- urls += k + "=" + url.QueryEscape(v) + "&"
- }
- urls = urls[:len(urls)-1]
- return utils.CurlGet(urls, nil)
- }
-
- func sign(m map[string]string, sk string) string {
- // key sort
- keys := make([]string, 0, len(m))
- for k := range m {
- keys = append(keys, k)
- }
- sort.Strings(keys)
- str := ""
- for _, k := range keys {
- str += k + m[k]
- }
- // merge string
- str = sk + str + sk
- return strings.ToUpper(utils.Md5(str))
- }
|