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

пре 10 месеци
пре 8 месеци
пре 10 месеци
пре 8 месеци
пре 10 месеци
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. package taobao
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md"
  4. "encoding/json"
  5. "github.com/syyongx/php2go"
  6. "strconv"
  7. )
  8. type UrlInfo struct {
  9. CategoryID int `json:"category_id"`
  10. CouponClickURL string `json:"coupon_click_url"`
  11. CouponEndTime string `json:"coupon_end_time"`
  12. CouponInfo string `json:"coupon_info"`
  13. CouponRemainCount int `json:"coupon_remain_count"`
  14. CouponStartTime string `json:"coupon_start_time"`
  15. CouponTotalCount int `json:"coupon_total_count"`
  16. ItemID string `json:"item_id"`
  17. ItemURL string `json:"item_url"`
  18. MaxCommissionRate string `json:"max_commission_rate"`
  19. MinCommissionRate string `json:"min_commission_rate"`
  20. RewardInfo int `json:"reward_info"`
  21. }
  22. // 淘宝转链
  23. func (t *TB) ConvertUrlSC(itemId, pid, externalId string) (*md.ConvertedUrls, error) {
  24. method := "taobao.tbk.privilege.get"
  25. _, siteId, adZoneId := SplitPid(pid)
  26. args := map[string]string{
  27. "item_id": itemId,
  28. "session": t.UserSID, // 一般用站长就可以转链
  29. "adzone_id": adZoneId,
  30. "platform": "2",
  31. "site_id": siteId,
  32. }
  33. if php2go.IsNumeric(itemId) {
  34. args["biz_scene_id"] = "2"
  35. }
  36. if externalId != "" {
  37. args["external_id"] = externalId
  38. }
  39. resp, err := send(args, method, t.Svc_AK, t.Svc_SK)
  40. if err != nil {
  41. return nil, err
  42. }
  43. var tmp struct {
  44. TbkPrivilegeGetResponse struct {
  45. Result struct {
  46. Data UrlInfo `json:"data"`
  47. } `json:"result"`
  48. RequestID string `json:"request_id"`
  49. } `json:"tbk_privilege_get_response"`
  50. }
  51. if err = json.Unmarshal(resp, &tmp); err != nil {
  52. return nil, err
  53. }
  54. url := tmp.TbkPrivilegeGetResponse.Result.Data.ItemURL
  55. hasCoupon := false
  56. itemUrl := tmp.TbkPrivilegeGetResponse.Result.Data.ItemURL
  57. maxCommissionRate := tmp.TbkPrivilegeGetResponse.Result.Data.MaxCommissionRate
  58. if tmp.TbkPrivilegeGetResponse.Result.Data.CouponClickURL != "" {
  59. hasCoupon = true
  60. url = tmp.TbkPrivilegeGetResponse.Result.Data.CouponClickURL
  61. }
  62. return &md.ConvertedUrls{
  63. ItemId: itemId,
  64. URL: url,
  65. ItemUrl: itemUrl,
  66. ShortenURL: url,
  67. NoOpenAppURL: url,
  68. AppURL: url,
  69. HasCoupon: hasCoupon,
  70. CommissionRate: maxCommissionRate,
  71. }, nil
  72. }
  73. func (t *TB) WnConvertUrlSC(itemId, types, pid, externalId string) (*md.ConvertedUrls, error) {
  74. method := "taobao.tbk.sc.general.link.convert"
  75. _, siteId, adZoneId := SplitPid(pid)
  76. args := map[string]string{
  77. "session": t.UserSID, // 一般用站长就可以转链
  78. "adzone_id": adZoneId,
  79. "platform": "2",
  80. "site_id": siteId,
  81. }
  82. if types == "1" || types == "4" { // 商品ID列表
  83. args["item_id_list"] = itemId
  84. args["biz_scene_id"] = "1"
  85. if externalId != "0" && externalId != "" {
  86. args["relation_id"] = externalId
  87. }
  88. }
  89. if types == "2" { //物料列表,可以为url或淘口令
  90. args["material_list"] = itemId
  91. if externalId != "0" && externalId != "" {
  92. args["relation_id"] = externalId
  93. }
  94. }
  95. if types == "3" { // 会场ID列表
  96. args["page_id_list"] = itemId
  97. if externalId != "" {
  98. args["relation_id"] = externalId
  99. }
  100. }
  101. resp, err := send(args, method, t.Svc_AK, t.Svc_SK)
  102. if err != nil {
  103. return nil, err
  104. }
  105. var tmp struct {
  106. TbkScGeneralLinkConvertResponse struct {
  107. Data struct {
  108. MaterialUrlList struct {
  109. MaterialUrlList []struct {
  110. Msg string `json:"msg"`
  111. Code int `json:"code"`
  112. PromotionInfoDto struct {
  113. CommissionRate string `json:"commission_rate"`
  114. } `json:"promotion_info_dto"`
  115. CouponInfoDto struct {
  116. CouponEndTime string `json:"coupon_end_time"`
  117. ActivityId string `json:"activity_id"`
  118. CouponRemainCount int `json:"coupon_remain_count"`
  119. CouponAmount string `json:"coupon_amount"`
  120. CouponStartTime string `json:"coupon_start_time"`
  121. CouponDesc string `json:"coupon_desc"`
  122. CouponType int `json:"coupon_type"`
  123. } `json:"coupon_info_dto"`
  124. LinkInfoDto struct {
  125. CouponLongUrl string `json:"coupon_long_url"`
  126. MaterialType int `json:"material_type"`
  127. TpwdOriginUrl string `json:"tpwd_origin_url"`
  128. MaterialId string `json:"material_id"`
  129. CpsLongUrl string `json:"cps_long_url"`
  130. CpsShortTpwd string `json:"cps_short_tpwd"`
  131. TkBizType int `json:"tk_biz_type"`
  132. CouponShortTpwd string `json:"coupon_short_tpwd"`
  133. CpsShortUrl string `json:"cps_short_url"`
  134. CouponShortUrl string `json:"coupon_short_url"`
  135. CouponFullTpwd string `json:"coupon_full_tpwd"`
  136. CpsFullTpwd string `json:"cps_full_tpwd"`
  137. } `json:"link_info_dto"`
  138. } `json:"material_url_list"`
  139. } `json:"material_url_list"`
  140. ShopUrlList struct {
  141. ShopUrlList []struct {
  142. Msg string `json:"msg"`
  143. Code int `json:"code"`
  144. LinkInfoDto struct {
  145. MaterialType int `json:"material_type"`
  146. SellerId string `json:"seller_id"`
  147. CpsLongUrl string `json:"cps_long_url"`
  148. CpsShortTpwd string `json:"cps_short_tpwd"`
  149. CpsShortUrl string `json:"cps_short_url"`
  150. CpsFullTpwd string `json:"cps_full_tpwd"`
  151. } `json:"link_info_dto"`
  152. } `json:"shop_url_list"`
  153. } `json:"shop_url_list"`
  154. EventUrlList struct {
  155. EventUrlList []struct {
  156. Msg string `json:"msg"`
  157. Code int `json:"code"`
  158. LinkInfoDto struct {
  159. MaterialType int `json:"material_type"`
  160. PageId string `json:"page_id"`
  161. CpsLongUrl string `json:"cps_long_url"`
  162. CpsShortTpwd string `json:"cps_short_tpwd"`
  163. CpsShortUrl string `json:"cps_short_url"`
  164. CpsFullTpwd string `json:"cps_full_tpwd"`
  165. } `json:"link_info_dto"`
  166. } `json:"event_url_list"`
  167. } `json:"event_url_list"`
  168. ItemUrlList struct {
  169. ItemUrlList []struct {
  170. Msg string `json:"msg"`
  171. Code int `json:"code"`
  172. PromotionInfoDto struct {
  173. CommissionRate string `json:"commission_rate"`
  174. } `json:"promotion_info_dto"`
  175. CouponInfoDto struct {
  176. CouponEndTime string `json:"coupon_end_time"`
  177. ActivityId string `json:"activity_id"`
  178. CouponRemainCount int `json:"coupon_remain_count"`
  179. CouponAmount string `json:"coupon_amount"`
  180. CouponStartTime string `json:"coupon_start_time"`
  181. CouponDesc string `json:"coupon_desc"`
  182. } `json:"coupon_info_dto"`
  183. LinkInfoDto struct {
  184. CouponLongUrl string `json:"coupon_long_url"`
  185. MaterialType int `json:"material_type"`
  186. ItemId string `json:"item_id"`
  187. CpsLongUrl string `json:"cps_long_url"`
  188. CpsShortTpwd string `json:"cps_short_tpwd"`
  189. CouponShortTpwd string `json:"coupon_short_tpwd"`
  190. CpsShortUrl string `json:"cps_short_url"`
  191. CouponShortUrl string `json:"coupon_short_url"`
  192. CouponFullTpwd string `json:"coupon_full_tpwd"`
  193. CpsFullTpwd string `json:"cps_full_tpwd"`
  194. } `json:"link_info_dto"`
  195. } `json:"item_url_list"`
  196. } `json:"item_url_list"`
  197. } `json:"data"`
  198. BizErrorDesc int `json:"biz_error_desc"`
  199. ResultMsg string `json:"result_msg"`
  200. } `json:"tbk_sc_general_link_convert_response"`
  201. }
  202. if err = json.Unmarshal(resp, &tmp); err != nil {
  203. return nil, err
  204. }
  205. url := ""
  206. hasCoupon := false
  207. itemUrl := ""
  208. maxCommissionRate := ""
  209. tkl := ""
  210. shortTkl := ""
  211. isitem := 0
  212. for _, v := range tmp.TbkScGeneralLinkConvertResponse.Data.ItemUrlList.ItemUrlList {
  213. url = v.LinkInfoDto.CouponLongUrl
  214. tkl = v.LinkInfoDto.CouponFullTpwd
  215. shortTkl = v.LinkInfoDto.CouponShortTpwd
  216. if url == "" {
  217. url = v.LinkInfoDto.CpsLongUrl
  218. tkl = v.LinkInfoDto.CpsFullTpwd
  219. shortTkl = v.LinkInfoDto.CpsShortTpwd
  220. }
  221. if v.LinkInfoDto.CouponLongUrl != "" {
  222. hasCoupon = true
  223. }
  224. itemId = v.LinkInfoDto.ItemId
  225. itemUrl = url
  226. isitem = 1
  227. maxCommissionRate = v.PromotionInfoDto.CommissionRate
  228. }
  229. for _, v := range tmp.TbkScGeneralLinkConvertResponse.Data.MaterialUrlList.MaterialUrlList {
  230. url = v.LinkInfoDto.CouponLongUrl
  231. tkl = v.LinkInfoDto.CouponFullTpwd
  232. shortTkl = v.LinkInfoDto.CouponShortTpwd
  233. if url == "" {
  234. url = v.LinkInfoDto.CpsLongUrl
  235. tkl = v.LinkInfoDto.CpsFullTpwd
  236. shortTkl = v.LinkInfoDto.CpsShortTpwd
  237. }
  238. if v.LinkInfoDto.CouponLongUrl != "" {
  239. hasCoupon = true
  240. }
  241. //1—单品 2—店铺 3—会场 4-承接开放 5-优惠券
  242. if v.Code == 0 && (v.LinkInfoDto.MaterialType == 1 || v.LinkInfoDto.MaterialType == 0) {
  243. itemId = v.LinkInfoDto.MaterialId
  244. isitem = 1
  245. }
  246. itemUrl = url
  247. maxCommissionRate = v.PromotionInfoDto.CommissionRate
  248. }
  249. if isitem == 0 && len(tmp.TbkScGeneralLinkConvertResponse.Data.MaterialUrlList.MaterialUrlList) > 0 {
  250. itemId = ""
  251. }
  252. for _, v := range tmp.TbkScGeneralLinkConvertResponse.Data.EventUrlList.EventUrlList {
  253. url = v.LinkInfoDto.CpsLongUrl
  254. tkl = v.LinkInfoDto.CpsFullTpwd
  255. shortTkl = v.LinkInfoDto.CpsShortTpwd
  256. itemUrl = url
  257. }
  258. return &md.ConvertedUrls{
  259. Tkl: tkl,
  260. ShortTkl: shortTkl,
  261. ItemId: itemId,
  262. URL: url,
  263. ItemUrl: itemUrl,
  264. ShortenURL: url,
  265. NoOpenAppURL: url,
  266. AppURL: url,
  267. HasCoupon: hasCoupon,
  268. CommissionRate: maxCommissionRate,
  269. }, nil
  270. }
  271. type T struct {
  272. TbkScActivityInfoGetResponse struct {
  273. Data struct {
  274. ClickUrl string `json:"click_url"`
  275. PageEndTime string `json:"page_end_time"`
  276. PageName string `json:"page_name"`
  277. PageStartTime string `json:"page_start_time"`
  278. TerminalType string `json:"terminal_type"`
  279. } `json:"data"`
  280. RequestId string `json:"request_id"`
  281. } `json:"tbk_sc_activity_info_get_response"`
  282. }
  283. func (t *TB) ActivityConvertUrlSC(activityMaterialId, pid string, relationId int64) (*md.OfficialRecommendUrl, error) {
  284. method := "taobao.tbk.sc.activity.info.get"
  285. _, siteId, adZoneId := SplitPid(pid)
  286. args := map[string]string{
  287. "activity_material_id": activityMaterialId,
  288. "session": t.UserSID, // 一般用站长就可以转链
  289. "adzone_id": adZoneId,
  290. "platform": "2",
  291. "site_id": siteId,
  292. }
  293. if relationId > 0 {
  294. args["relation_id"] = strconv.FormatInt(relationId, 10)
  295. }
  296. resp, err := send(args, method, t.Svc_AK, t.Svc_SK)
  297. if err != nil {
  298. return nil, err
  299. }
  300. var tmp struct {
  301. TbkScActivityInfoGetResponse struct {
  302. Data struct {
  303. WxQrcodeUrl string `json:"wx_qrcode_url"`
  304. WxMiniprogramPath string `json:"wx_miniprogram_path"`
  305. Url string `json:"click_url"`
  306. ShortClickurl string `json:"short_click_url"`
  307. } `json:"data"`
  308. } `json:"tbk_sc_activity_info_get_response"`
  309. }
  310. if err = json.Unmarshal(resp, &tmp); err != nil {
  311. return nil, err
  312. }
  313. url := tmp.TbkScActivityInfoGetResponse.Data.Url
  314. if tmp.TbkScActivityInfoGetResponse.Data.ShortClickurl != "" {
  315. url = tmp.TbkScActivityInfoGetResponse.Data.ShortClickurl
  316. }
  317. return &md.OfficialRecommendUrl{
  318. WxQrcodeUrl: tmp.TbkScActivityInfoGetResponse.Data.WxQrcodeUrl,
  319. WxMiniprogramPath: tmp.TbkScActivityInfoGetResponse.Data.WxMiniprogramPath,
  320. Url: url,
  321. }, nil
  322. }