第三方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.

137 lines
7.5 KiB

  1. package taobao
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db"
  4. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md"
  5. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  6. "errors"
  7. "github.com/tidwall/gjson"
  8. "xorm.io/xorm"
  9. )
  10. func NewTaobaoSDK(eg *xorm.Engine, dbName, Platform string, AccTaobaoShareId int) (*TB, error) {
  11. // 从联盟设置中获取淘宝配置
  12. taobaoCfg, err := db.SysUnionByTaobaoByUseByAuth(eg, dbName)
  13. if err != nil {
  14. return nil, err
  15. }
  16. var cfg *TB
  17. freeCfg := db.SysCfgGetWithDb(eg, dbName, "newcomers_free_cfg")
  18. /*if freeCfg == "" {
  19. return nil, errors.New("no free cfg found")
  20. }*/
  21. Svc_AK := "26302019"
  22. Svc_SK := "ba877cfcdc64d3fbc1105d61d66dd1d7"
  23. if taobaoCfg.AuthTime.Unix() >= zhios_third_party_utils.TimeStdParseUnix(TB_SVC_TIME) {
  24. Svc_AK = TB_SVC_AK
  25. Svc_SK = TB_SVC_SK
  26. }
  27. // 跟随官方
  28. if taobaoCfg.AuthType == 1 {
  29. cfg = &TB{
  30. Web_AK: Svc_AK,
  31. Web_SK: Svc_SK,
  32. UserSID: gjson.Get(taobaoCfg.KeyData, "accessToken").String(),
  33. SID: "6200f110dca5586962fhjf512d05f0cb731d43045fdd460199979191",
  34. Svc_AK: Svc_AK,
  35. Svc_SK: Svc_SK,
  36. Svc_SID: "6200f110dca5586962fhjf512d05f0cb731d43045fdd460199979191",
  37. User_Web_AK: gjson.Get(taobaoCfg.KeyData, "apiAppKey").String(),
  38. User_Web_SK: gjson.Get(taobaoCfg.KeyData, "apiAppSecret").String(),
  39. ShareInviteCode: gjson.Get(taobaoCfg.KeyData, "channelUrl").String(),
  40. SharePromoIdIOS: gjson.Get(taobaoCfg.KeyData, "ios.shareKey").String(),
  41. SharePromoIdAndroid: gjson.Get(taobaoCfg.KeyData, "android.shareKey").String(),
  42. SharePromoIdWeb: gjson.Get(taobaoCfg.KeyData, "webShareKey").String(),
  43. SelfInviteCode: gjson.Get(taobaoCfg.KeyData, "memberUrl").String(),
  44. SelfPromoIdIOS: gjson.Get(taobaoCfg.KeyData, "ios.selfKey").String(),
  45. SelfPromoIdAndroid: gjson.Get(taobaoCfg.KeyData, "android.selfKey").String(),
  46. SelfPromoIdWeb: gjson.Get(taobaoCfg.KeyData, "webSelfKey").String(),
  47. SelfPromoIdFree: gjson.Get(freeCfg, "taobao_pid").String(),
  48. ActivitySelfPromoIdWeb: gjson.Get(taobaoCfg.KeyData, "activitySelfKey").String(),
  49. ActivitySharePromoIdWeb: gjson.Get(taobaoCfg.KeyData, "activityShareKey").String(),
  50. WechatActivitySelfPromoIdWeb: gjson.Get(taobaoCfg.KeyData, "wechatActivitySelfKey").String(),
  51. WechatActivitySharePromoIdWeb: gjson.Get(taobaoCfg.KeyData, "wechatActivityShareKey").String(),
  52. ChannelUrl: gjson.Get(taobaoCfg.KeyData, "channelUrl").String(),
  53. ShareChannelUrl: gjson.Get(taobaoCfg.KeyData, "channelUrl").String(),
  54. AuthType: 1,
  55. AppletIsAuth: zhios_third_party_utils.IntToStr(taobaoCfg.AppletIsAuth),
  56. }
  57. var authBuyType = gjson.Get(taobaoCfg.KeyData, "authBuyType").String()
  58. cfg.AuthBuyType = authBuyType
  59. if authBuyType == "1" && Platform != md.PLATFORM_WX_APPLET {
  60. //如果是1 就是纯渠道模式 要更换渠道推广位
  61. cfg.SelfPromoIdWeb = gjson.Get(taobaoCfg.KeyData, "webRelationSelfKey").String()
  62. cfg.SelfPromoIdAndroid = gjson.Get(taobaoCfg.KeyData, "androidRelationSelfKey").String()
  63. cfg.SelfPromoIdIOS = gjson.Get(taobaoCfg.KeyData, "iosRelationSelfKey").String()
  64. }
  65. if Platform == md.PLATFORM_WX_APPLET {
  66. if authBuyType == "1" && AccTaobaoShareId > 0 {
  67. //如果是1 就是纯渠道模式 要更换渠道推广位
  68. cfg.SelfPromoIdWeb = gjson.Get(taobaoCfg.KeyData, "webRelationSelfKey").String()
  69. cfg.SelfPromoIdAndroid = gjson.Get(taobaoCfg.KeyData, "androidRelationSelfKey").String()
  70. cfg.SelfPromoIdIOS = gjson.Get(taobaoCfg.KeyData, "iosRelationSelfKey").String()
  71. } else if gjson.Get(taobaoCfg.KeyData, "wechatSelfKey").String() != "" {
  72. cfg.SelfPromoIdWeb = gjson.Get(taobaoCfg.KeyData, "wechatSelfKey").String()
  73. }
  74. }
  75. } else {
  76. if gjson.Get(taobaoCfg.KeyData, "apiAppKey").String() == "" ||
  77. gjson.Get(taobaoCfg.KeyData, "apiAppSecret").String() == "" ||
  78. gjson.Get(taobaoCfg.KeyData, "accessToken").String() == "" {
  79. return nil, errors.New("联盟配置错误")
  80. }
  81. // 自由联盟账号
  82. cfg = &TB{
  83. Web_AK: gjson.Get(taobaoCfg.KeyData, "apiAppKey").String(),
  84. Web_SK: gjson.Get(taobaoCfg.KeyData, "apiAppSecret").String(),
  85. SID: gjson.Get(taobaoCfg.KeyData, "accessToken").String(),
  86. UserSID: gjson.Get(taobaoCfg.KeyData, "accessToken").String(),
  87. Svc_AK: Svc_AK,
  88. Svc_SK: Svc_SK,
  89. Svc_SID: "6200f110dca5586962fhjf512d05f0cb731d43045fdd460199979191",
  90. User_Web_AK: gjson.Get(taobaoCfg.KeyData, "apiAppKey").String(),
  91. User_Web_SK: gjson.Get(taobaoCfg.KeyData, "apiAppSecret").String(),
  92. ShareInviteCode: gjson.Get(taobaoCfg.KeyData, "channelUrl").String(),
  93. SharePromoIdIOS: gjson.Get(taobaoCfg.KeyData, "ios.shareKey").String(),
  94. SharePromoIdAndroid: gjson.Get(taobaoCfg.KeyData, "android.shareKey").String(),
  95. SharePromoIdWeb: gjson.Get(taobaoCfg.KeyData, "webShareKey").String(),
  96. SelfInviteCode: gjson.Get(taobaoCfg.KeyData, "memberUrl").String(),
  97. SelfPromoIdIOS: gjson.Get(taobaoCfg.KeyData, "ios.selfKey").String(),
  98. SelfPromoIdAndroid: gjson.Get(taobaoCfg.KeyData, "android.selfKey").String(),
  99. SelfPromoIdWeb: gjson.Get(taobaoCfg.KeyData, "webSelfKey").String(),
  100. SelfPromoIdFree: gjson.Get(freeCfg, "taobao_pid").String(),
  101. ActivitySelfPromoIdWeb: gjson.Get(taobaoCfg.KeyData, "activitySelfKey").String(),
  102. ActivitySharePromoIdWeb: gjson.Get(taobaoCfg.KeyData, "activityShareKey").String(),
  103. WechatActivitySelfPromoIdWeb: gjson.Get(taobaoCfg.KeyData, "wechatActivitySelfKey").String(),
  104. WechatActivitySharePromoIdWeb: gjson.Get(taobaoCfg.KeyData, "wechatActivityShareKey").String(),
  105. ChannelUrl: gjson.Get(taobaoCfg.KeyData, "channelUrl").String(),
  106. ShareChannelUrl: gjson.Get(taobaoCfg.KeyData, "channelUrl").String(),
  107. AuthType: 0,
  108. AppletIsAuth: zhios_third_party_utils.IntToStr(taobaoCfg.AppletIsAuth),
  109. }
  110. var authBuyType = gjson.Get(taobaoCfg.KeyData, "authBuyType").String()
  111. cfg.AuthBuyType = authBuyType
  112. if authBuyType == "1" && Platform != md.PLATFORM_WX_APPLET {
  113. //如果是1 就是纯渠道模式 要更换渠道推广位
  114. cfg.SelfPromoIdWeb = gjson.Get(taobaoCfg.KeyData, "webRelationSelfKey").String()
  115. cfg.SelfPromoIdAndroid = gjson.Get(taobaoCfg.KeyData, "androidRelationSelfKey").String()
  116. cfg.SelfPromoIdIOS = gjson.Get(taobaoCfg.KeyData, "iosRelationSelfKey").String()
  117. }
  118. if Platform == md.PLATFORM_WX_APPLET {
  119. if authBuyType == "1" && AccTaobaoShareId > 0 {
  120. //如果是1 就是纯渠道模式 要更换渠道推广位
  121. cfg.SelfPromoIdWeb = gjson.Get(taobaoCfg.KeyData, "webRelationSelfKey").String()
  122. cfg.SelfPromoIdAndroid = gjson.Get(taobaoCfg.KeyData, "androidRelationSelfKey").String()
  123. cfg.SelfPromoIdIOS = gjson.Get(taobaoCfg.KeyData, "iosRelationSelfKey").String()
  124. } else if gjson.Get(taobaoCfg.KeyData, "wechatSelfKey").String() != "" {
  125. cfg.SelfPromoIdWeb = gjson.Get(taobaoCfg.KeyData, "wechatSelfKey").String()
  126. }
  127. }
  128. }
  129. return cfg, nil
  130. }