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

convert_url.go 12 KiB

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