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

340 lines
11 KiB

  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 php2go.IsNumeric(itemId) {
  86. args["biz_scene_id"] = "2"
  87. }
  88. if externalId != "" && types == "1" {
  89. args["relation_id"] = externalId
  90. }
  91. if externalId != "" && types == "4" {
  92. args["external_id"] = externalId
  93. }
  94. }
  95. if types == "2" { //物料列表,可以为url或淘口令
  96. args["material_list"] = itemId
  97. if externalId != "" {
  98. args["relation_id"] = externalId
  99. }
  100. }
  101. if types == "3" { // 会场ID列表
  102. args["page_id_list"] = itemId
  103. if externalId != "" {
  104. args["relation_id"] = externalId
  105. }
  106. }
  107. resp, err := send(args, method, t.Svc_AK, t.Svc_SK)
  108. if err != nil {
  109. return nil, err
  110. }
  111. var tmp struct {
  112. TbkScGeneralLinkConvertResponse struct {
  113. Data struct {
  114. MaterialUrlList struct {
  115. MaterialUrlList []struct {
  116. Msg string `json:"msg"`
  117. Code int `json:"code"`
  118. PromotionInfoDto struct {
  119. CommissionRate string `json:"commission_rate"`
  120. } `json:"promotion_info_dto"`
  121. CouponInfoDto struct {
  122. CouponEndTime string `json:"coupon_end_time"`
  123. ActivityId string `json:"activity_id"`
  124. CouponRemainCount int `json:"coupon_remain_count"`
  125. CouponAmount string `json:"coupon_amount"`
  126. CouponStartTime string `json:"coupon_start_time"`
  127. CouponDesc string `json:"coupon_desc"`
  128. CouponType int `json:"coupon_type"`
  129. } `json:"coupon_info_dto"`
  130. LinkInfoDto struct {
  131. CouponLongUrl string `json:"coupon_long_url"`
  132. MaterialType int `json:"material_type"`
  133. TpwdOriginUrl string `json:"tpwd_origin_url"`
  134. MaterialId string `json:"material_id"`
  135. CpsLongUrl string `json:"cps_long_url"`
  136. CpsShortTpwd string `json:"cps_short_tpwd"`
  137. TkBizType int `json:"tk_biz_type"`
  138. CouponShortTpwd string `json:"coupon_short_tpwd"`
  139. CpsShortUrl string `json:"cps_short_url"`
  140. CouponShortUrl string `json:"coupon_short_url"`
  141. CouponFullTpwd string `json:"coupon_full_tpwd"`
  142. CpsFullTpwd string `json:"cps_full_tpwd"`
  143. } `json:"link_info_dto"`
  144. } `json:"material_url_list"`
  145. } `json:"material_url_list"`
  146. ShopUrlList struct {
  147. ShopUrlList []struct {
  148. Msg string `json:"msg"`
  149. Code int `json:"code"`
  150. LinkInfoDto struct {
  151. MaterialType int `json:"material_type"`
  152. SellerId string `json:"seller_id"`
  153. CpsLongUrl string `json:"cps_long_url"`
  154. CpsShortTpwd string `json:"cps_short_tpwd"`
  155. CpsShortUrl string `json:"cps_short_url"`
  156. CpsFullTpwd string `json:"cps_full_tpwd"`
  157. } `json:"link_info_dto"`
  158. } `json:"shop_url_list"`
  159. } `json:"shop_url_list"`
  160. EventUrlList struct {
  161. EventUrlList []struct {
  162. Msg string `json:"msg"`
  163. Code int `json:"code"`
  164. LinkInfoDto struct {
  165. MaterialType int `json:"material_type"`
  166. PageId string `json:"page_id"`
  167. CpsLongUrl string `json:"cps_long_url"`
  168. CpsShortTpwd string `json:"cps_short_tpwd"`
  169. CpsShortUrl string `json:"cps_short_url"`
  170. CpsFullTpwd string `json:"cps_full_tpwd"`
  171. } `json:"link_info_dto"`
  172. } `json:"event_url_list"`
  173. } `json:"event_url_list"`
  174. ItemUrlList struct {
  175. ItemUrlList []struct {
  176. Msg string `json:"msg"`
  177. Code int `json:"code"`
  178. PromotionInfoDto struct {
  179. CommissionRate string `json:"commission_rate"`
  180. } `json:"promotion_info_dto"`
  181. CouponInfoDto struct {
  182. CouponEndTime string `json:"coupon_end_time"`
  183. ActivityId string `json:"activity_id"`
  184. CouponRemainCount int `json:"coupon_remain_count"`
  185. CouponAmount string `json:"coupon_amount"`
  186. CouponStartTime string `json:"coupon_start_time"`
  187. CouponDesc string `json:"coupon_desc"`
  188. } `json:"coupon_info_dto"`
  189. LinkInfoDto struct {
  190. CouponLongUrl string `json:"coupon_long_url"`
  191. MaterialType int `json:"material_type"`
  192. ItemId string `json:"item_id"`
  193. CpsLongUrl string `json:"cps_long_url"`
  194. CpsShortTpwd string `json:"cps_short_tpwd"`
  195. CouponShortTpwd string `json:"coupon_short_tpwd"`
  196. CpsShortUrl string `json:"cps_short_url"`
  197. CouponShortUrl string `json:"coupon_short_url"`
  198. CouponFullTpwd string `json:"coupon_full_tpwd"`
  199. CpsFullTpwd string `json:"cps_full_tpwd"`
  200. } `json:"link_info_dto"`
  201. } `json:"item_url_list"`
  202. } `json:"item_url_list"`
  203. } `json:"data"`
  204. BizErrorDesc int `json:"biz_error_desc"`
  205. ResultMsg string `json:"result_msg"`
  206. } `json:"tbk_sc_general_link_convert_response"`
  207. }
  208. if err = json.Unmarshal(resp, &tmp); err != nil {
  209. return nil, err
  210. }
  211. url := ""
  212. hasCoupon := false
  213. itemUrl := ""
  214. maxCommissionRate := ""
  215. tkl := ""
  216. shortTkl := ""
  217. isitem := 0
  218. for _, v := range tmp.TbkScGeneralLinkConvertResponse.Data.ItemUrlList.ItemUrlList {
  219. url = v.LinkInfoDto.CouponLongUrl
  220. tkl = v.LinkInfoDto.CouponFullTpwd
  221. shortTkl = v.LinkInfoDto.CouponShortTpwd
  222. if url == "" {
  223. url = v.LinkInfoDto.CpsLongUrl
  224. tkl = v.LinkInfoDto.CpsFullTpwd
  225. shortTkl = v.LinkInfoDto.CpsShortTpwd
  226. }
  227. if v.LinkInfoDto.CouponLongUrl != "" {
  228. hasCoupon = true
  229. }
  230. itemId = v.LinkInfoDto.ItemId
  231. itemUrl = url
  232. isitem = 1
  233. maxCommissionRate = v.PromotionInfoDto.CommissionRate
  234. }
  235. for _, v := range tmp.TbkScGeneralLinkConvertResponse.Data.MaterialUrlList.MaterialUrlList {
  236. url = v.LinkInfoDto.CouponLongUrl
  237. tkl = v.LinkInfoDto.CouponFullTpwd
  238. shortTkl = v.LinkInfoDto.CouponShortTpwd
  239. if url == "" {
  240. url = v.LinkInfoDto.CpsLongUrl
  241. tkl = v.LinkInfoDto.CpsFullTpwd
  242. shortTkl = v.LinkInfoDto.CpsShortTpwd
  243. }
  244. if v.LinkInfoDto.CouponLongUrl != "" {
  245. hasCoupon = true
  246. }
  247. //1—单品 2—店铺 3—会场 4-承接开放 5-优惠券
  248. if v.Code == 0 && (v.LinkInfoDto.MaterialType == 1 || v.LinkInfoDto.MaterialType == 0) {
  249. itemId = v.LinkInfoDto.MaterialId
  250. isitem = 1
  251. }
  252. itemUrl = url
  253. maxCommissionRate = v.PromotionInfoDto.CommissionRate
  254. }
  255. if isitem == 0 && len(tmp.TbkScGeneralLinkConvertResponse.Data.MaterialUrlList.MaterialUrlList) > 0 {
  256. itemId = ""
  257. }
  258. for _, v := range tmp.TbkScGeneralLinkConvertResponse.Data.EventUrlList.EventUrlList {
  259. url = v.LinkInfoDto.CpsLongUrl
  260. tkl = v.LinkInfoDto.CpsFullTpwd
  261. shortTkl = v.LinkInfoDto.CpsShortTpwd
  262. itemUrl = url
  263. }
  264. return &md.ConvertedUrls{
  265. Tkl: tkl,
  266. ShortTkl: shortTkl,
  267. ItemId: itemId,
  268. URL: url,
  269. ItemUrl: itemUrl,
  270. ShortenURL: url,
  271. NoOpenAppURL: url,
  272. AppURL: url,
  273. HasCoupon: hasCoupon,
  274. CommissionRate: maxCommissionRate,
  275. }, nil
  276. }
  277. type T struct {
  278. TbkScActivityInfoGetResponse struct {
  279. Data struct {
  280. ClickUrl string `json:"click_url"`
  281. PageEndTime string `json:"page_end_time"`
  282. PageName string `json:"page_name"`
  283. PageStartTime string `json:"page_start_time"`
  284. TerminalType string `json:"terminal_type"`
  285. } `json:"data"`
  286. RequestId string `json:"request_id"`
  287. } `json:"tbk_sc_activity_info_get_response"`
  288. }
  289. func (t *TB) ActivityConvertUrlSC(activityMaterialId, pid string, relationId int64) (*md.OfficialRecommendUrl, error) {
  290. method := "taobao.tbk.sc.activity.info.get"
  291. _, siteId, adZoneId := SplitPid(pid)
  292. args := map[string]string{
  293. "activity_material_id": activityMaterialId,
  294. "session": t.UserSID, // 一般用站长就可以转链
  295. "adzone_id": adZoneId,
  296. "platform": "2",
  297. "site_id": siteId,
  298. }
  299. if relationId > 0 {
  300. args["relation_id"] = strconv.FormatInt(relationId, 10)
  301. }
  302. resp, err := send(args, method, t.Svc_AK, t.Svc_SK)
  303. if err != nil {
  304. return nil, err
  305. }
  306. var tmp struct {
  307. TbkScActivityInfoGetResponse struct {
  308. Data struct {
  309. WxQrcodeUrl string `json:"wx_qrcode_url"`
  310. WxMiniprogramPath string `json:"wx_miniprogram_path"`
  311. Url string `json:"click_url"`
  312. ShortClickurl string `json:"short_click_url"`
  313. } `json:"data"`
  314. } `json:"tbk_sc_activity_info_get_response"`
  315. }
  316. if err = json.Unmarshal(resp, &tmp); err != nil {
  317. return nil, err
  318. }
  319. url := tmp.TbkScActivityInfoGetResponse.Data.Url
  320. if tmp.TbkScActivityInfoGetResponse.Data.ShortClickurl != "" {
  321. url = tmp.TbkScActivityInfoGetResponse.Data.ShortClickurl
  322. }
  323. return &md.OfficialRecommendUrl{
  324. WxQrcodeUrl: tmp.TbkScActivityInfoGetResponse.Data.WxQrcodeUrl,
  325. WxMiniprogramPath: tmp.TbkScActivityInfoGetResponse.Data.WxMiniprogramPath,
  326. Url: url,
  327. }, nil
  328. }