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

base.go 8.0 KiB

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