package taobao import ( "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db" "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md" zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" "errors" "github.com/tidwall/gjson" "xorm.io/xorm" ) func NewTaobaoSDK(eg *xorm.Engine, dbName, Platform string, AccTaobaoShareId int) (*TB, error) { // 从联盟设置中获取淘宝配置 taobaoCfg, err := db.SysUnionByTaobaoByUseByAuth(eg, dbName) if err != nil { return nil, err } var cfg *TB freeCfg := db.SysCfgGetWithDb(eg, dbName, "newcomers_free_cfg") /*if freeCfg == "" { return nil, errors.New("no free cfg found") }*/ Svc_AK := "26302019" Svc_SK := "ba877cfcdc64d3fbc1105d61d66dd1d7" if taobaoCfg.AuthTime.Unix() >= zhios_third_party_utils.TimeStdParseUnix(TB_SVC_TIME) { Svc_AK = TB_SVC_AK Svc_SK = TB_SVC_SK } // 跟随官方 if taobaoCfg.AuthType == 1 { cfg = &TB{ Web_AK: Svc_AK, Web_SK: Svc_SK, UserSID: gjson.Get(taobaoCfg.KeyData, "accessToken").String(), SID: "6200f110dca5586962fhjf512d05f0cb731d43045fdd460199979191", Svc_AK: Svc_AK, Svc_SK: Svc_SK, Svc_SID: "6200f110dca5586962fhjf512d05f0cb731d43045fdd460199979191", User_Web_AK: gjson.Get(taobaoCfg.KeyData, "apiAppKey").String(), User_Web_SK: gjson.Get(taobaoCfg.KeyData, "apiAppSecret").String(), ShareInviteCode: gjson.Get(taobaoCfg.KeyData, "channelUrl").String(), SharePromoIdIOS: gjson.Get(taobaoCfg.KeyData, "ios.shareKey").String(), SharePromoIdAndroid: gjson.Get(taobaoCfg.KeyData, "android.shareKey").String(), SharePromoIdWeb: gjson.Get(taobaoCfg.KeyData, "webShareKey").String(), SelfInviteCode: gjson.Get(taobaoCfg.KeyData, "memberUrl").String(), SelfPromoIdIOS: gjson.Get(taobaoCfg.KeyData, "ios.selfKey").String(), SelfPromoIdAndroid: gjson.Get(taobaoCfg.KeyData, "android.selfKey").String(), SelfPromoIdWeb: gjson.Get(taobaoCfg.KeyData, "webSelfKey").String(), SelfPromoIdFree: gjson.Get(freeCfg, "taobao_pid").String(), ActivitySelfPromoIdWeb: gjson.Get(taobaoCfg.KeyData, "activitySelfKey").String(), ActivitySharePromoIdWeb: gjson.Get(taobaoCfg.KeyData, "activityShareKey").String(), WechatActivitySelfPromoIdWeb: gjson.Get(taobaoCfg.KeyData, "wechatActivitySelfKey").String(), WechatActivitySharePromoIdWeb: gjson.Get(taobaoCfg.KeyData, "wechatActivityShareKey").String(), ChannelUrl: gjson.Get(taobaoCfg.KeyData, "channelUrl").String(), ShareChannelUrl: gjson.Get(taobaoCfg.KeyData, "channelUrl").String(), AuthType: 1, AppletIsAuth: zhios_third_party_utils.IntToStr(taobaoCfg.AppletIsAuth), } var authBuyType = gjson.Get(taobaoCfg.KeyData, "authBuyType").String() cfg.AuthBuyType = authBuyType if authBuyType == "1" && Platform != md.PLATFORM_WX_APPLET { //如果是1 就是纯渠道模式 要更换渠道推广位 cfg.SelfPromoIdWeb = gjson.Get(taobaoCfg.KeyData, "webRelationSelfKey").String() cfg.SelfPromoIdAndroid = gjson.Get(taobaoCfg.KeyData, "androidRelationSelfKey").String() cfg.SelfPromoIdIOS = gjson.Get(taobaoCfg.KeyData, "iosRelationSelfKey").String() } if Platform == md.PLATFORM_WX_APPLET { if authBuyType == "1" && AccTaobaoShareId > 0 { //如果是1 就是纯渠道模式 要更换渠道推广位 cfg.SelfPromoIdWeb = gjson.Get(taobaoCfg.KeyData, "webRelationSelfKey").String() cfg.SelfPromoIdAndroid = gjson.Get(taobaoCfg.KeyData, "androidRelationSelfKey").String() cfg.SelfPromoIdIOS = gjson.Get(taobaoCfg.KeyData, "iosRelationSelfKey").String() } else if gjson.Get(taobaoCfg.KeyData, "wechatSelfKey").String() != "" { cfg.SelfPromoIdWeb = gjson.Get(taobaoCfg.KeyData, "wechatSelfKey").String() } } } else { if gjson.Get(taobaoCfg.KeyData, "apiAppKey").String() == "" || gjson.Get(taobaoCfg.KeyData, "apiAppSecret").String() == "" || gjson.Get(taobaoCfg.KeyData, "accessToken").String() == "" { return nil, errors.New("联盟配置错误") } // 自由联盟账号 cfg = &TB{ Web_AK: gjson.Get(taobaoCfg.KeyData, "apiAppKey").String(), Web_SK: gjson.Get(taobaoCfg.KeyData, "apiAppSecret").String(), SID: gjson.Get(taobaoCfg.KeyData, "accessToken").String(), UserSID: gjson.Get(taobaoCfg.KeyData, "accessToken").String(), Svc_AK: Svc_AK, Svc_SK: Svc_SK, Svc_SID: "6200f110dca5586962fhjf512d05f0cb731d43045fdd460199979191", User_Web_AK: gjson.Get(taobaoCfg.KeyData, "apiAppKey").String(), User_Web_SK: gjson.Get(taobaoCfg.KeyData, "apiAppSecret").String(), ShareInviteCode: gjson.Get(taobaoCfg.KeyData, "channelUrl").String(), SharePromoIdIOS: gjson.Get(taobaoCfg.KeyData, "ios.shareKey").String(), SharePromoIdAndroid: gjson.Get(taobaoCfg.KeyData, "android.shareKey").String(), SharePromoIdWeb: gjson.Get(taobaoCfg.KeyData, "webShareKey").String(), SelfInviteCode: gjson.Get(taobaoCfg.KeyData, "memberUrl").String(), SelfPromoIdIOS: gjson.Get(taobaoCfg.KeyData, "ios.selfKey").String(), SelfPromoIdAndroid: gjson.Get(taobaoCfg.KeyData, "android.selfKey").String(), SelfPromoIdWeb: gjson.Get(taobaoCfg.KeyData, "webSelfKey").String(), SelfPromoIdFree: gjson.Get(freeCfg, "taobao_pid").String(), ActivitySelfPromoIdWeb: gjson.Get(taobaoCfg.KeyData, "activitySelfKey").String(), ActivitySharePromoIdWeb: gjson.Get(taobaoCfg.KeyData, "activityShareKey").String(), WechatActivitySelfPromoIdWeb: gjson.Get(taobaoCfg.KeyData, "wechatActivitySelfKey").String(), WechatActivitySharePromoIdWeb: gjson.Get(taobaoCfg.KeyData, "wechatActivityShareKey").String(), ChannelUrl: gjson.Get(taobaoCfg.KeyData, "channelUrl").String(), ShareChannelUrl: gjson.Get(taobaoCfg.KeyData, "channelUrl").String(), AuthType: 0, AppletIsAuth: zhios_third_party_utils.IntToStr(taobaoCfg.AppletIsAuth), } var authBuyType = gjson.Get(taobaoCfg.KeyData, "authBuyType").String() cfg.AuthBuyType = authBuyType if authBuyType == "1" && Platform != md.PLATFORM_WX_APPLET { //如果是1 就是纯渠道模式 要更换渠道推广位 cfg.SelfPromoIdWeb = gjson.Get(taobaoCfg.KeyData, "webRelationSelfKey").String() cfg.SelfPromoIdAndroid = gjson.Get(taobaoCfg.KeyData, "androidRelationSelfKey").String() cfg.SelfPromoIdIOS = gjson.Get(taobaoCfg.KeyData, "iosRelationSelfKey").String() } if Platform == md.PLATFORM_WX_APPLET { if authBuyType == "1" && AccTaobaoShareId > 0 { //如果是1 就是纯渠道模式 要更换渠道推广位 cfg.SelfPromoIdWeb = gjson.Get(taobaoCfg.KeyData, "webRelationSelfKey").String() cfg.SelfPromoIdAndroid = gjson.Get(taobaoCfg.KeyData, "androidRelationSelfKey").String() cfg.SelfPromoIdIOS = gjson.Get(taobaoCfg.KeyData, "iosRelationSelfKey").String() } else if gjson.Get(taobaoCfg.KeyData, "wechatSelfKey").String() != "" { cfg.SelfPromoIdWeb = gjson.Get(taobaoCfg.KeyData, "wechatSelfKey").String() } } } return cfg, nil }