|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- package taobao
-
- import (
- "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md"
- "encoding/json"
- "github.com/syyongx/php2go"
- "strconv"
- "strings"
- )
-
- type UrlInfo struct {
- CategoryID int `json:"category_id"`
- CouponClickURL string `json:"coupon_click_url"`
- CouponEndTime string `json:"coupon_end_time"`
- CouponInfo string `json:"coupon_info"`
- CouponRemainCount int `json:"coupon_remain_count"`
- CouponStartTime string `json:"coupon_start_time"`
- CouponTotalCount int `json:"coupon_total_count"`
- ItemID string `json:"item_id"`
- ItemURL string `json:"item_url"`
- MaxCommissionRate string `json:"max_commission_rate"`
- MinCommissionRate string `json:"min_commission_rate"`
- RewardInfo int `json:"reward_info"`
- }
-
- // 淘宝转链
- func (t *TB) ConvertUrlSC(itemId, pid, externalId string) (*md.ConvertedUrls, error) {
- method := "taobao.tbk.privilege.get"
- _, siteId, adZoneId := SplitPid(pid)
- args := map[string]string{
- "item_id": itemId,
- "session": t.UserSID, // 一般用站长就可以转链
- "adzone_id": adZoneId,
- "platform": "2",
- "site_id": siteId,
- }
-
- if php2go.IsNumeric(itemId) {
- args["biz_scene_id"] = "2"
- }
- if externalId != "" {
- args["external_id"] = externalId
- }
- resp, err := send(args, method, t.Svc_AK, t.Svc_SK)
- if err != nil {
- return nil, err
- }
- var tmp struct {
- TbkPrivilegeGetResponse struct {
- Result struct {
- Data UrlInfo `json:"data"`
- } `json:"result"`
- RequestID string `json:"request_id"`
- } `json:"tbk_privilege_get_response"`
- }
- if err = json.Unmarshal(resp, &tmp); err != nil {
- return nil, err
- }
- url := tmp.TbkPrivilegeGetResponse.Result.Data.ItemURL
- hasCoupon := false
- itemUrl := tmp.TbkPrivilegeGetResponse.Result.Data.ItemURL
- maxCommissionRate := tmp.TbkPrivilegeGetResponse.Result.Data.MaxCommissionRate
- if tmp.TbkPrivilegeGetResponse.Result.Data.CouponClickURL != "" {
- hasCoupon = true
- url = tmp.TbkPrivilegeGetResponse.Result.Data.CouponClickURL
- }
- return &md.ConvertedUrls{
- ItemId: itemId,
- URL: url,
- ItemUrl: itemUrl,
- ShortenURL: url,
- NoOpenAppURL: url,
- AppURL: url,
- HasCoupon: hasCoupon,
- CommissionRate: maxCommissionRate,
- }, nil
- }
-
- func (t *TB) WnConvertUrlSC(itemId, types, pid, externalId string) (*md.ConvertedUrls, error) {
- method := "taobao.tbk.sc.general.link.convert"
- _, siteId, adZoneId := SplitPid(pid)
- args := map[string]string{
- "session": t.UserSID, // 一般用站长就可以转链
- "adzone_id": adZoneId,
- "platform": "2",
- "site_id": siteId,
- }
- if types == "1" || types == "4" { // 商品ID列表
- args["item_id_list"] = itemId
- args["biz_scene_id"] = "1"
- if externalId != "0" && externalId != "" {
- args["relation_id"] = externalId
- }
- }
- if types == "2" { //物料列表,可以为url或淘口令
- args["material_list"] = itemId
- if externalId != "0" && externalId != "" {
- args["relation_id"] = externalId
- }
- }
-
- if types == "3" { // 会场ID列表
- args["page_id_list"] = itemId
- if externalId != "" {
- args["relation_id"] = externalId
- }
- }
-
- resp, err := send(args, method, t.Svc_AK, t.Svc_SK)
- if err != nil {
- return nil, err
- }
- var tmp struct {
- TbkScGeneralLinkConvertResponse struct {
- Data struct {
- MaterialUrlList struct {
- MaterialUrlList []struct {
- Msg string `json:"msg"`
- Code int `json:"code"`
- PromotionInfoDto struct {
- CommissionRate string `json:"commission_rate"`
- } `json:"promotion_info_dto"`
- CouponInfoDto struct {
- CouponEndTime string `json:"coupon_end_time"`
- ActivityId string `json:"activity_id"`
- CouponRemainCount int `json:"coupon_remain_count"`
- CouponAmount string `json:"coupon_amount"`
- CouponStartTime string `json:"coupon_start_time"`
- CouponDesc string `json:"coupon_desc"`
- CouponType int `json:"coupon_type"`
- } `json:"coupon_info_dto"`
- LinkInfoDto struct {
- CouponLongUrl string `json:"coupon_long_url"`
- MaterialType int `json:"material_type"`
- TpwdOriginUrl string `json:"tpwd_origin_url"`
- MaterialId string `json:"material_id"`
- CpsLongUrl string `json:"cps_long_url"`
- CpsShortTpwd string `json:"cps_short_tpwd"`
- TkBizType int `json:"tk_biz_type"`
- CouponShortTpwd string `json:"coupon_short_tpwd"`
- CpsShortUrl string `json:"cps_short_url"`
- CouponShortUrl string `json:"coupon_short_url"`
- CouponFullTpwd string `json:"coupon_full_tpwd"`
- CpsFullTpwd string `json:"cps_full_tpwd"`
- } `json:"link_info_dto"`
- } `json:"material_url_list"`
- } `json:"material_url_list"`
- ShopUrlList struct {
- ShopUrlList []struct {
- Msg string `json:"msg"`
- Code int `json:"code"`
- LinkInfoDto struct {
- MaterialType int `json:"material_type"`
- SellerId string `json:"seller_id"`
- CpsLongUrl string `json:"cps_long_url"`
- CpsShortTpwd string `json:"cps_short_tpwd"`
- CpsShortUrl string `json:"cps_short_url"`
- CpsFullTpwd string `json:"cps_full_tpwd"`
- } `json:"link_info_dto"`
- } `json:"shop_url_list"`
- } `json:"shop_url_list"`
- EventUrlList struct {
- EventUrlList []struct {
- Msg string `json:"msg"`
- Code int `json:"code"`
- LinkInfoDto struct {
- MaterialType int `json:"material_type"`
- PageId string `json:"page_id"`
- CpsLongUrl string `json:"cps_long_url"`
- CpsShortTpwd string `json:"cps_short_tpwd"`
- CpsShortUrl string `json:"cps_short_url"`
- CpsFullTpwd string `json:"cps_full_tpwd"`
- } `json:"link_info_dto"`
- } `json:"event_url_list"`
- } `json:"event_url_list"`
- ItemUrlList struct {
- ItemUrlList []struct {
- Msg string `json:"msg"`
- Code int `json:"code"`
- PromotionInfoDto struct {
- CommissionRate string `json:"commission_rate"`
- } `json:"promotion_info_dto"`
- CouponInfoDto struct {
- CouponEndTime string `json:"coupon_end_time"`
- ActivityId string `json:"activity_id"`
- CouponRemainCount int `json:"coupon_remain_count"`
- CouponAmount string `json:"coupon_amount"`
- CouponStartTime string `json:"coupon_start_time"`
- CouponDesc string `json:"coupon_desc"`
- } `json:"coupon_info_dto"`
- LinkInfoDto struct {
- CouponLongUrl string `json:"coupon_long_url"`
- MaterialType int `json:"material_type"`
- ItemId string `json:"item_id"`
- CpsLongUrl string `json:"cps_long_url"`
- CpsShortTpwd string `json:"cps_short_tpwd"`
- CouponShortTpwd string `json:"coupon_short_tpwd"`
- CpsShortUrl string `json:"cps_short_url"`
- CouponShortUrl string `json:"coupon_short_url"`
- CouponFullTpwd string `json:"coupon_full_tpwd"`
- CpsFullTpwd string `json:"cps_full_tpwd"`
- } `json:"link_info_dto"`
- } `json:"item_url_list"`
- } `json:"item_url_list"`
- } `json:"data"`
- BizErrorDesc int `json:"biz_error_desc"`
- ResultMsg string `json:"result_msg"`
- } `json:"tbk_sc_general_link_convert_response"`
- }
- if err = json.Unmarshal(resp, &tmp); err != nil {
- return nil, err
- }
- url := ""
- hasCoupon := false
- itemUrl := ""
- maxCommissionRate := ""
- tkl := ""
- shortTkl := ""
- isitem := 0
- for _, v := range tmp.TbkScGeneralLinkConvertResponse.Data.ItemUrlList.ItemUrlList {
- url = v.LinkInfoDto.CouponLongUrl
- tkl = v.LinkInfoDto.CouponFullTpwd
- shortTkl = v.LinkInfoDto.CouponShortTpwd
- if url == "" {
- url = v.LinkInfoDto.CpsLongUrl
- tkl = v.LinkInfoDto.CpsFullTpwd
- shortTkl = v.LinkInfoDto.CpsShortTpwd
- }
- if v.LinkInfoDto.CouponLongUrl != "" {
- hasCoupon = true
- }
- itemId = v.LinkInfoDto.ItemId
- itemUrl = url
- isitem = 1
- maxCommissionRate = v.PromotionInfoDto.CommissionRate
- }
-
- for _, v := range tmp.TbkScGeneralLinkConvertResponse.Data.MaterialUrlList.MaterialUrlList {
- if v.LinkInfoDto.CouponLongUrl == "" && v.LinkInfoDto.CpsLongUrl == "" {
- continue
- }
- url = v.LinkInfoDto.CouponLongUrl
- tkl = v.LinkInfoDto.CouponFullTpwd
- shortTkl = v.LinkInfoDto.CouponShortTpwd
- if url == "" {
- url = v.LinkInfoDto.CpsLongUrl
- tkl = v.LinkInfoDto.CpsFullTpwd
- shortTkl = v.LinkInfoDto.CpsShortTpwd
- }
- if v.LinkInfoDto.CouponLongUrl != "" {
- hasCoupon = true
- }
- //1—单品 2—店铺 3—会场 4-承接开放 5-优惠券
- if v.Code == 0 && (v.LinkInfoDto.MaterialType == 1 || v.LinkInfoDto.MaterialType == 0) {
- itemId = v.LinkInfoDto.MaterialId
- isitem = 1
- }
- itemUrl = url
- maxCommissionRate = v.PromotionInfoDto.CommissionRate
- }
- if isitem == 0 && len(tmp.TbkScGeneralLinkConvertResponse.Data.MaterialUrlList.MaterialUrlList) > 0 {
- itemId = ""
- }
- for _, v := range tmp.TbkScGeneralLinkConvertResponse.Data.EventUrlList.EventUrlList {
- url = v.LinkInfoDto.CpsLongUrl
- tkl = v.LinkInfoDto.CpsFullTpwd
- shortTkl = v.LinkInfoDto.CpsShortTpwd
- itemUrl = url
- }
- isDown := "0"
- if tkl == "" {
- isDown = "2"
- }
- if strings.Contains(string(resp), "该商品已下架") {
- isDown = "1"
- }
- return &md.ConvertedUrls{
- IsDown: isDown,
- Tkl: tkl,
- ShortTkl: shortTkl,
- ItemId: itemId,
- URL: url,
- ItemUrl: itemUrl,
- ShortenURL: url,
- NoOpenAppURL: url,
- AppURL: url,
- HasCoupon: hasCoupon,
- CommissionRate: maxCommissionRate,
- }, nil
- }
-
- type T struct {
- TbkScActivityInfoGetResponse struct {
- Data struct {
- ClickUrl string `json:"click_url"`
- PageEndTime string `json:"page_end_time"`
- PageName string `json:"page_name"`
- PageStartTime string `json:"page_start_time"`
- TerminalType string `json:"terminal_type"`
- } `json:"data"`
- RequestId string `json:"request_id"`
- } `json:"tbk_sc_activity_info_get_response"`
- }
-
- func (t *TB) ActivityConvertUrlSC(activityMaterialId, pid string, relationId int64) (*md.OfficialRecommendUrl, error) {
- method := "taobao.tbk.sc.activity.info.get"
- _, siteId, adZoneId := SplitPid(pid)
- args := map[string]string{
- "activity_material_id": activityMaterialId,
- "session": t.UserSID, // 一般用站长就可以转链
- "adzone_id": adZoneId,
- "platform": "2",
- "site_id": siteId,
- }
- if relationId > 0 {
- args["relation_id"] = strconv.FormatInt(relationId, 10)
- }
- resp, err := send(args, method, t.Svc_AK, t.Svc_SK)
- if err != nil {
- return nil, err
- }
- var tmp struct {
- TbkScActivityInfoGetResponse struct {
- Data struct {
- WxQrcodeUrl string `json:"wx_qrcode_url"`
- WxMiniprogramPath string `json:"wx_miniprogram_path"`
- Url string `json:"click_url"`
- ShortClickurl string `json:"short_click_url"`
- } `json:"data"`
- } `json:"tbk_sc_activity_info_get_response"`
- }
- if err = json.Unmarshal(resp, &tmp); err != nil {
- return nil, err
- }
-
- url := tmp.TbkScActivityInfoGetResponse.Data.Url
- if tmp.TbkScActivityInfoGetResponse.Data.ShortClickurl != "" {
- url = tmp.TbkScActivityInfoGetResponse.Data.ShortClickurl
- }
- return &md.OfficialRecommendUrl{
- WxQrcodeUrl: tmp.TbkScActivityInfoGetResponse.Data.WxQrcodeUrl,
- WxMiniprogramPath: tmp.TbkScActivityInfoGetResponse.Data.WxMiniprogramPath,
- Url: url,
- }, nil
- }
|