From 284bdbd22e7338654e2a09da117542242289534c Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Fri, 24 Nov 2023 16:41:30 +0800 Subject: [PATCH] test --- chain_transfer/chain_transfer.go | 171 +--- chain_transfer/svc/svc_kuaishou.go | 149 +++ chain_transfer/svc/svc_turnchain.go | 1292 +++++++++++++++++++++++++++ chain_transfer/svc/turn_chain.go | 101 +++ chain_transfer/turn_chain.go | 419 +++++++++ dataoke/dels_content_parse.go | 55 ++ db/db_sys_union.go | 14 + db/offical/db_master_list_cfg.go | 19 + db/offical/db_user_app_list.go | 15 + db/offical/model/master_list_cfg.go | 9 + db/offical/model/user_app_list.go | 33 + go.mod | 1 + go.sum | 2 + jd/api.go | 17 + jd/client.go | 285 ++++++ jd/convert_url.go | 5 + jd/errors.go | 8 + jd/featured.go | 15 + jd/guess.go | 19 + jd/jd_zhimeng.go | 13 + jd/model.go | 88 ++ jd/order_track.go | 13 + jd/recommend.go | 15 + jd/sdk.go | 95 ++ md/kuaishou.go | 101 +++ md/md_chain.go | 98 ++ md/official_recommend_list.go | 26 + md/product_detail.go | 3 + md/provider.go | 1 + md/tik_tok.go | 51 +- md/url.go | 1 + pdd/api.go | 49 + pdd/detail.go | 13 + pdd/pdd_zhimeng.go | 10 + pdd/recommend.go | 91 ++ tik_tok/svc_tik_tok_convert.go | 36 + tik_tok/svc_tik_tok_goods.go | 33 + utils/open_platform.go | 135 +++ utils/string.go | 40 + zhimeng/kuaishou_goods.go | 36 + zhimeng/pdd_convert_url.go | 116 +++ zhimeng/tik_tok_goods.go | 1 + zhimeng/word_parse.go | 54 ++ 43 files changed, 3555 insertions(+), 193 deletions(-) create mode 100644 chain_transfer/svc/svc_kuaishou.go create mode 100644 chain_transfer/svc/svc_turnchain.go create mode 100644 chain_transfer/svc/turn_chain.go create mode 100644 chain_transfer/turn_chain.go create mode 100644 dataoke/dels_content_parse.go create mode 100644 db/offical/db_master_list_cfg.go create mode 100644 db/offical/db_user_app_list.go create mode 100644 db/offical/model/master_list_cfg.go create mode 100644 db/offical/model/user_app_list.go create mode 100644 jd/api.go create mode 100644 jd/client.go create mode 100644 jd/convert_url.go create mode 100644 jd/errors.go create mode 100644 jd/featured.go create mode 100644 jd/guess.go create mode 100644 jd/jd_zhimeng.go create mode 100644 jd/model.go create mode 100644 jd/order_track.go create mode 100644 jd/recommend.go create mode 100644 jd/sdk.go create mode 100644 md/kuaishou.go create mode 100644 md/md_chain.go create mode 100644 md/official_recommend_list.go create mode 100644 pdd/api.go create mode 100644 pdd/detail.go create mode 100644 pdd/pdd_zhimeng.go create mode 100644 pdd/recommend.go create mode 100644 utils/open_platform.go create mode 100644 zhimeng/word_parse.go diff --git a/chain_transfer/chain_transfer.go b/chain_transfer/chain_transfer.go index ba07a84..6126d4d 100644 --- a/chain_transfer/chain_transfer.go +++ b/chain_transfer/chain_transfer.go @@ -1,17 +1,16 @@ package chain_transfer import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/chain_transfer/svc" "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db" "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/haodanku" "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md" "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/taobao" "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tik_tok" zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" - "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/zhimeng" "fmt" "github.com/tidwall/gjson" "strings" - "time" "xorm.io/xorm" ) @@ -51,7 +50,7 @@ func ChainTransfer(eg *xorm.Engine, args map[string]string) map[string]string { if tbItemInfo != nil { args["gid"] = zhios_third_party_utils.AnyToString(tbItemInfo.ItemID) } - curls, err := ConvertUrl(eg, args) + curls, err := svc.ConvertUrl(eg, args) if err != nil || curls == nil { return res } @@ -149,7 +148,7 @@ func ChainTransfer(eg *xorm.Engine, args map[string]string) map[string]string { } if zhios_third_party_utils.InArr(args["provider"], []string{md.PVD_TB, md.PVD_TM}) == false { - curls, err := ConvertUrl(eg, args) + curls, err := svc.ConvertUrl(eg, args) if err != nil || curls == nil { return res } @@ -167,167 +166,3 @@ func ChainTransfer(eg *xorm.Engine, args map[string]string) map[string]string { } return res } - -func ConvertUrl(eg *xorm.Engine, args map[string]string) (*md.ConvertedUrls, error) { - var ( - err error - ) - var urls *md.ConvertedUrls - switch args["provider"] { - case md.PVD_TB, md.PVD_TM: - taobaoSdk, err := taobao.NewTaobaoSDK(eg, args["master_id"], args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"])) - if err != nil { - return nil, err - } - tb := taobaoSdk - var promoId = tb.CloudPromoIdWeb - if promoId == "" { - promoId = tb.SharePromoIdWeb - } - var promoId1 string - var taobaoShareId1 string - var IsWxTaobaoAuth bool - fmt.Println(IsWxTaobaoAuth) - if zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"]) == 0 { - if tb.AppletIsAuth == "1" { - IsWxTaobaoAuth, taobaoShareId1, promoId1 = taobao.TaobaoRelationPid(eg, args) - if IsWxTaobaoAuth == false { - return nil, err - } else { - promoId = promoId1 - } - } - } - thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key") - if thirdZmAppKeyData == nil || err != nil { - return urls, err - } - thirdZmAppSecretData, err := db.SysCfgGetOne(eg, "third_zm_app_secret") - if thirdZmAppSecretData == nil || err != nil { - return urls, err - } - urls, err = zhimeng.TaobaoConvertUrl(thirdZmAppKeyData.Val, - thirdZmAppSecretData.Val, args["gid"], promoId, tb.UserSID, "", tb.Svc_AK) - if urls != nil { - if taobaoShareId1 != "" { - urls.TbShareId = zhios_third_party_utils.StrToInt64(taobaoShareId1) - } - if promoId1 != "" { - urls.NewPid = promoId1 - } - } - case md.PVD_JDS: - thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key") - if thirdZmAppKeyData == nil || err != nil { - return urls, err - } - thirdZmAppSecretData, err := db.SysCfgGetOne(eg, "third_zm_app_secret") - if thirdZmAppSecretData == nil || err != nil { - return urls, err - } - // 初始化京东配置 - pid := args["acc_jd_share_id"] - postData := make(map[string]interface{}) - postData["gid"] = args["gid"] - postData["appkey"] = thirdZmAppKeyData.Val - postData["secret_key"] = thirdZmAppSecretData.Val - jdData, err := zhimeng.NewZhiMengJingDongSDK(). - SelectFunction("getgoodsinfo"). - WithArgs(postData). - Result() - mdData := &md.MoreDetailResponse{} - // to struct - couponUrl := "" - couponPrice := "" - err = jdData.ToStruct(mdData) - if err == nil && mdData != nil && mdData.CouponURL != "" { - couponUrl = mdData.CouponURL - couponPrice = mdData.CouponPrice - } - urls, err = zhimeng.JDConvertUrl( - thirdZmAppKeyData.Val, - thirdZmAppSecretData.Val, - args["gid"], - pid, - couponUrl, - couponPrice, - "") - case md.PVD_TIKTOK, md.PVD_KUAISHOU: - pid := "cloud_" + args["uid"] - thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key") - if thirdZmAppKeyData == nil || err != nil { - return urls, err - } - thirdZmAppSecretData, err := db.SysCfgGetOne(eg, "third_zm_app_secret") - if thirdZmAppSecretData == nil || err != nil { - return urls, err - } - tikTokArgs := map[string]interface{}{ - "appkey": thirdZmAppKeyData.Val, - "secret_key": thirdZmAppSecretData.Val, - "product_url": args["coupon_url"], - "external_info": pid, - } - - if args["provider"] == md.PVD_TIKTOK { - tikTokArgs["need_qr_code"] = "0" - - tikTokBase, _ := tik_tok.Base(eg, args["master_id"], "") - if zhios_third_party_utils.InArr(tikTokBase.AuthType, []string{"2", "3"}) { - if time.Now().Unix() > 1670055300 { - tikTokArgs["external_info"] = pid + "_" + args["master_id"] - } - urls, err = tik_tok.OwnTikTokUrl(tikTokBase, tikTokArgs) - } else { - tikTokArgs["external_info"] = pid + "_" + args["master_id"] - urls, err = zhimeng.TikTokUrl(tikTokArgs) - } - - } else if args["provider"] == md.PVD_KUAISHOU { - tikTokArgs["gid"] = args["gid"] - tikTokArgs["linkType"] = "101" - tikTokArgs["genPoster"] = "0" - tikTokArgs["external_info"] = pid + "_" + args["master_id"] - urls, err = zhimeng.KuaiShouUrl(tikTokArgs) - } - case md.PVD_VIP: - thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key") - if thirdZmAppKeyData == nil || err != nil { - return urls, err - } - thirdZmAppSecretData, err := db.SysCfgGetOne(eg, "third_zm_app_secret") - if thirdZmAppSecretData == nil || err != nil { - return urls, err - } - // 初始化vip配置 - pid := args["master_id"] + "_vip_cloud_" + args["uid"] - openId := args["master_id"] + "_vip_" + args["uid"] - urls, err = zhimeng.VipConvertUrl( - thirdZmAppKeyData.Val, - thirdZmAppSecretData.Val, - args["gid"], - pid, - "", "vendoapi", openId, "1") - case md.PVD_PDD: - pid := args["acc_pdd_self_id"] - thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key") - if thirdZmAppKeyData == nil || err != nil { - return urls, err - } - thirdZmAppSecretData, err := db.SysCfgGetOne(eg, "third_zm_app_secret") - if thirdZmAppSecretData == nil || err != nil { - return urls, err - } - miniApp := "0" - isShares := "2" - urls, err = zhimeng.PDDConvertUrl( - thirdZmAppKeyData.Val, - thirdZmAppSecretData.Val, - args["gid"], - pid, - "", - miniApp, - "0", isShares) - } - return urls, err -} diff --git a/chain_transfer/svc/svc_kuaishou.go b/chain_transfer/svc/svc_kuaishou.go new file mode 100644 index 0000000..8ca022c --- /dev/null +++ b/chain_transfer/svc/svc_kuaishou.go @@ -0,0 +1,149 @@ +package svc + +import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db/offical" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/kuaishou" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md" + zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/zhimeng" + "encoding/json" + "github.com/tidwall/gjson" + "xorm.io/xorm" +) + +func KuaiShouKlGoods(eg *xorm.Engine, officialEg *xorm.Engine, dbName string, tikTokArgs map[string]interface{}) *zhimeng.TikTokDetailData { + arg := map[string]interface{}{ + "cpsLink": tikTokArgs["content"], + } + param, kuaishouData := GetKuaishouKey(eg, officialEg, dbName) + if kuaishouData["authType"] != "2" { + goods, _ := zhimeng.KuaiShouKlGoods(tikTokArgs) + return goods + } + param["param"] = zhios_third_party_utils.SerializeStr(arg) + data, err := kuaishou.GetKuishouCpsKlGoods(kuaishouData["sign_secret"], param) + goods := gjson.Get(data, "data.itemId").String() + if goods == "" || err != nil { + return nil + } + detail := KuaiShouDetail(eg, officialEg, dbName, map[string]interface{}{"gid": []string{goods}}) + return detail +} + +func GetKuaishouKey(eg *xorm.Engine, officialEg *xorm.Engine, dbName string) (map[string]string, map[string]string) { + kuaishouData := CommKuaishou(eg, officialEg, dbName) + param := map[string]string{ + "appkey": kuaishouData["appkey"], + "access_token": kuaishouData["token"], + } + + return param, kuaishouData +} +func KuaiShouDetail(eg *xorm.Engine, officialEg *xorm.Engine, dbName string, tikTokArgs map[string]interface{}) *zhimeng.TikTokDetailData { + arg := map[string]interface{}{ + "itemId": []interface{}{tikTokArgs["gid"]}, + } + param, kuaishouData := GetKuaishouKey(eg, officialEg, dbName) + if kuaishouData["authType"] != "2" { + goods, _ := zhimeng.KuaiShouDetail(tikTokArgs) + return goods + } + param["param"] = zhios_third_party_utils.SerializeStr(arg) + data, err := kuaishou.GetKuishouCpsGoodsDetail(kuaishouData["sign_secret"], param) + goods := gjson.Get(data, "data").String() + if goods == "" || err != nil { + return nil + } + var list = make([]md.KuaishouGoods, 0) + err = json.Unmarshal([]byte(goods), &list) + if err != nil { + return nil + } + var detail = zhimeng.TikTokDetailData{} + for _, v := range list { + if zhios_third_party_utils.IntToStr(v.GoodsId) == zhios_third_party_utils.AnyToString(tikTokArgs["gid"]) { + detail = CommGoodsDetail(v) + } + } + return &detail +} +func CommGoodsDetail(goods md.KuaishouGoods) zhimeng.TikTokDetailData { + var res = zhimeng.TikTokDetailData{ + Commission: zhios_third_party_utils.Float64ToStr(float64(goods.PromotionRate) / 10), + CostPrice: zhios_third_party_utils.Float64ToStr(float64(goods.GoodsPrice) / 100), + GoodsID: zhios_third_party_utils.IntToStr(goods.GoodsId), + GoodsImg: goods.GoodsImageUrl, + GoodsSales: zhios_third_party_utils.IntToStr(goods.SalesTip), + GoodsTitle: goods.GoodsTitle, + Price: zhios_third_party_utils.Float64ToStr(float64(goods.ZkGoodsPrice) / 100), + ShopID: zhios_third_party_utils.IntToStr(goods.MallId), + ShopName: goods.MallName, + } + img, ok := goods.GoodsGalleryUrls.([]interface{}) + res.Imgs = make([]string, 0) + if ok { + for _, v := range img { + res.Imgs = append(res.Imgs, zhios_third_party_utils.AnyToString(v)) + } + } + detailImg, ok := goods.ItemDescUrls.([]interface{}) + res.DetailImgs = make([]string, 0) + if ok { + for _, v := range detailImg { + res.DetailImgs = append(res.DetailImgs, zhios_third_party_utils.AnyToString(v)) + } + } + return res +} + +func CommKuaishou(eg *xorm.Engine, officialEg *xorm.Engine, dbName string) map[string]string { + kuaishouAppkey := offical.MasterListCfgGetOneData(officialEg, "0", "kuaishou_appkey") + kuaishouAppSecret := offical.MasterListCfgGetOneData(officialEg, "0", "kuaishou_app_secret") + kuaishouSignSecret := offical.MasterListCfgGetOneData(officialEg, "0", "kuaishou_sign_secret") + kuaishouToken := offical.MasterListCfgGetOneData(officialEg, "0", "kuaishou_token") + kuaishouPid := offical.MasterListCfgGetOneData(officialEg, "0", "kuaishou_pid") + puid := AppUserListPuidWithDb(officialEg, dbName) + puidKuaishouAppkey := offical.MasterListCfgGetOneData(officialEg, puid, "kuaishou_appkey") + if puidKuaishouAppkey != "" { + kuaishouAppkey = puidKuaishouAppkey + } + puidKuaishouSignSecret := offical.MasterListCfgGetOneData(officialEg, puid, "kuaishou_sign_secret") + if puidKuaishouSignSecret != "" { + kuaishouSignSecret = puidKuaishouSignSecret + } + puidKuaishouToken := offical.MasterListCfgGetOneData(officialEg, puid, "kuaishou_token") + if puidKuaishouToken != "" { + kuaishouToken = puidKuaishouToken + } + puidKuaishouPid := offical.MasterListCfgGetOneData(officialEg, puid, "kuaishou_pid") + if puidKuaishouPid != "" { + kuaishouPid = puidKuaishouPid + } + cfg, _ := db.SysUnionByKuaishouByUseByAuth(eg, dbName) + authType := "" + pid := kuaishouPid + if cfg != nil && cfg.AuthType == 2 { //自有 + authType = zhios_third_party_utils.IntToStr(cfg.AuthType) + kuaishouToken = gjson.Get(cfg.KeyData, "teamAccessToken").String() + pid = gjson.Get(cfg.KeyData, "pid").String() + } + res := map[string]string{ + "authType": authType, + "appkey": kuaishouAppkey, + "token": kuaishouToken, + "pid": pid, + "app_secret": kuaishouAppSecret, + "sign_secret": kuaishouSignSecret, + } + return res +} + +func AppUserListPuidWithDb(officialEg *xorm.Engine, dbName string) string { + appList := offical.GetUserAppList(officialEg, dbName) + uid := "0" + if appList != nil && appList.Puid > 0 { + uid = zhios_third_party_utils.IntToStr(appList.Puid) + } + return uid +} diff --git a/chain_transfer/svc/svc_turnchain.go b/chain_transfer/svc/svc_turnchain.go new file mode 100644 index 0000000..30cffda --- /dev/null +++ b/chain_transfer/svc/svc_turnchain.go @@ -0,0 +1,1292 @@ +package svc + +import ( + taoke "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/dataoke" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db/model" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db/offical" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/haodanku" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/jd" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/pdd" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/taobao" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tik_tok" + zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils/cache" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/zhimeng" + "encoding/json" + "errors" + "fmt" + "github.com/jinzhu/copier" + "github.com/tidwall/gjson" + "math/rand" + "regexp" + "strings" + "time" + "xorm.io/xorm" +) + +//转链主入口 +func TurnChainFeatures(eg *xorm.Engine, dbName string, tikTokBase map[string]string, user *model.User) (*md.ConvertedUrls, error) { + pvd := tikTokBase["pvd"] + goodsId := tikTokBase["goodsId"] + var ( + //cfg map[string]string + err error + urls *md.ConvertedUrls + ) + userProfile, _ := db.UserProfileFindByID(eg, user.Uid) + if userProfile != nil { + tikTokBase["acc_taobao_share_id"] = zhios_third_party_utils.Int64ToStr(userProfile.AccTaobaoShareId) + if userProfile.AccJdCloudId == "" { + userProfile.AccJdCloudId = userProfile.AccJdShareId + } + tikTokBase["acc_jd_share_id"] = userProfile.AccJdCloudId + tikTokBase["acc_pdd_self_id"] = userProfile.AccPddSelfId + } + tikTokBase["uid"] = zhios_third_party_utils.IntToStr(user.Uid) + tikTokBase["gid"] = goodsId + tikTokBase["master_id"] = dbName + tikTokBase["provider"] = pvd + switch pvd { + case md.PVD_TIKTOK: + if strings.Contains(goodsId, "cid") { + ex := strings.Split(goodsId, "cid") + goodsId = ex[0] + } + tikTokBase["gid"] = goodsId + urls, err = TikTokTurnChain(eg, dbName, tikTokBase) + case md.PVD_TB, md.PVD_TM: + urls, err = TBOrTmTurnChain(eg, dbName, tikTokBase) + case md.PVD_JD: + urls, err = JDTurnChain(eg, dbName, tikTokBase) + + case md.PVD_PDD: + urls, err = PDDTurnChain(eg, dbName, tikTokBase) + default: + return nil, errors.New("失败") + } + return urls, err +} +func TBOrTmTurnChain(eg *xorm.Engine, dbName string, args map[string]string) (*md.ConvertedUrls, error) { + urls, err := ConvertUrl(eg, args) + if err != nil { + return nil, err + } + + var couponUrl = "" + if urls != nil { + taobaoSdk, err := taobao.NewTaobaoSDK(eg, dbName, args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"])) + if err != nil { + fmt.Println("=======商品10", err) + + return nil, nil + } + bizSceneId := "2" + itemInfo, err := taobaoSdk.ItemDetailById(args["gid"], bizSceneId) + if err != nil { + return nil, nil + } + //调用好单库 + hdkItemInfo, err := haodanku.HaodankuDetail(args["gid"]) + if err != nil { + return nil, nil + } + if zhios_third_party_utils.StrToFloat64(itemInfo.CouponAmount) == 0 && zhios_third_party_utils.StrToFloat64(hdkItemInfo.CouponAmount) == 0 { + urls.ShortenURL = urls.ItemUrl + urls.URL = urls.ItemUrl + urls.NoOpenAppURL = urls.ItemUrl + } + couponUrl = urls.ShortenURL + //如果优惠券高 读取隐藏券 + if zhios_third_party_utils.StrToFloat64(hdkItemInfo.CouponAmount) > zhios_third_party_utils.StrToFloat64(itemInfo.CouponAmount) && zhios_third_party_utils.StrToFloat64(hdkItemInfo.CouponAmount) > 0 { + couponUrl += "&activityId=" + hdkItemInfo.ActivityId + } + //分享或纯渠道要拼上渠道id + if zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"]) > 0 && strings.Contains(couponUrl, "&relationId=") == false { + couponUrl = couponUrl + "&relationId=" + args["acc_taobao_share_id"] + } + if urls.NewPid != "" && strings.Contains(couponUrl, "&relationId=") == false { + if args["platform"] == md.PLATFORM_WX_APPLET && zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"]) == 0 { + couponUrl = couponUrl + "&relationId=" + zhios_third_party_utils.Int64ToStr(urls.TbShareId) + } + } + urls.ShortenURL = couponUrl + } + return urls, nil +} + +//京东转链 +func JDTurnChain(eg *xorm.Engine, dbName string, args map[string]string) (*md.ConvertedUrls, error) { + pid := args["acc_jd_share_id"] + urls, err := zhimeng.JDConvertUrl( + db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_AK), + db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_SK), + args["gid"], + pid, + "", + "", + "") + if err != nil { + return nil, err + } + return urls, nil +} + +//pdd转链 +func PDDTurnChain(eg *xorm.Engine, dbName string, args map[string]string) (*md.ConvertedUrls, error) { + pid := args["acc_pdd_self_id"] + var urls *md.ConvertedUrls + var err error + thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key") + if thirdZmAppKeyData == nil || err != nil { + return urls, err + } + thirdZmAppSecretData, err := db.SysCfgGetOne(eg, "third_zm_app_secret") + if thirdZmAppSecretData == nil || err != nil { + return urls, err + } + miniApp := "0" + isShares := "2" + urls, err = zhimeng.PDDConvertUrl( + thirdZmAppKeyData.Val, + thirdZmAppSecretData.Val, + args["gid"], + pid, + "", + miniApp, + "0", isShares) + if err != nil { + return nil, err + } + return urls, nil +} + +func TikTokTurnChain(eg *xorm.Engine, dbName string, args map[string]string) (*md.ConvertedUrls, error) { + couponShareURL := "" + itemUrl := args["itemUrl"] + if itemUrl != "" && (strings.Contains(itemUrl, "ins_activity_param=") || strings.Contains(itemUrl, "pick_source=")) || (zhios_third_party_utils.StrToInt(args["tik_activity_id"]) > 0) { + tikTokBase, _ := tik_tok.Base(eg, dbName, "") + if zhios_third_party_utils.StrToInt(args["tik_activity_id"]) > 0 { + url := TikTokUrl(eg, dbName, args["gid"], args["tik_activity_id"]) + if url != "" { + tikTokBase.TeamAccessToken = args["tik_team_token"] + itemUrl = url + } + } + postData := map[string]interface{}{ + "product_url": itemUrl, + "pick_extra": dbName + "_" + args["uid"], + } + fmt.Println(postData) + detailUrlData, err := tik_tok.OwnTeamUrl(tikTokBase, postData) + fmt.Println(detailUrlData) + if err == nil && detailUrlData["product_url"] != "" { + couponShareURL = detailUrlData["product_url"] + } + } + + if couponShareURL == "" { + couponShareURL = "https://haohuo.jinritemai.com/views/product/item2?id=" + args["gid"] + } + urls, err := ConvertUrl(eg, args) + if err != nil { + return nil, err + } + return urls, nil +} +func ConvertUrl(eg *xorm.Engine, args map[string]string) (*md.ConvertedUrls, error) { + var ( + err error + ) + var urls *md.ConvertedUrls + switch args["provider"] { + case md.PVD_TB, md.PVD_TM: + taobaoSdk, err := taobao.NewTaobaoSDK(eg, args["master_id"], args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"])) + if err != nil { + return nil, err + } + tb := taobaoSdk + var promoId = tb.CloudPromoIdWeb + if promoId == "" { + promoId = tb.SharePromoIdWeb + } + var promoId1 string + var taobaoShareId1 string + var IsWxTaobaoAuth bool + fmt.Println(IsWxTaobaoAuth) + if zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"]) == 0 { + if tb.AppletIsAuth == "1" { + IsWxTaobaoAuth, taobaoShareId1, promoId1 = taobao.TaobaoRelationPid(eg, args) + if IsWxTaobaoAuth == false { + return nil, err + } else { + promoId = promoId1 + } + } + } + thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key") + if thirdZmAppKeyData == nil || err != nil { + return urls, err + } + thirdZmAppSecretData, err := db.SysCfgGetOne(eg, "third_zm_app_secret") + if thirdZmAppSecretData == nil || err != nil { + return urls, err + } + urls, err = zhimeng.TaobaoConvertUrl(thirdZmAppKeyData.Val, + thirdZmAppSecretData.Val, args["gid"], promoId, tb.UserSID, "", tb.Svc_AK) + if urls != nil { + if taobaoShareId1 != "" { + urls.TbShareId = zhios_third_party_utils.StrToInt64(taobaoShareId1) + } + if promoId1 != "" { + urls.NewPid = promoId1 + } + } + case md.PVD_JDS: + thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key") + if thirdZmAppKeyData == nil || err != nil { + return urls, err + } + thirdZmAppSecretData, err := db.SysCfgGetOne(eg, "third_zm_app_secret") + if thirdZmAppSecretData == nil || err != nil { + return urls, err + } + // 初始化京东配置 + pid := args["acc_jd_share_id"] + postData := make(map[string]interface{}) + postData["gid"] = args["gid"] + postData["appkey"] = thirdZmAppKeyData.Val + postData["secret_key"] = thirdZmAppSecretData.Val + jdData, err := zhimeng.NewZhiMengJingDongSDK(). + SelectFunction("getgoodsinfo"). + WithArgs(postData). + Result() + mdData := &md.MoreDetailResponse{} + // to struct + couponUrl := "" + couponPrice := "" + err = jdData.ToStruct(mdData) + if err == nil && mdData != nil && mdData.CouponURL != "" { + couponUrl = mdData.CouponURL + couponPrice = mdData.CouponPrice + } + urls, err = zhimeng.JDConvertUrl( + thirdZmAppKeyData.Val, + thirdZmAppSecretData.Val, + args["gid"], + pid, + couponUrl, + couponPrice, + "") + case md.PVD_TIKTOK, md.PVD_KUAISHOU: + pid := "cloud_" + args["uid"] + thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key") + if thirdZmAppKeyData == nil || err != nil { + return urls, err + } + thirdZmAppSecretData, err := db.SysCfgGetOne(eg, "third_zm_app_secret") + if thirdZmAppSecretData == nil || err != nil { + return urls, err + } + tikTokArgs := map[string]interface{}{ + "appkey": thirdZmAppKeyData.Val, + "secret_key": thirdZmAppSecretData.Val, + "product_url": args["coupon_url"], + "external_info": pid, + } + + if args["provider"] == md.PVD_TIKTOK { + tikTokArgs["need_qr_code"] = "0" + + tikTokBase, _ := tik_tok.Base(eg, args["master_id"], "") + if zhios_third_party_utils.InArr(tikTokBase.AuthType, []string{"2", "3"}) { + if time.Now().Unix() > 1670055300 { + tikTokArgs["external_info"] = pid + "_" + args["master_id"] + } + urls, err = tik_tok.OwnTikTokUrl(tikTokBase, tikTokArgs) + } else { + tikTokArgs["external_info"] = pid + "_" + args["master_id"] + urls, err = zhimeng.TikTokUrl(tikTokArgs) + } + + } else if args["provider"] == md.PVD_KUAISHOU { + tikTokArgs["gid"] = args["gid"] + tikTokArgs["linkType"] = "101" + tikTokArgs["genPoster"] = "0" + tikTokArgs["external_info"] = pid + "_" + args["master_id"] + urls, err = zhimeng.KuaiShouUrl(tikTokArgs) + } + case md.PVD_VIP: + thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key") + if thirdZmAppKeyData == nil || err != nil { + return urls, err + } + thirdZmAppSecretData, err := db.SysCfgGetOne(eg, "third_zm_app_secret") + if thirdZmAppSecretData == nil || err != nil { + return urls, err + } + // 初始化vip配置 + pid := args["master_id"] + "_vip_cloud_" + args["uid"] + openId := args["master_id"] + "_vip_" + args["uid"] + urls, err = zhimeng.VipConvertUrl( + thirdZmAppKeyData.Val, + thirdZmAppSecretData.Val, + args["gid"], + pid, + "", "vendoapi", openId, "1") + case md.PVD_PDD: + pid := args["acc_pdd_self_id"] + thirdZmAppKeyData, err := db.SysCfgGetOne(eg, "third_zm_app_key") + if thirdZmAppKeyData == nil || err != nil { + return urls, err + } + thirdZmAppSecretData, err := db.SysCfgGetOne(eg, "third_zm_app_secret") + if thirdZmAppSecretData == nil || err != nil { + return urls, err + } + miniApp := "0" + isShares := "2" + urls, err = zhimeng.PDDConvertUrl( + thirdZmAppKeyData.Val, + thirdZmAppSecretData.Val, + args["gid"], + pid, + "", + miniApp, + "0", isShares) + } + return urls, err +} + +func TikTokUrl(eg *xorm.Engine, dbName string, gid, activityId string) string { + tikTokBase, _ := tik_tok.Base(eg, dbName, "") + postData := make(map[string]interface{}) + postData["gid"] = gid + postData["appkey"] = db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_AK) + postData["secret_key"] = db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_SK) + postData["category_id"] = activityId + postData["p"] = "1" + postData["size"] = "1" + tikTokBase.ExtendTeamTokenMap = GetTikTokTeamTokenEg(eg, dbName, "") + + list, _ := tik_tok.OwnTeamGoods(tikTokBase, postData) + fmt.Println(list) + url := "" + if list != nil { + for _, v := range *list { + if v.GoodsID == gid { + url = v.DetailURL + } + } + } + return url +} + +// 淘口令 +func CheckTaobaoWordGetId(eg *xorm.Engine, dbName string, s string, args map[string]string) string { + ak := db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_AK) + sk := db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_SK) + taobaoSdk, _ := taobao.NewTaobaoSDK(eg, dbName, args["platfrom"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"])) + if taobaoSdk == nil { + return "" + } + itemData := zhimeng.WordParse(ak, sk, taobaoSdk.SelfPromoIdWeb, s, taobaoSdk.UserSID, taobaoSdk.Svc_AK) + fmt.Println(itemData) + // 查无数据 + if itemData.Gid == "" { + return "" + } + + return itemData.Gid +} +func CommGetGoods(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]string, tcPrase md.TCPrase, isFirst int, reqCount, pvd, goodsId, countUrl, tklWord, isTkl string) (md.TCPrase, string) { + newPvd := pvd + now := time.Now() + fmt.Println("======================这里", time.Since(now)) + goods, pvd, _, _, _, _, _, mddata := ProcessTurnChainByGoodsId(eg, officialEg, tmp, goodsId, pvd, countUrl) + fmt.Println("======================这里1", time.Since(now)) + oldCountUrl := countUrl + var urls = &md.ConvertedUrls{} + var err error + if tklWord != "" && zhios_third_party_utils.InArr(pvd, []string{md.PVD_TIKTOKLIFE, md.PVD_TIKTOK, md.PVD_KUAISHOU}) { + urls.TaoBaoWord = tklWord + } else if tklWord != "" && zhios_third_party_utils.InArr(newPvd, []string{md.PVD_TIKTOKLIFE, md.PVD_TIKTOK}) { + urls.TaoBaoWord = tklWord + } else { + if goods != nil { + //通过商品id转链 + tikTokBase := make(map[string]string) + tikTokBase["gid"] = goodsId + tikTokBase["pvd"] = pvd + user, _ := db.UserFindByID(eg, tmp["uid"]) + urls, err = TurnChainFeatures(eg, tmp["master_id"], tikTokBase, user) + if err != nil || urls == nil { + return tcPrase, reqCount + } + if pvd == md.PVD_TIKTOK && urls.Content != "" { + urls.TaoBaoWord = urls.Content + tklWord = urls.Content + } + + } + //if countUrl != "" && isEnd == "" { + // curls, _ := svc.OfficialRecommendUrl(c, newPvd, 1, 0, 0, 0, "", "1", user, 0, countUrl) + // if curls == nil { + // return tcPrase, reqCount + // } + // urls.ShortenURL = curls.Url + //} + } + fmt.Println("======================这里2", time.Since(now)) + + if goods == nil { + goods = &md.ProductDetailResponse{} + } + if isFirst == 1 { + copier.Copy(&tcPrase, mddata) + tcPrase.ProductDetail = goods + tcPrase.Count = reqCount + tcPrase.Tkl = urls.TaoBaoWord + tcPrase.TurnChainLink = urls.ShortenURL + } + if pvd != md.PVD_TB && pvd != md.PVD_TM && countUrl != "" && tklWord == "" { + if urls.ShortenURL == "" { + tcPrase.Count = strings.ReplaceAll(reqCount, countUrl, "["+countUrl+"]") + tcPrase.Count = strings.ReplaceAll(tcPrase.Count, "[[", "[") + tcPrase.Count = strings.ReplaceAll(tcPrase.Count, "]]", "]") + } else { + tcPrase.Count = strings.ReplaceAll(reqCount, countUrl, urls.ShortenURL) + } + } + isNull := "" + if pvd != md.PVD_TB && pvd != md.PVD_TM && oldCountUrl != "" && countUrl == "" && tklWord == "" { + isNull = "1" + tcPrase.Count = strings.ReplaceAll(reqCount, oldCountUrl, "["+oldCountUrl+"]") + tcPrase.Count = strings.ReplaceAll(tcPrase.Count, "[[", "[") + tcPrase.Count = strings.ReplaceAll(tcPrase.Count, "]]", "]") + } + fmt.Println(isNull) + if (pvd == md.PVD_TIKTOKLIFE || pvd == md.PVD_TIKTOK || newPvd == md.PVD_TIKTOK) && tklWord != "" { + tcPrase.Count = strings.ReplaceAll(reqCount, countUrl, tklWord) + } + if pvd == md.PVD_KUAISHOU && tklWord != "" { + tcPrase.Count = strings.ReplaceAll(reqCount, countUrl, tklWord) + } + if pvd == md.PVD_TB || pvd == md.PVD_TM { + word, _ := ReplaceTbAll(eg, urls.ShortenURL, tmp) + tcPrase.Tkl = word + if countUrl != "" && strings.Contains(countUrl, "http") { + tcPrase.Count = strings.ReplaceAll(reqCount, countUrl, "") + } + if tklWord != "" && countUrl != "" { //获取到旧的淘口令 + tcPrase.Count = strings.ReplaceAll(tcPrase.Count, tklWord, word) + } else if tklWord != "" && countUrl == "" { //获取到旧的淘口令 + tcPrase.Count = strings.ReplaceAll(reqCount, tklWord, word) + } else { + split := strings.Split(tcPrase.Count, " ") + if split != nil && len(split) > 0 { + tcPrase.Count = strings.ReplaceAll(tcPrase.Count, split[0], word) + } + } + } + reqCount = tcPrase.Count + return tcPrase, reqCount +} +func ReplaceTbAll(eg *xorm.Engine, url string, args map[string]string) (taoBaoWord, shortURL string) { + taobaoSdk, err := taobao.NewTaobaoSDK(eg, args["master_id"], args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"])) + if err != nil { + return + } + // 生成淘口令 + taokou, err := taobaoSdk.WordCreate(url, "12345") + if err != nil { + taokou = new(md.TaobaoWord) + } + taoBaoWord = WordDeal(eg, args["master_id"], taokou) + //shortURL, _ = baidu.ShortenUrl(url) + return +} +func WordDeal(eg *xorm.Engine, dbName string, word *md.TaobaoWord) string { + tbTurnWordType := db.SysCfgGetWithDb(eg, dbName, "tb_share_word_type") + tbTurnWordFormat := db.SysCfgGetWithDb(eg, dbName, "tb_share_word_format") + tbTurnWordLeft := db.SysCfgGetWithDb(eg, dbName, "tb_share_word_left") + tbTurnWordRight := db.SysCfgGetWithDb(eg, dbName, "tb_share_word_right") + tbTurnWordType = db.SysCfgGetWithDb(eg, dbName, "tb_turn_word_type") + tbTurnWordFormat = db.SysCfgGetWithDb(eg, dbName, "tb_turn_word_format") + tbTurnWordLeft = db.SysCfgGetWithDb(eg, dbName, "tb_turn_word_left") + tbTurnWordRight = db.SysCfgGetWithDb(eg, dbName, "tb_turn_word_right") + taoBaoWord := zhios_third_party_utils.IntToStr(rand.Intn(9)) + " " + tbTurnWordLeft + word.Code + "/" + tbTurnWordRight + taoBaoWords := strings.Split(word.Text, "http") + if len(taoBaoWords) > 0 { + split := strings.Split(taoBaoWords[0], "¥") + wordStr := taoBaoWords[0] + if len(split) > 0 && tbTurnWordLeft != "" { + wordStr = strings.ReplaceAll(wordStr, split[0], "") + } + tbTurnWordRight = strings.ReplaceAll(tbTurnWordRight, "????", "🍑") + taoBaoWord = tbTurnWordLeft + wordStr + tbTurnWordRight + } + if tbTurnWordType != "1" { + taoBaoWord = word.Text + } + if tbTurnWordFormat != "" { + split := strings.Split(tbTurnWordFormat, "_") + tbsplit := strings.Split(taoBaoWord, "¥") + taoBaoWord = "" + for k, v := range tbsplit { + if k < 2 { + taoBaoWord += v + split[k] + } else { + taoBaoWord += v + } + } + } + return taoBaoWord +} + +//淘口令判断 +func FindTaobaoWord(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]string, reqCount string, user *model.User) (pvd, goodsId, tklWord, url string) { + dbName := tmp["master_id"] + if strings.Contains(reqCount, "haohuo.jinritemai.") { + //https://haohuo.jinritemai.com/ecommerce/trade/detail/index.html?id=3556342393857024570&ins_activity_param=yNAkhfs&origin_type=pc_buyin_group&pick_source=v.6nZos + tikTokBase := CommTik(eg, dbName, reqCount) + url := strings.ReplaceAll(reqCount, "?", "&") + "&" + split := strings.Split(url, "&id=") + if len(split) == 2 { + split1 := strings.Split(split[1], "&") + if len(split1) > 0 { + goodsId = split1[0] + tikTokBase["gid"] = goodsId + tikTokBase["pvd"] = pvd + urls, err := TurnChainFeatures(eg, dbName, tikTokBase, user) + if err != nil || urls == nil { + return "", "", "", "" + } + if zhios_third_party_utils.StrToInt(tikTokBase["tik_activity_id"]) > 0 && strings.Contains(goodsId, "cid") == false { + goodsId += "cid" + tikTokBase["tik_activity_id"] + } + return md.PVD_TIKTOK, goodsId, urls.Content, "" + } + } + } + if strings.Contains(reqCount, "【快手】") { + info, _ := CheckKuaishouWord(eg, officialEg, dbName, reqCount, user, 1) + if info != nil { + return md.PVD_KUAISHOU, info.ItemId, info.Word, "" + } + } + if strings.Contains(reqCount, "dou音") || strings.Contains(reqCount, "buydouke") || (strings.Contains(reqCount, "抖音") || strings.Contains(reqCount, "douyin")) && strings.Contains(reqCount, "【") { + info := CheckTikTokWord(eg, officialEg, dbName, reqCount, user, 0) + activityId := "" + if info != nil { + if info.Pvd == md.PVD_TIKTOKLIFE { + return md.PVD_TIKTOKLIFE, info.ItemId, info.Word, info.Url + } + goodsId = info.ItemId + activityId = info.ActivityId + } + var curls = new(md.ConvertedUrls) + var err error + if activityId != "" { + needQrCode := "0" + pid := "s_" + zhios_third_party_utils.IntToStr(user.Uid) + "_" + dbName + tikTokArgs := map[string]interface{}{ + "appkey": db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_AK), + "secret_key": db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_SK), + "need_qr_code": needQrCode, + "external_info": pid, + "material_id": "", + } + + tikTokBase, _ := tik_tok.Base(eg, dbName, "") + tikTokArgs["material_id"] = activityId + var actUrls *md.ConvertedUrls + if zhios_third_party_utils.InArr(tikTokBase.AuthType, []string{"2", "3"}) { + actUrls, err = tik_tok.OwnTikTokActUrl(tikTokBase, tikTokArgs) + } else { + tikTokArgs["material_id"] = activityId + actUrls, _ = zhimeng.TikTokActUrl(tikTokArgs) + } + if actUrls != nil { + curls.Content = actUrls.Content + } + } else { + args := make(map[string]string) + args["gid"] = "" + args["coupon_url"] = reqCount + args["master_id"] = dbName + args["provider"] = md.PVD_TIKTOK + args["uid"] = zhios_third_party_utils.IntToStr(user.Uid) + curls, err = ConvertUrl(eg, args) + } + if err != nil { + return "", "", "", "" + } + if curls == nil { + return "", "", "", "" + } + if curls.Content == "" { + return "", "", "", "" + } + return md.PVD_TIKTOK, goodsId, curls.Content, "" + } + goodsParam := make(map[string]string) + goodsParam["gid"] = "" + goodsParam["platform"] = tmp["platform"] + goodsParam["master_id"] = dbName + userProfile, _ := db.UserProfileFindByID(eg, user.Uid) + if userProfile != nil { + goodsParam["acc_taobao_share_id"] = zhios_third_party_utils.Int64ToStr(userProfile.AccTaobaoShareId) + if userProfile.AccJdCloudId == "" { + userProfile.AccJdCloudId = userProfile.AccJdShareId + } + goodsParam["acc_jd_share_id"] = userProfile.AccJdCloudId + goodsParam["acc_pdd_self_id"] = userProfile.AccPddSelfId + } + //判断是不是有淘宝链接 + if strings.Count(reqCount, "€") >= 1 || strings.Contains(reqCount, "tb.cn") { + + ItemId := CheckTaobaoWordGetId(eg, dbName, reqCount, goodsParam) + if ItemId != "" { + return md.PVD_TB, ItemId, "", "" + } + + } + //判断如果是有纯字母 字母+数字的内容 并且没有链接的 都调淘宝接口 + split := regexp.MustCompile("[a-zA-Z0-9]{9,14}").FindAllString(reqCount, -1) + //split_letter := regexp.MustCompile("[a-zA-Z]{8,15}").FindAllString(reqCount, -1) + if split != nil && ((zhios_third_party_utils.IsChineseChar(reqCount) && strings.Contains(reqCount, "http")) || strings.Contains(reqCount, "http") == false) { + var is_tkl = 0 + for k, v := range split { + if k == 0 { + is_tkl = 1 + tklWord = v + } + } + + if is_tkl == 1 { + taobaoWord := CheckTaobaoWordGetId(eg, dbName, reqCount, goodsParam) + if taobaoWord != "" { + return md.PVD_TB, taobaoWord, tklWord, "" + } + } + } + if strings.Contains(reqCount, "http") == false { + if tmp["platType"] != "taobao" { + info := CheckTikTokWord(eg, officialEg, dbName, reqCount, user, 1) + if info != nil { + + return md.PVD_TIKTOK, info.ItemId, info.Word, info.Url + } + info, _ = CheckKuaishouWord(eg, officialEg, dbName, reqCount, user, 1) + if info != nil { + return md.PVD_KUAISHOU, info.ItemId, info.Word, "" + } + } + if len(reqCount) > 16 { + taobaoWord := CheckTaobaoWordGetId(eg, dbName, reqCount, goodsParam) + if taobaoWord != "" { + return md.PVD_TB, taobaoWord, tklWord, "" + } + } + } + if strings.Contains(strings.ToLower(reqCount), "taobao.com") || strings.Contains(strings.ToLower(reqCount), "tmall.com") { + taobaoWord := CheckTaobao(eg, dbName, reqCount, goodsParam) + if taobaoWord != nil { + return md.PVD_TB, taobaoWord.ItemId, "", "" + } + } + if strings.Contains(reqCount, "s.click.Taobao") { + taobaoWord := CheckTaobao(eg, dbName, reqCount, goodsParam) + if taobaoWord != nil { + return md.PVD_TB, taobaoWord.ItemId, "", "" + } + } + return +} +func CheckTaobao(eg *xorm.Engine, dbName, s string, args map[string]string) *md.ItemParseInfo { + bizSceneId := "2" + if strings.Contains(s, "s.click.Taobao") { + parse, err := taoke.DaTaoKeContentParse(s) + if err != nil || parse.ItemId == "" { + return nil + } + s = "https://uland.taobao.com/item/edetail?id=" + parse.ItemId + bizSceneId = "" + + } + taobaoSdk, _ := taobao.NewTaobaoSDK(eg, args["master_id"], args["platform"], zhios_third_party_utils.StrToInt(args["acc_taobao_share_id"])) + itemInfo, err := taobaoSdk.ItemDetailByLink(s, bizSceneId) + if itemInfo == nil || err != nil { + return nil + } + // 用户登陆, 就要转链 + + couponUrl := itemInfo.URL + //调用好单库 + //hdkItemInfo, itemInfo, providers := GetHdkDtkGoods(c, itemInfo, md.PVD_DTK) + convertUrl, err := ConvertUrl(eg, args) + if err == nil && convertUrl != nil { + couponUrl = convertUrl.ShortenURL + ////如果优惠券高 + //if strings.Contains(couponUrl, "uland.") { + // if strings.Contains(couponUrl, "?") { + // couponUrl += "&activityId=" + itemInfo.ActivityId + // } else { + // couponUrl += "?activityId=" + itemInfo.ActivityId + // } + //} + couponUrl = couponUrl + "&relationId=" + args["acc_taobao_share_id"] + + } + provider := md.PVD_TB + if itemInfo.UserType == 1 { + provider = md.PVD_TM + } + return &md.ItemParseInfo{ + ItemId: zhios_third_party_utils.AnyToString(itemInfo.ItemID), + Provider: provider, + CouponUrl: couponUrl, + APPUrl: couponUrl, + ShopName: itemInfo.Nick, + } +} + +func CheckTikTokWord(eg *xorm.Engine, officialEg *xorm.Engine, dbName, s string, user *model.User, isChange int) *md.ItemParseInfo { + var postData = map[string]interface{}{} + postData["appkey"] = db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_AK) + postData["secret_key"] = db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_SK) + postData["content"] = s + now := time.Now() + tikTokBase, _ := tik_tok.Base(eg, dbName, "") + var itemData *zhimeng.TikTokDetailData + var err error + if zhios_third_party_utils.InArr(tikTokBase.AuthType, []string{"2", "3"}) { + itemData, err = tik_tok.OwnTikTokGoodsKlNew(tikTokBase, postData) + } else { + itemData, err = zhimeng.TikTokGoodsKlNew(postData) + } + fmt.Println("1", time.Since(now)) + provider := md.PVD_TIKTOK + word := s + url := "" + if err != nil || itemData == nil { + tikTokOpenUid := offical.MasterListCfgGetOneData(officialEg, "0", "tik_tok_open_uid") + tikTokOpenPid := offical.MasterListCfgGetOneData(officialEg, "0", "tik_tok_open_pid") + shareParams := map[string]interface{}{ + "pid": tikTokOpenPid, + "external_info": "s_" + zhios_third_party_utils.IntToStr(user.Uid) + "_" + dbName, //自定义字段,只允许数字、字母和_,限制⻓度为40 + "platform": "0", + "need_command": true, + "need_qr_code": true, + } + param := map[string]interface{}{ + "uid": tikTokOpenUid, + "command": s, //商品ID/商品URL/短链/口令 + "share_params": shareParams, //转链参数,无需转链不传 + } + api, _ := tik_tok.LocalApi("command_parse_and_share/", TikTokToken(officialEg), zhios_third_party_utils.SerializeStr(param)) + fmt.Println(api) + productId := gjson.Get(api, "data.product_info.product_id").Int() + if productId > 0 { + word = gjson.Get(api, "data.product_info.share_info.dy_password").String() + url = gjson.Get(api, "data.product_info.share_info.dy_deeplink").String() + return &md.ItemParseInfo{ + Url: url, + Pvd: md.PVD_TIKTOKLIFE, + Word: word, + ItemId: zhios_third_party_utils.Int64ToStr(productId), + } + } else { + return nil + } + } + if itemData.ActivityId != "" { + return &md.ItemParseInfo{ActivityId: itemData.ActivityId} + } + if itemData.GoodsID == "" { + return nil + } + couponUrl := "" + if user != nil { + if isChange == 1 { + args := make(map[string]string) + args["gid"] = itemData.GoodsID + args["master_id"] = dbName + args["provider"] = provider + args["uid"] = zhios_third_party_utils.IntToStr(user.Uid) + convertUrl, err := ConvertUrl(eg, args) + if err == nil && convertUrl != nil { + couponUrl = convertUrl.AppURL + word = convertUrl.Content + } + } + } + fmt.Println("2", time.Since(now)) + + return &md.ItemParseInfo{ + Url: url, + Pvd: provider, + Word: word, + ItemId: itemData.GoodsID, + Provider: provider, + CouponUrl: couponUrl, + APPUrl: couponUrl, + } + +} + +func TikTokToken(eg *xorm.Engine) string { + tikTokOpenAppkey := offical.MasterListCfgGetOneData(eg, "0", "tik_tok_open_appkey") + tikTokOpenAppSecret := offical.MasterListCfgGetOneData(eg, "0", "tik_tok_open_app_secret") + args := map[string]string{ + "appkey": tikTokOpenAppkey, + "appSecret": tikTokOpenAppSecret, + } + key := "tikTok_client_" + args["appkey"] + tokeStr, err := cache.GetString(key) + if tokeStr == "" || err != nil { + token := tik_tok.GetClientToken(args) + if token["tik_tok_acc_token"] != "" { + tokeStr = token["tik_tok_acc_token"] + cache.SetEx(key, token["tik_tok_acc_token"], zhios_third_party_utils.StrToInt(token["expires_in"])) + } + } + return tokeStr +} +func CheckKuaishouWord(eg *xorm.Engine, officialEg *xorm.Engine, dbName string, s string, user *model.User, isChange int) (*md.ItemParseInfo, bool) { + var postData = map[string]interface{}{} + postData["appkey"] = db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_AK) + postData["secret_key"] = db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_SK) + postData["content"] = s + itemData := KuaiShouKlGoods(eg, officialEg, dbName, postData) + + if itemData == nil || itemData.GoodsID == "" { + return nil, false + } + provider := md.PVD_KUAISHOU + couponUrl := "" + word := s + + if user != nil { + if isChange == 1 { + userProfile, _ := db.UserProfileFindByID(eg, user.Uid) + args := make(map[string]string) + if userProfile != nil { + args["acc_taobao_share_id"] = zhios_third_party_utils.Int64ToStr(userProfile.AccTaobaoShareId) + if userProfile.AccJdCloudId == "" { + userProfile.AccJdCloudId = userProfile.AccJdShareId + } + args["acc_jd_share_id"] = userProfile.AccJdCloudId + args["acc_pdd_self_id"] = userProfile.AccPddSelfId + } + args["gid"] = itemData.GoodsID + args["master_id"] = dbName + args["provider"] = provider + args["uid"] = zhios_third_party_utils.IntToStr(user.Uid) + convertUrl, err := ConvertUrl(eg, args) + if err == nil && convertUrl != nil { + couponUrl = convertUrl.AppURL + word = convertUrl.Content + } + } + } + + return &md.ItemParseInfo{ + Word: word, + ItemId: itemData.GoodsID, + Provider: provider, + CouponUrl: couponUrl, + APPUrl: couponUrl, + DetailUrl: itemData.DetailUrl, + }, false + +} + +//获取商品主入口 +func ProcessTurnChainByGoodsId(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]string, goodsId, pvd, url string) (productDetail *md.ProductDetailResponse, productPvd, itemUrl, couponShareURL, couponAmount, couponUrl, couponPrice string, resMd *md.MoreDetailResponse) { + mdData := &md.MoreDetailResponse{} + switch pvd { + + case md.PVD_KUAISHOU: + tikTokResponse, tikTokProvider := KuaishouByGoodsID(eg, officialEg, tmp, goodsId, url, mdData) + if tikTokResponse != nil && tikTokProvider != "" { + return tikTokResponse, tikTokProvider, "", "", "", "", "", mdData + } else { + return + } + case md.PVD_TIKTOK: + if goodsId == "" { + return + } + tikTokResponse, tikTokProvider := TikTokByGoodsID(eg, officialEg, tmp, goodsId, url, mdData) + if tikTokResponse != nil && tikTokProvider != "" { + return tikTokResponse, tikTokProvider, "", "", "", "", "", mdData + } else { + return + } + case md.PVD_TB, md.PVD_TM: + tbOrTmResponse, tbOrTmProvider, tbcouponShareURL, tbcouponAmount := TBByGoodsId(eg, officialEg, tmp, goodsId, url, mdData) + if tbOrTmResponse != nil && tbOrTmProvider != "" { //taobaoOrTm + return tbOrTmResponse, tbOrTmProvider, url, tbcouponShareURL, tbcouponAmount, "", "", mdData + } else { + return + } + case md.PVD_JD: + jdResponse, jdProvider, jdCouponUrl, jdCouponPrice := JDByGoodsId(eg, officialEg, tmp, goodsId, url, mdData) + if jdResponse != nil && jdProvider != "" { + return jdResponse, jdProvider, "", "", "", jdCouponUrl, jdCouponPrice, mdData + } else { + return + } + + case md.PVD_PDD: + pddResponse, pddProvider := PDDByGoodsId(eg, officialEg, tmp, goodsId, url, mdData) + if pddResponse != nil && pddProvider != "" { + return pddResponse, pddProvider, "", "", "", "", "", mdData + } else { + return nil, "", "", "", "", "", "", mdData + } + default: + return + } +} + +func KuaishouByGoodsID(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]string, goodsId, url string, mdData *md.MoreDetailResponse) (*md.ProductDetailResponse, string) { + + r := &md.ProductDetailResponse{GoodID: goodsId} + return r, md.PVD_KUAISHOU +} +func TikTokByGoodsID(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]string, goodsId, url string, mdData *md.MoreDetailResponse) (*md.ProductDetailResponse, string) { + + r := &md.ProductDetailResponse{GoodID: goodsId} + return r, md.PVD_TIKTOK +} +func TBByGoodsId(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]string, goodsId, url string, mdData *md.MoreDetailResponse) (productDetail *md.ProductDetailResponse, pvd, couponShareURL, couponAmount string) { + //获取到传进来的id先请求淘宝 + //根据prodId获取对应产品信息 + taobaoSdk, err := taobao.NewTaobaoSDK(eg, tmp["master_id"], tmp["platform"], zhios_third_party_utils.StrToInt(tmp["acc_taobao_share_id"])) + + if err != nil { + //e.OutErr(c, e.ERR_SYSUNION_CONFIG, err) + return + } + var itemInfo *taobao.Material + if goodsId != "" { + itemInfo, err = taobaoSdk.ItemDetailById(goodsId, "2") + } else { + itemInfo, err = taobaoSdk.ItemDetailByLink(url, "") + } + if err != nil { + return + } + if itemInfo != nil { + + r := &md.ProductDetailResponse{} + istaobaoURL := strings.Contains(itemInfo.ItemURL, "taobao.com") + provider := md.PVD_TB + if istaobaoURL { + provider = md.PVD_TB + } else { + istmallURL := strings.Contains(itemInfo.ItemURL, "tmall.com") + if istmallURL { + provider = md.PVD_TM + } + } + r.GoodID = zhios_third_party_utils.AnyToString(itemInfo.ItemID) + return r, provider, itemInfo.CouponShareURL, itemInfo.CouponAmount + } + return +} +func JDByGoodsId(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]string, goodsId, url string, mdData *md.MoreDetailResponse) (jdResponse *md.ProductDetailResponse, pvd, couponUrl, couponPrice string) { + now := time.Now() + fmt.Println("===zhe", time.Since(now)) + var jdData *zhimeng.SDK + postData := make(map[string]interface{}) + postData["appkey"] = db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_AK) + postData["secret_key"] = db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_SK) + //请求jd + var err error + ClickUrl := "" + isNull := "" + if zhios_third_party_utils.StrToInt(goodsId) > 0 { + postData["gid"] = goodsId + jdData, err = jd.NewZhiMengJingDongSDK(). + SelectFunction("getgoodsinfo"). + WithArgs(postData). + Result() + } else { + curls, _ := OfficialRecommendUrl(eg, tmp, "jd", 1, 0, 0, 0, "", "1", 0, url) + if curls != nil && curls.Url != "" { + fmt.Println("===zhe1", time.Since(now)) + + ClickUrl = curls.Url + //parse, _ = taoke.DaTaoKeContentParse(curls.Url) + postData["keyword"] = url + postData["size"] = "2" + postData["p"] = "1" + postData["is_url"] = "1" + jdData, err = jd.NewZhiMengJingDongSDK(). + SelectFunction("new_getgoods"). + WithArgs(postData). + Result() + fmt.Println("===zhe2", time.Since(now)) + + } else { + isNull = "1" + } + } + if jdData == nil { + if ClickUrl != "" { + return &md.ProductDetailResponse{ClickUrl: ClickUrl}, md.PVD_JD, "", "" + } + return &md.ProductDetailResponse{IsNull: isNull}, md.PVD_JD, "", "" + } + // scrap detail image + if zhios_third_party_utils.StrToInt(goodsId) > 0 { + jdData.WithJDDetailImageList(goodsId) + } + if err != nil { + //e.OutErr(c, e.ERR_API_RESPONSE, e.NewErr(400, "商品已下架")) + return nil, "", "", "" + } + // to struct + err = jdData.ToStruct(mdData) + if err != nil { + //e.OutErr(c, e.ERR_INVALID_ARGS, err) + return nil, "", "", "" + } + + if mdData != nil { + if mdData.GID == "100038437991" || strings.Contains(mdData.GoodsTitle, "Apple iPhone") { + return nil, "", "", "" + } + // to response + r := &md.ProductDetailResponse{} + r.ClickUrl = ClickUrl + r.GoodID = mdData.GID + return r, md.PVD_JD, mdData.CouponURL, mdData.CouponPrice + } + return nil, "", "", "" +} +func PDDByGoodsId(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]string, goodsId, url string, mdData *md.MoreDetailResponse) (*md.ProductDetailResponse, string) { + postData := make(map[string]interface{}) + isList := false + if zhios_third_party_utils.StrToInt(goodsId) > 0 { + postData["gid"] = goodsId + } else { + postData["keyword"] = url + isList = true + } + postData["appkey"] = db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_AK) + postData["secret_key"] = db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_SK) + //换为用搜索接口查商品 + var pddPid string + var coustom string + master, err := db.UserProfileFindByID(eg, 1) + if err != nil { + return nil, "" + } + if master == nil || master.AccPddBind != 1 { + one_user, _ := db.UserProfileFindByID(eg, 0) + pddPid = one_user.AccPddSelfId + coustom = one_user.AccPddSelfId + } else { + pddPid = master.AccPddSelfId + coustom = zhios_third_party_utils.IntToStr(master.Uid) + } + postData["pid"] = pddPid + postData["custom_parameters"] = coustom + pddData, err := pdd.NewZhiMengPDDSDK(). + SelectFunction("getgoods"). + WithArgs(postData). + Result() + if err != nil || pddData == nil { + return nil, "" + } + if isList { + err = pddData.PddToStruct(mdData) + } else { + err = pddData.ToStruct(mdData) + } + if err != nil { + //e.OutErr(c, e.ERR_INVALID_ARGS, err) + return nil, "" + } + if mdData != nil && (mdData.GID == goodsId || goodsId == "") { + r := &md.ProductDetailResponse{} + r.GoodID = mdData.GoodsSign + return r, md.PVD_PDD + } + return nil, "" +} + +func OfficialRecommendUrl(eg *xorm.Engine, tmp map[string]string, sourceType string, isShare int, isWxMini int, lat float64, lng float64, ActivityId, linkType string, isShowMiniUrl int, activityPlatformUrl string) (*md.OfficialRecommendUrl, error) { + var ( + err error + urls *md.OfficialRecommendUrl + activityPlatformId string + MaterialId string + ) + urls = new(md.OfficialRecommendUrl) + if strings.Contains(sourceType, "_new") { + sourceType = strings.Replace(sourceType, "_new", "", -1) + } + + switch sourceType { + + case "tik_tok": + needQrCode := "0" + pid := "cloud_" + tmp["uid"] + "_" + tmp["master_id"] + activityId := "3" + if activityPlatformId == "1" { + activityId = "1" + activityPlatformId = "" + } + if activityPlatformId == "2" { + activityId = "2" + activityPlatformId = "" + } + if isWxMini == 2 { + needQrCode = "1" + } + tikTokArgs := map[string]interface{}{ + "appkey": db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_AK), + "secret_key": db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_SK), + "activity_id": activityId, + "mix_activity_id": activityPlatformId, + "need_qr_code": needQrCode, + "external_info": pid, + "material_id": "", + } + + tikTokBase, _ := tik_tok.Base(eg, tmp["master_id"], "") + if tikTokBase.AuthSubjectType == "DouKe" { + tikTokArgs["material_id"] = MaterialId + } + key := fmt.Sprintf("%s_tikTokNew_%s_%d_%s_%d_%s_%s_%s_%s_%s", tmp["master_id"], sourceType, isWxMini, needQrCode, isShare, ActivityId, pid, activityPlatformId, tikTokBase.AuthType, MaterialId) + err1 := cache.GetJson(key, urls) + var actUrls *md.ConvertedUrls + if err1 != nil || urls == nil { + if zhios_third_party_utils.InArr(tikTokBase.AuthType, []string{"2", "3"}) { + actUrls, err = tik_tok.OwnTikTokActUrl(tikTokBase, tikTokArgs) + if actUrls != nil { + urls = &md.OfficialRecommendUrl{ + Url: actUrls.AppURL, + WxQrcodeUrl: actUrls.QrcodeUrl, + TaobaoWord: actUrls.Content, + } + } + } else { + tikTokArgs["material_id"] = MaterialId + actUrls, _ = zhimeng.TikTokActUrl(tikTokArgs) + if actUrls != nil { + urls = &md.OfficialRecommendUrl{ + Url: actUrls.AppURL, + WxQrcodeUrl: actUrls.QrcodeUrl, + TaobaoWord: actUrls.Content, + } + } + } + if urls != nil && urls.Url != "" { + cache.SetJson(key, urls, 300) + } + } + case "jd": + + pid := tmp["acc_jd_share_id"] + + var jdUrl *md.ConvertedUrls + jdUrl, _ = zhimeng.JDConvertUrl( + db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_AK), + db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_SK), + "", + pid, + "", + "", + activityPlatformUrl) + if jdUrl != nil { + urls.Url = jdUrl.URL + urls.ClickUrl = jdUrl.ClickUrl + urls.WxMiniprogramPath = jdUrl.WeChatMiniURL + urls.Appid = jdUrl.WeChatMiniAPPID + } + + case "pdd": + pid := tmp["acc_pdd_self_id"] + + masterPid := pid + pddPidData, _ := pdd.NewZhiMengPDDSDK(). + SelectFunction("get_pid_list"). + WithArgs(map[string]interface{}{ + "appkey": db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_AK), + "secret_key": db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_SK), + "pid": masterPid}, + ).Result() + if pddPidData != nil { + b, _ := json.Marshal(pddPidData.ToInterface()) + pddPid := gjson.GetBytes(b, "pdd_pid").String() + if pddPid == "" { + profile, _ := db.UserProfileFindByID(eg, 0) + if profile != nil { + masterPid = profile.AccPddSelfId + } + } + } else { + profile, _ := db.UserProfileFindByID(eg, 0) + if profile != nil { + masterPid = profile.AccPddSelfId + } + } + var pddUrl *md.ConvertedUrls + var resourceType = "39998" + if activityPlatformId != "" { + ActivityId = activityPlatformId + } + //如果是act_ 就是其他活动 + if strings.Contains(ActivityId, "act_") { + resourceType = strings.ReplaceAll(ActivityId, "act_", "") + activityPlatformUrl = "" + } + if strings.Contains(ActivityId, "store_") { //商城的 + resourceType = strings.ReplaceAll(ActivityId, "store_", "") + activityPlatformUrl = "" + pddUrl, _ = zhimeng.PDDActivityStoreConvertUrl( + db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_AK), + db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_SK), + resourceType, + masterPid, + pid, + activityPlatformUrl, isShare) + } else if strings.Contains(ActivityId, "sale_") { //营销 + resourceType = strings.ReplaceAll(ActivityId, "sale_", "") + activityPlatformUrl = "" + pddUrl, _ = zhimeng.PDDActivitySaleConvertUrl( + db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_AK), + db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_SK), + resourceType, + masterPid, + pid, + activityPlatformUrl, isShare) + } else { + pddUrl, _ = zhimeng.PDDActivityConvertUrl( + db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_AK), + db.SysCfgGetWithDb(eg, tmp["master_id"], md.KEY_CFG_ZM_SK), + resourceType, + masterPid, + pid, + activityPlatformUrl, isShare) + } + + if pddUrl != nil { + urls.Url = pddUrl.URL + urls.WxMiniprogramPath = pddUrl.WeChatMiniURL + urls.Appid = pddUrl.WeChatMiniAPPID + } + + default: + return urls, errors.New("失败") + } + return urls, err +} diff --git a/chain_transfer/svc/turn_chain.go b/chain_transfer/svc/turn_chain.go new file mode 100644 index 0000000..f02475a --- /dev/null +++ b/chain_transfer/svc/turn_chain.go @@ -0,0 +1,101 @@ +package svc + +import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tik_tok" + zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" + + "fmt" + "strings" + "xorm.io/xorm" +) + +func CommTik(eg *xorm.Engine, dbName, url string) map[string]string { + activityId := 0 + teamToken := "" + commission := "" + if strings.Contains(url, "ecommerce") { + tikTokBase, _ := tik_tok.Base(eg, dbName, "") + tikTokBase.ExtendTeamTokenMap = GetTikTokTeamTokenEg(eg, dbName, url) + isSet := 0 + for _, v1 := range tikTokBase.ExtendTeamTokenMap { + if isSet == 1 { + continue + } + if v1 != "" { + rgs := map[string]string{ + "appkey": tikTokBase.ApiTeamAppKey, + "appSecret": tikTokBase.ApiTeamAppSecret, + "acctoken": zhios_third_party_utils.AnyToString(v1), + "activity_url": url, + } + urlMap := tik_tok.ColonelMultiParseActivityUrl(rgs) + if urlMap[url].ActivityId != 0 { + isSet = 1 + activityId = urlMap[url].ActivityId + teamToken = zhios_third_party_utils.AnyToString(v1) + commission = zhios_third_party_utils.Float64ToStr(float64(urlMap[url].CommissionRate) / 100) + } + } + } + } + res := map[string]string{ + "tik_activity_id": zhios_third_party_utils.IntToStr(activityId), + "tik_team_token": teamToken, + "tik_team_commission": commission, + } + return res +} + +func GetTikTokTeamTokenEg(eg *xorm.Engine, dbName, url string) map[string]interface{} { + tmp := map[string]interface{}{} + zhiosOpenSelectionLibraryMasterId := db.SysCfgGetWithDb(eg, dbName, "zhios_open_selection_library_master_id") + if zhiosOpenSelectionLibraryMasterId == "" { + return tmp + } + bizData := map[string]interface{}{ + "mid": zhiosOpenSelectionLibraryMasterId, + } + returnData, err := OauthApiReqEg(eg, dbName, url, bizData, "inapi.selection_library.team_info_more", "1.0") + if returnData == nil || err != nil { + return tmp + } + data := returnData.Data.(map[string]interface{}) + return data + +} +func GetKuaishouTeamTokenEg(eg *xorm.Engine, dbName, url string) map[string]interface{} { + tmp := map[string]interface{}{} + zhiosOpenSelectionLibraryMasterId := db.SysCfgGetWithDb(eg, dbName, "zhios_open_kuaishou_selection_library_master_id") + if zhiosOpenSelectionLibraryMasterId == "" { + return tmp + } + bizData := map[string]interface{}{ + "mid": zhiosOpenSelectionLibraryMasterId, + } + returnData, err := OauthApiReqEg(eg, dbName, url, bizData, "inapi.selection_library.kuaishou_team_info_more", "1.0") + if returnData == nil || err != nil { + return tmp + } + data := returnData.Data.(map[string]interface{}) + return data + +} + +func OauthApiReqEg(eg *xorm.Engine, dbName, url string, bizData map[string]interface{}, method, version string) (*zhios_third_party_utils.ReturnDataResp, error) { + openAppKey := db.SysCfgGetWithDb(eg, dbName, "zhios_open_app_key") + openAppSecret := db.SysCfgGetWithDb(eg, dbName, "zhios_open_app_secret") + // 创建请求 + openClient, err := zhios_third_party_utils.NewOpenPlatformReqClient(openAppKey, method, version, openAppSecret, bizData) + if err != nil { + return nil, err + } + openClient.Url = url + fmt.Println("return :", openClient.ReturnData) + // 发送请求 + err = openClient.SetBizDataToParams().CreateSign().CurlOpen() + if err != nil { + return nil, err + } + return &openClient.ReturnData, nil +} diff --git a/chain_transfer/turn_chain.go b/chain_transfer/turn_chain.go new file mode 100644 index 0000000..d22a05c --- /dev/null +++ b/chain_transfer/turn_chain.go @@ -0,0 +1,419 @@ +package chain_transfer + +import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/chain_transfer/svc" + taoke "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/dataoke" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md" + zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" + "fmt" + "github.com/mvdan/xurls" + "regexp" + "strings" + "time" + "xorm.io/xorm" +) + +func TurnChain(eg *xorm.Engine, officialEg *xorm.Engine, args map[string]string) md.TCPrase { + dbName := args["master_id"] + var tcPrase md.TCPrase + tcPrase.TurnGoods = make([]md.TurnGoods, 0) + db.UserFindByID(eg, args["uid"]) + now := time.Now() + PlatType := "" + args["platType"] = PlatType + user, _ := db.UserFindByID(eg, args["uid"]) + userProfile, _ := db.UserProfileFindByID(eg, user.Uid) + if userProfile != nil { + args["acc_taobao_share_id"] = zhios_third_party_utils.Int64ToStr(userProfile.AccTaobaoShareId) + if userProfile.AccJdCloudId == "" { + userProfile.AccJdCloudId = userProfile.AccJdShareId + } + args["acc_jd_share_id"] = userProfile.AccJdCloudId + args["acc_pdd_self_id"] = userProfile.AccPddSelfId + } + //1、识别出对应平台的口令或链接 + reqCount := args["content"] + if reqCount == "" { + return tcPrase + } + reqCount = strings.ReplaceAll(reqCount, "\n¥", "¥") + reqCount = strings.ReplaceAll(reqCount, "http", "\nhttp") + reqCounts := reqCount + if strings.Contains(reqCount, "¥") { + reqCounts = "" + splits := strings.Split(reqCount, "¥") + for k, v := range splits { + if k == 0 { + reqCounts += v + "\n¥" + } else if k+1 == len(splits) { + reqCounts += v + } else { + reqCounts += v + "¥" + } + } + } + reqCount = reqCounts + findAllUrl := xurls.Strict.FindAllString(reqCount, -1) + var pvd, goodsId, tklWord string + reg1 := regexp.MustCompile(`¥.*?¥`) + matched := reg1.FindAllStringSubmatch(reqCount, -1) + isTikTok := "0" + if strings.Contains(reqCount, "dou音") || strings.Contains(reqCount, "buydouke") || (strings.Contains(reqCount, "抖音") || strings.Contains(reqCount, "douyin")) && strings.Contains(reqCount, "【") { + isTikTok = "1" + } + split := strings.Split(reqCount, "\n") + reqCount = strings.ReplaceAll(reqCount, "\nhttp", "http") + if isTikTok == "1" { + pvd, goodsId, tklWord, _ := svc.FindTaobaoWord(eg, officialEg, args, reqCount, user) + if goodsId != "" || tklWord != "" { + tcPrase, _ = svc.CommGetGoods(eg, officialEg, args, tcPrase, 1, reqCount, pvd, goodsId, reqCount, tklWord, "0") + } + } else if len(split) > 0 { + for _, v := range split { + if strings.Contains(v, "m.tb") || strings.Contains(reqCount, "taobao.com") || strings.Contains(reqCount, "tmall.com") { + PlatType = "has" + } + if strings.Contains(v, "haohuo.jinritemai.") { + PlatType = "has" + + } + if strings.Contains(v, "jd.") { + PlatType = "has" + + } + if strings.Contains(v, "pinduoduo.com") || strings.Contains(v, "yangkeduo.com") { + PlatType = "has" + + } + if strings.Contains(v, "kaola.com") { + PlatType = "has" + + } + if strings.Contains(v, "suning.") { + PlatType = "has" + + } + if strings.Contains(v, "vip.") { + PlatType = "has" + + } + } + if PlatType == "" { + parse, _ := taoke.DaTaoKeContentParse(args["content"]) + //fmt.Println("============1", time.Since(now)) + args["platType"] = parse.PlatType + if parse.DataType == "activity" { + + } + } + for k, v := range split { + if v == "" { + continue + } + isFirst := 1 + if k > 0 && tcPrase.GID != "" { + isFirst = 0 + } + if strings.Contains(v, "m.tb") || strings.Contains(reqCount, "taobao.com") || strings.Contains(reqCount, "tmall.com") { + // 淘口令 + //fmt.Println(s) + pvd, goodsId, tklWord, _ = svc.FindTaobaoWord(eg, officialEg, args, v, user) + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, pvd, goodsId, v, tklWord, "0") + } + if strings.Contains(v, "haohuo.jinritemai.") { + //https://haohuo.jinritemai.com/ecommerce/trade/detail/index.html?id=3556342393857024570&ins_activity_param=yNAkhfs&origin_type=pc_buyin_group&pick_source=v.6nZos + tikTokBase := svc.CommTik(eg, dbName, v) + url := strings.ReplaceAll(v, "?", "&") + "&" + split := strings.Split(url, "&id=") + if len(split) == 2 { + split1 := strings.Split(split[1], "&") + if len(split1) > 0 { + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_TIKTOK, split1[0], v, tklWord, "0") + if zhios_third_party_utils.StrToInt(tikTokBase["tik_activity_id"]) > 0 && strings.Contains(tcPrase.GID, "cid") == false { + tcPrase.GID += "cid" + tikTokBase["tik_activity_id"] + } + } + } + } + if strings.Contains(v, "jd.") { + //只有链接带有.html才会剥离出商品id + if strings.Contains(v, ".html") { + var index int + s1 := v + split := strings.Split(s1, "/") + for i, s := range split { + if strings.Contains(s, ".html") { + index = i + } + } + goodsidStrs := strings.Split(split[index], ".html") + if len(goodsidStrs) > 0 { + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_JD, goodsidStrs[0], v, tklWord, "0") + } + } else { + findAllUrl1 := xurls.Strict.FindAllString(v, -1) + for _, v1 := range findAllUrl1 { + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_JD, "", v1, tklWord, "0") + } + } + } + if strings.Contains(v, "pinduoduo.com") || strings.Contains(v, "yangkeduo.com") { + split := strings.Split(v, "?") + if len(split) > 1 { + sUrl := strings.Split(split[1], "&") + if len(sUrl) > 0 { + for _, v2 := range sUrl { + if strings.Contains(v2, "goods_id=") { + goods := strings.Split(v2, "=") + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_PDD, goods[1], v, tklWord, "0") + } + } + + } + } else { + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_PDD, "", v, tklWord, "0") + } + } + if strings.Contains(v, "kaola.com") { + var index int + s1 := v + split := strings.Split(s1, "/") + for i, s := range split { + if strings.Contains(s, ".html") { + index = i + } + } + goodsidStrs := strings.Split(split[index], ".html") + if len(goodsidStrs) > 0 { + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_KL, goodsidStrs[0], v, tklWord, "0") + } + return tcPrase + } + if strings.Contains(v, "suning.") { + r, _ := regexp.Compile(`/(\d+)/(\d+).html`) + reg := r.FindStringSubmatch(v) + if len(reg) < 3 { + return tcPrase + } + bytes := []byte(reg[2]) + var index int + for i, b := range bytes { + if b != byte(48) { + index = i + break + } + } + i := bytes[index:len(bytes)] + fmt.Println(string(i)) + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_SN, string(i), v, tklWord, "0") + } + if strings.Contains(v, "vip.") { + gid := "" + if strings.Contains(v, "goodsId=") { + split := strings.Split(v+"&", "&") + for _, v := range split { + if strings.Contains(v, "goodsId=") { + gid = strings.ReplaceAll(v, "goodsId=", "") + } + } + } else { + var index int + s1 := v + split := strings.Split(s1, "/") + for i, s := range split { + if strings.Contains(s, ".html") { + index = i + } + } + goodsidStrs := strings.Split(split[index], ".html") + if len(goodsidStrs) > 0 { + product := strings.Split(goodsidStrs[0], "-") + gid = product[len(product)-1] + } + } + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_VIP, gid, v, tklWord, "0") + } + newV := strings.ToLower(v) + for i := 0; i < 10; i++ { + newV = strings.ReplaceAll(newV, zhios_third_party_utils.IntToStr(i), "") + } + if strings.Contains(v, "¥") == false && strings.Contains(v, "http") == false { + var numArr = []string{"、", "-", "~", ".", "。", "!", "/", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} + for _, v1 := range numArr { + newV = strings.ReplaceAll(newV, v1, "") + } + } + if goodsId == "" && zhios_third_party_utils.IsAllChinese(newV) == false && (PlatType == "taobao" || PlatType == "") { + + pvd, goodsId, word, _ := svc.FindTaobaoWord(eg, officialEg, args, v, user) + if goodsId == "" && pvd == "" { + continue + } + url := "" + if zhios_third_party_utils.InArr(pvd, []string{md.PVD_TB, md.PVD_TM}) { + url = v + v = "" + } + if pvd == md.PVD_KUAISHOU { + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, pvd, goodsId, v, word, "1") + } else { + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, pvd, goodsId, v, url, "0") + } + } + fmt.Println("============"+zhios_third_party_utils.IntToStr(k+3), time.Since(now)) + + } + fmt.Println("============30", time.Since(now)) + + } else if matched != nil && len(matched) > 0 { + + for k, v := range matched { + isFirst := 1 + if k > 0 && tcPrase.GID != "" { + isFirst = 0 + } + for _, v1 := range v { + pvd, goodsId, _, _ := svc.FindTaobaoWord(eg, officialEg, args, v1, user) + url := "" + if len(findAllUrl) > 0 { + url = findAllUrl[k] + } + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, pvd, goodsId, url, v1, "1") + } + } + } else if len(findAllUrl) > 0 && isTikTok == "0" { + for k, v := range findAllUrl { + isFirst := 1 + if k > 0 && tcPrase.GID != "" { + isFirst = 0 + } + if strings.Contains(v, "m.tb") || + strings.Contains(reqCount, "taobao.com") || strings.Contains(reqCount, "tmall.com") { + // 淘口令 + //fmt.Println(s) + pvd, goodsId, tklWord, _ = svc.FindTaobaoWord(eg, officialEg, args, v, user) + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, pvd, goodsId, v, tklWord, "0") + } + if strings.Contains(v, "haohuo.jinritemai.") { + tikTokBase := svc.CommTik(eg, args["master_id"], v) + url := strings.ReplaceAll(v, "?", "&") + "&" + split := strings.Split(url, "&id=") + if len(split) == 2 { + split1 := strings.Split(split[1], "&") + if len(split1) > 0 { + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_TIKTOK, split1[0], v, tklWord, "0") + if zhios_third_party_utils.StrToInt(tikTokBase["tik_activity_id"]) > 0 && strings.Contains(tcPrase.GID, "cid") == false { + tcPrase.GID += "cid" + tikTokBase["tik_activity_id"] + } + } + } + } + if strings.Contains(v, "jd.") { + //只有链接带有.html才会剥离出商品id + if strings.Contains(v, ".html") { + var index int + s1 := v + split := strings.Split(s1, "/") + for i, s := range split { + if strings.Contains(s, ".html") { + index = i + } + } + goodsidStrs := strings.Split(split[index], ".html") + if len(goodsidStrs) > 0 { + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_JD, goodsidStrs[0], v, tklWord, "0") + } + } else { + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_JD, "", v, tklWord, "0") + } + } + if strings.Contains(v, "pinduoduo.com") || strings.Contains(v, "yangkeduo.com") { + split := strings.Split(v, "?") + if len(split) > 1 { + sUrl := strings.Split(split[1], "&") + if len(sUrl) > 0 { + for _, v2 := range sUrl { + if strings.Contains(v2, "goods_id=") { + goods := strings.Split(v2, "=") + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_PDD, goods[1], v, tklWord, "0") + } + } + + } + } else { + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_PDD, "", v, tklWord, "0") + } + } + if strings.Contains(v, "kaola.com") { + var index int + s1 := v + split := strings.Split(s1, "/") + for i, s := range split { + if strings.Contains(s, ".html") { + index = i + } + } + goodsidStrs := strings.Split(split[index], ".html") + if len(goodsidStrs) > 0 { + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_KL, goodsidStrs[0], v, tklWord, "0") + } + return tcPrase + } + if strings.Contains(v, "suning.") { + r, _ := regexp.Compile(`/(\d+)/(\d+).html`) + reg := r.FindStringSubmatch(v) + if len(reg) < 3 { + return tcPrase + } + bytes := []byte(reg[2]) + var index int + for i, b := range bytes { + if b != byte(48) { + index = i + break + } + } + i := bytes[index:len(bytes)] + fmt.Println(string(i)) + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_SN, string(i), v, tklWord, "0") + } + if strings.Contains(v, "vip.") { + + gid := "" + if strings.Contains(v, "goodsId=") { + split := strings.Split(v+"&", "&") + for _, v := range split { + if strings.Contains(v, "goodsId=") { + gid = strings.ReplaceAll(v, "goodsId=", "") + } + } + } else { + var index int + s1 := v + split := strings.Split(s1, "/") + for i, s := range split { + if strings.Contains(s, ".html") { + index = i + } + } + goodsidStrs := strings.Split(split[index], ".html") + if len(goodsidStrs) > 0 { + product := strings.Split(goodsidStrs[0], "-") + gid = product[len(product)-1] + } + } + + tcPrase, reqCount = svc.CommGetGoods(eg, officialEg, args, tcPrase, isFirst, reqCount, md.PVD_VIP, gid, v, tklWord, "0") + } + } + + } else { + pvd, goodsId, tklWord, _ := svc.FindTaobaoWord(eg, officialEg, args, reqCount, user) + if goodsId != "" { + tcPrase, _ = svc.CommGetGoods(eg, officialEg, args, tcPrase, 1, reqCount, pvd, goodsId, "", tklWord, "0") + + } + } + return tcPrase +} diff --git a/dataoke/dels_content_parse.go b/dataoke/dels_content_parse.go new file mode 100644 index 0000000..79b3622 --- /dev/null +++ b/dataoke/dels_content_parse.go @@ -0,0 +1,55 @@ +package dataoke + +import ( + zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils/cache" + "encoding/json" + "errors" + "fmt" + "github.com/tidwall/gjson" +) + +type ContentParse struct { + ItemId string `json:"itemId"` + ItemLink string `json:"itemLink"` + ItemName string `json:"itemName"` + DataType string `json:"dataType"` + PlatType string `json:"platType"` + MainPic string `json:"mainPic"` + MonthSales interface{} `json:"monthSales"` + OriginalPrice interface{} `json:"originalPrice"` + ActualPrice interface{} `json:"actualPrice"` + CommissionRate interface{} `json:"commissionRate"` + CouponPrice interface{} `json:"coupon_price"` + Url string `json:"url"` +} + +func DaTaoKeContentParse(content string) (data ContentParse, err error) { + key := "new_" + content + get, err := cache.GetString(key) + if get == "" || err != nil { + params := map[string]string{ + "version": "v1.0.0", + "content": key, + } + resp, err := SendReq("https://openapi.dataoke.com/api/dels/kit/contentParse", params) + if err != nil { + return data, err + } + list := gjson.Get(string(resp), "data").String() + err = json.Unmarshal([]byte(list), &data) + if err != nil { + return data, err + } + if data.DataType != "goods" { + return data, errors.New("不是商品") + } + if data.ItemId != "" { + _, err := cache.SetEx(content, zhios_third_party_utils.SerializeStr(data), 15*86400) + fmt.Println(err) + } + } else { + json.Unmarshal([]byte(get), &data) + } + return data, nil +} diff --git a/db/db_sys_union.go b/db/db_sys_union.go index b48a029..67efb5e 100644 --- a/db/db_sys_union.go +++ b/db/db_sys_union.go @@ -123,3 +123,17 @@ func SysUnionById(eg *xorm.Engine, id string) *model.SysUnionSet { } return &data } +func SysUnionByKuaishouByUseByAuth(Db *xorm.Engine, masterId string) (*model.SysUnionSet, error) { + var ( + m model.SysUnionSet + ) + has, err := Db.Where("provider = 'kuaishou' AND is_use = 1 ").Get(&m) + if err != nil { + return nil, err + } + if !has { + return nil, errors.New("找不到联盟设置") + } + + return &m, nil +} diff --git a/db/offical/db_master_list_cfg.go b/db/offical/db_master_list_cfg.go new file mode 100644 index 0000000..7e0aecc --- /dev/null +++ b/db/offical/db_master_list_cfg.go @@ -0,0 +1,19 @@ +package offical + +import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db/offical/model" + "xorm.io/xorm" +) + +func MasterListCfgGetOneData(eg *xorm.Engine, uid, key string) string { + var cfgList model.MasterListCfg + has, err := eg.Where("`k`=? and uid=?", key, uid).Get(&cfgList) + if err != nil { + return "" + } + if has == false { + cfgList = model.MasterListCfg{Uid: uid, K: key} + eg.InsertOne(&cfgList) + } + return cfgList.V +} diff --git a/db/offical/db_user_app_list.go b/db/offical/db_user_app_list.go new file mode 100644 index 0000000..838374e --- /dev/null +++ b/db/offical/db_user_app_list.go @@ -0,0 +1,15 @@ +package offical + +import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/db/offical/model" + "xorm.io/xorm" +) + +func GetUserAppList(eg *xorm.Engine, uid string) *model.UserAppList { + var data model.UserAppList + get, err := eg.Where("uuid=?", uid).Get(&data) + if get == false || err != nil { + return nil + } + return &data +} diff --git a/db/offical/model/master_list_cfg.go b/db/offical/model/master_list_cfg.go new file mode 100644 index 0000000..3963c50 --- /dev/null +++ b/db/offical/model/master_list_cfg.go @@ -0,0 +1,9 @@ +package model + +type MasterListCfg struct { + K string `json:"k" xorm:"not null VARCHAR(255)"` + V string `json:"v" xorm:"TEXT"` + Memo string `json:"memo" xorm:"VARCHAR(255)"` + Uid string `json:"uid" xorm:"comment('0是官方') VARCHAR(255)"` + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` +} diff --git a/db/offical/model/user_app_list.go b/db/offical/model/user_app_list.go new file mode 100644 index 0000000..9720400 --- /dev/null +++ b/db/offical/model/user_app_list.go @@ -0,0 +1,33 @@ +package model + +type UserAppList struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + Uuid int `json:"uuid" xorm:"not null comment('masterId') INT(10)"` + Uid int `json:"uid" xorm:"not null comment('用户ID') INT(10)"` + AppId int `json:"app_id" xorm:"not null comment('应用ID') INT(10)"` + PlanId string `json:"plan_id" xorm:"not null default '' comment('套餐ID') VARCHAR(100)"` + Expire int `json:"expire" xorm:"not null default 0 comment('过期时间') INT(10)"` + Name string `json:"name" xorm:"not null default '' comment('应用主名称') VARCHAR(32)"` + Icon string `json:"icon" xorm:"not null default '' comment('应用主图标') VARCHAR(250)"` + CreateTime int `json:"create_time" xorm:"not null default 0 comment('初次激活时间') INT(10)"` + RenewTime int `json:"renew_time" xorm:"not null default 0 comment('上次续费时间') INT(10)"` + Domain string `json:"domain" xorm:"not null default '' comment('域名') index VARCHAR(110)"` + DomainAlias string `json:"domain_alias" xorm:"not null default '' comment('域名别名') index VARCHAR(110)"` + Platform string `json:"platform" xorm:"not null default '' comment('平台信息 ios,android,applet') VARCHAR(100)"` + Info string `json:"info" xorm:"comment('平台名称如ios.name.#ddd;') TEXT"` + PayMode int `json:"pay_mode" xorm:"not null default 1 comment('付费模式,0授信,1付款') TINYINT(1)"` + Price float32 `json:"price" xorm:"not null default 0.00 comment('应用价格') FLOAT(10,2)"` + PricePay float32 `json:"price_pay" xorm:"not null default 0.00 comment('实际付款价格') FLOAT(10,2)"` + OfficialPrice float32 `json:"official_price" xorm:"not null default 0.00 comment('应用价格') FLOAT(10,2)"` + OfficialPricePay float32 `json:"official_price_pay" xorm:"not null default 0.00 comment('实际付款价格') FLOAT(10,2)"` + State int `json:"state" xorm:"not null default 0 comment('0未创建,1正常,2停用,3过期') TINYINT(1)"` + DeleteAt int `json:"delete_at" xorm:"not null default 0 TINYINT(1)"` + CustomAndroidCount int `json:"custom_android_count" xorm:"default 0 comment('客户端安卓包名重置次数') INT(11)"` + CustomIosCount int `json:"custom_ios_count" xorm:"default 0 comment('客户端ios包名重置次数') INT(11)"` + StoreAndroidCount int `json:"store_android_count" xorm:"default 0 comment('商家端安卓包名重置次数') INT(11)"` + StoreIosCount int `json:"store_ios_count" xorm:"default 0 comment('商家端ios包名重置次数') INT(11)"` + SmsPlatform string `json:"sms_platform" xorm:"default 'mob' comment('mob ljioe联江') VARCHAR(255)"` + IsClose int `json:"is_close" xorm:"default 0 comment('是否关闭') INT(1)"` + Puid int `json:"puid" xorm:"default 0 comment('') INT(11)"` + StoreRateInfo string `json:"store_rate_info" xorm:"comment('付呗商品进件费率') TEXT"` +} diff --git a/go.mod b/go.mod index 1b72a45..124158c 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/google/go-cmp v0.5.9 // indirect github.com/jinzhu/copier v0.3.5 github.com/kr/pretty v0.3.1 // indirect + github.com/mvdan/xurls v1.1.0 github.com/nilorg/sdk v0.0.0-20221104025912-4b6ccb7004d8 github.com/onsi/ginkgo v1.16.5 // indirect github.com/onsi/gomega v1.19.0 // indirect diff --git a/go.sum b/go.sum index 67e9e6e..4dc11e6 100644 --- a/go.sum +++ b/go.sum @@ -279,6 +279,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/mvdan/xurls v1.1.0 h1:OpuDelGQ1R1ueQ6sSryzi6P+1RtBpfQHM8fJwlE45ww= +github.com/mvdan/xurls v1.1.0/go.mod h1:tQlNn3BED8bE/15hnSL2HLkDeLWpNPAwtw7wkEq44oU= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= diff --git a/jd/api.go b/jd/api.go new file mode 100644 index 0000000..22c1e50 --- /dev/null +++ b/jd/api.go @@ -0,0 +1,17 @@ +package jd + +func init() { + JDAppKey = "444ab671c4d095122916453d09af27fc" + JDAppSecret = "aef3c2745cc44194816d0c89c65b3847" + JDVersion = "1.0" + JDRouter = "https://router.jd.com/api" + // taoke.JDRouter = "https://api.jd.com/routerjson" + +} +func send(method string, args map[string]interface{}) ([]byte, error) { + result, err := Execute(method, Arg{"goodsReq": args}) + if err != nil { + return nil, err + } + return result.MarshalJSON() +} diff --git a/jd/client.go b/jd/client.go new file mode 100644 index 0000000..b3720c0 --- /dev/null +++ b/jd/client.go @@ -0,0 +1,285 @@ +package jd + +import ( + "bytes" + "crypto/md5" + "crypto/tls" + "encoding/hex" + "encoding/json" + "errors" + "io" + "io/ioutil" + "net/http" + "net/url" + "sort" + "strconv" + "strings" + "time" + + "github.com/bitly/go-simplejson" + "github.com/nilorg/sdk/convert" +) + +var ( + /**公用方法**/ + // Session 用户登录授权成功后,TOP颁发给应用的授权信息。当此API的标签上注明:“需要授权”,则此参数必传;“不需要授权”,则此参数不需要传;“可选授权”,则此参数为可选 + Session string + // Timeout ... + Timeout time.Duration + // CacheExpiration 缓存过期时间 + CacheExpiration = time.Hour + + /**淘宝平台信息**/ + TaobaoAppKey string + TaobaoAppSecret string + TaobaoRouter string + TaobaoVersion = "2.0" + + /**京东平台信息**/ + JDAppKey string + JDAppSecret string + JDRouter string + JDVersion = "2.0" + + /**拼多多平台信息**/ + PDDAppKey string + PDDAppSecret string + PDDRouter string + PDDVersion = "v1.0" + + /**考拉海购平台信息**/ + KaolaAppKey string + KaolaAppSecret string + KaolaRouter string + KaolaVersion = "1.0" +) + +// Arg 参数 +type Arg map[string]interface{} + +// copyArg 复制参数 +func copyArg(srcArgs Arg) Arg { + newArgs := make(Arg) + for key, value := range srcArgs { + newArgs[key] = value + } + return newArgs +} + +// newCacheKey 创建缓存Key +func newCacheKey(p Arg) string { + cpArgs := copyArg(p) + delete(cpArgs, "session") + delete(cpArgs, "timestamp") + delete(cpArgs, "sign") + + keys := []string{} + for k := range cpArgs { + keys = append(keys, k) + } + // 排序asc + sort.Strings(keys) + // 把所有参数名和参数值串在一起 + cacheKeyBuf := new(bytes.Buffer) + for _, k := range keys { + cacheKeyBuf.WriteString(k) + cacheKeyBuf.WriteString("=") + cacheKeyBuf.WriteString(interfaceToString(cpArgs[k])) + } + h := md5.New() + io.Copy(h, cacheKeyBuf) + return hex.EncodeToString(h.Sum(nil)) +} + +// execute 执行API接口 +func execute(p Arg, router string) (bytes []byte, err error) { + err = checkConfig() + if err != nil { + return + } + + var req *http.Request + req, err = http.NewRequest("POST", router, strings.NewReader(p.getReqData())) + if err != nil { + return + } + tr := &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + } + req.Header.Add("Content-Type", "application/x-www-form-urlencoded;charset=utf-8") + httpClient := &http.Client{Transport: tr} + httpClient.Timeout = Timeout + var resp *http.Response + resp, err = httpClient.Do(req) + if err != nil { + return + } + + if resp.StatusCode != 200 { + err = errors.New("请求错误:" + strconv.Itoa(resp.StatusCode)) + return + } + + defer resp.Body.Close() + bytes, err = ioutil.ReadAll(resp.Body) + // fmt.Printf("\n\n\nreq: %v\n\nresp: %v\n\n\n", p.getReqData(), string(bytes)) + return +} + +// Execute 执行API接口 +func Execute(method string, p Arg) (res *simplejson.Json, err error) { + p, r := setReqData(p, method) + var bodyBytes []byte + bodyBytes, err = execute(p, r) + if err != nil { + return + } + + return bytesToResult(bodyBytes) +} + +func bytesToResult(bytes []byte) (res *simplejson.Json, err error) { + res, err = simplejson.NewJson(bytes) + if err != nil { + return + } + if responseError, ok := res.CheckGet("error_response"); ok { + if subMsg, subOk := responseError.CheckGet("sub_msg"); subOk { + err = errors.New(subMsg.MustString()) + } else if zhDesc, descOk := responseError.CheckGet("zh_desc"); descOk { + err = errors.New(zhDesc.MustString()) + } else { + err = errors.New(responseError.Get("msg").MustString()) + } + res = nil + } + return +} + +// ExecuteCache 执行API接口,缓存 + +// 检查配置 +func checkConfig() error { + if TaobaoAppKey == "" && JDAppKey == "" && KaolaAppKey == "" && PDDAppKey == "" { + return errors.New("至少需要设置一个平台参数") + } + return nil +} + +//组装参数及添加公共参数 +func setReqData(p Arg, method string) (Arg, string) { + platform := strings.Split(method, ".")[0] + router := "" + hh, _ := time.ParseDuration("8h") + loc := time.Now().UTC().Add(hh) + if platform == "taobao" { + //淘宝 + p["timestamp"] = strconv.FormatInt(loc.Unix(), 10) + p["partner_id"] = "Blant" + p["app_key"] = TaobaoAppKey + p["v"] = TaobaoVersion + if Session != "" { + p["session"] = Session + } + p["method"] = method + p["format"] = "json" + p["sign_method"] = "md5" + // 设置签名 + p["sign"] = getSign(p, TaobaoAppSecret) + router = TaobaoRouter + } else if platform == "jd" { + //京东 + param := p + p = Arg{} + p["param_json"] = param + p["app_key"] = JDAppKey + p["v"] = JDVersion + p["timestamp"] = loc.Format("2006-01-02 15:04:05") + p["method"] = method + p["format"] = "json" + p["sign_method"] = "md5" + // 设置签名 + p["sign"] = getSign(p, JDAppSecret) + router = JDRouter + } else if platform == "pdd" { + //拼多多 + p["type"] = method + p["data_type"] = "json" + p["version"] = PDDVersion + p["client_id"] = PDDAppKey + p["timestamp"] = strconv.FormatInt(loc.Unix(), 10) + // 设置签名 + p["sign"] = getSign(p, PDDAppSecret) + router = PDDRouter + } else if platform == "kaola" { + //考拉海购 + p["method"] = method + p["v"] = KaolaVersion + p["signMethod"] = "md5" + p["unionId"] = KaolaAppKey + p["timestamp"] = loc.Format("2006-01-02 15:04:05") + // 设置签名 + p["sign"] = getSign(p, KaolaAppSecret) + router = KaolaRouter + } else if platform == "suning" { + // TODO 苏宁 + + } else if platform == "vip" { + // TODO 唯品会 + } + + return p, router +} + +// 获取请求数据 +func (p Arg) getReqData() string { + // 公共参数 + args := url.Values{} + // 请求参数 + for key, val := range p { + args.Set(key, interfaceToString(val)) + } + return args.Encode() +} + +// 获取签名 +func getSign(p Arg, secret string) string { + // 获取Key + var keys []string + for k := range p { + keys = append(keys, k) + } + // 排序asc + sort.Strings(keys) + // 把所有参数名和参数值串在一起 + query := bytes.NewBufferString(secret) + for _, k := range keys { + query.WriteString(k) + query.WriteString(interfaceToString(p[k])) + } + query.WriteString(secret) + // 使用MD5加密 + h := md5.New() + _, _ = io.Copy(h, query) + // 把二进制转化为大写的十六进制 + return strings.ToUpper(hex.EncodeToString(h.Sum(nil))) +} + +func interfaceToString(src interface{}) string { + if src == nil { + panic(ErrTypeIsNil) + } + switch src.(type) { + case string: + return src.(string) + case int, int8, int32, int64: + case uint8, uint16, uint32, uint64: + case float32, float64: + return convert.ToString(src) + } + data, err := json.Marshal(src) + if err != nil { + panic(err) + } + return string(data) +} diff --git a/jd/convert_url.go b/jd/convert_url.go new file mode 100644 index 0000000..c8a7084 --- /dev/null +++ b/jd/convert_url.go @@ -0,0 +1,5 @@ +package jd + +func ConvertUrl() { + +} diff --git a/jd/errors.go b/jd/errors.go new file mode 100644 index 0000000..93d1aa5 --- /dev/null +++ b/jd/errors.go @@ -0,0 +1,8 @@ +package jd + +import "errors" + +var ( + ErrTypeIsNil = errors.New("类型为Nil") + ErrTypeUnknown = errors.New("未处理到的数据类型") +) diff --git a/jd/featured.go b/jd/featured.go new file mode 100644 index 0000000..d64a090 --- /dev/null +++ b/jd/featured.go @@ -0,0 +1,15 @@ +package jd + +// Featured is 京粉精选商品 https://open.jd.com/home/home#/doc/api?apiCateId=461&apiId=3588&apiName=jd.union.open.goods.jingfen.query +func Featured(r *RequestJD) ([]byte, error) { + method := "jd.union.open.goods.jingfen.query" + args := map[string]interface{}{ + "pageIndex": r.PageIndex, + "pageSize": r.PageSize, + // 1-好券商品,2-精选卖场,10-9.9包邮,15-京东配送,22-实时热销榜,23-为你推荐,24-数码家电,25-超市,26-母婴玩具,27-家具日用,28-美妆穿搭,29-医药保健,30-图书文具,31-今日必推,32-京东好物,33-京东秒杀,34-拼购商品,40-高收益榜,41-自营热卖榜,109-新品首发,110-自营,112-京东爆品,125-首购商品,129-高佣榜单,130-视频商品,153-历史最低价商品榜 + "eliteId": r.EliteID, + // 排序字段(price:单价, commissionShare:佣金比例, commission:佣金, inOrderCount30DaysSku:sku维度30天引单量,comments:评论数,goodComments:好评数) + "sortName": r.SortName, + } + return send(method, args) +} diff --git a/jd/guess.go b/jd/guess.go new file mode 100644 index 0000000..673aab3 --- /dev/null +++ b/jd/guess.go @@ -0,0 +1,19 @@ +package jd + +// Guess is 猜你喜欢 https://open.jd.com/home/home#/doc/api?apiCateId=461&apiId=5479&apiName=jd.union.open.goods.material.query +func Guess(r *RequestJD) ([]byte, error) { + method := "jd.union.open.goods.material.query" + args := map[string]interface{}{ + "pageIndex": r.PageIndex, + "pageSize": r.PageSize, + // 1-好券商品,2-精选卖场,10-9.9包邮,15-京东配送,22-实时热销榜,23-为你推荐,24-数码家电,25-超市,26-母婴玩具,27-家具日用,28-美妆穿搭,29-医药保健,30-图书文具,31-今日必推,32-京东好物,33-京东秒杀,34-拼购商品,40-高收益榜,41-自营热卖榜,109-新品首发,110-自营,112-京东爆品,125-首购商品,129-高佣榜单,130-视频商品,153-历史最低价商品榜 + "eliteId": r.EliteID, + // 排序字段(price:单价, commissionShare:佣金比例, commission:佣金, inOrderCount30DaysSku:sku维度30天引单量,comments:评论数,goodComments:好评数) + "sortName": r.SortName, + } + if r.UserIDType != 0 && r.UserID != "" { + args["userIdType"] = r.UserIDType + args["userId"] = r.UserID + } + return send(method, args) +} diff --git a/jd/jd_zhimeng.go b/jd/jd_zhimeng.go new file mode 100644 index 0000000..c177fa1 --- /dev/null +++ b/jd/jd_zhimeng.go @@ -0,0 +1,13 @@ +package jd + +import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/zhimeng" +) + +// NewZhiMengJingDongSDK is constructor +func NewZhiMengJingDongSDK() *zhimeng.SDK { + jd := &zhimeng.SDK{} + jd.Init(md.PVD_JD) + return jd +} diff --git a/jd/model.go b/jd/model.go new file mode 100644 index 0000000..431fd75 --- /dev/null +++ b/jd/model.go @@ -0,0 +1,88 @@ +package jd + +// 1-好券商品,2-精选卖场,10-9.9包邮,15-京东配送,22-实时热销榜,23-为你推荐,24-数码家电,25-超市,26-母婴玩具,27-家具日用,28-美妆穿搭,29-医药保健,30-图书文具,31-今日必推,32-京东好物,33-京东秒杀,34-拼购商品,40-高收益榜,41-自营热卖榜,109-新品首发,110-自营,112-京东爆品,125-首购商品,129-高佣榜单,130-视频商品,153-历史最低价商品榜 +// 排序字段(price:单价, commissionShare:佣金比例, commission:佣金, inOrderCount30DaysSku:sku维度30天引单量,comments:评论数,goodComments:好评数) +//RequestJD is 请求 京东sdk的参数 +type RequestJD struct { + PageIndex int `json:"page_index"` + PageSize int `json:"page_size"` + EliteID int `json:"elite_id"` + SortName string `json:"sort_name"` + UserIDType int `json:"userid_type"` + UserID string `json:"user_id"` +} + +// JDFeaturedResponse is return from taoke.jd +type JDFeaturedResponse struct { + JdUnionOpenGoodsJingfenQueryResponse struct { + Code string `json:"code"` + Result string `json:"result"` + } `json:"jd_union_open_goods_jingfen_query_response"` +} + +// JDFeature is jd 精选 for微信 +type JDFeature struct { + BrandCode string `json:"brandCode"` + BrandName string `json:"brandName"` + CategoryInfo struct { + Cid1 int `json:"cid1"` + Cid1Name string `json:"cid1Name"` + Cid2 int `json:"cid2"` + Cid2Name string `json:"cid2Name"` + Cid3 int `json:"cid3"` + Cid3Name string `json:"cid3Name"` + } `json:"categoryInfo"` + Comments int `json:"comments"` + CommissionInfo struct { + Commission float64 `json:"commission"` + CommissionShare float64 `json:"commissionShare"` + CouponCommission float64 `json:"couponCommission"` + PlusCommissionShare float64 `json:"plusCommissionShare"` + } `json:"commissionInfo"` + CouponInfo struct { + CouponList []struct { + BindType int `json:"bindType"` + Discount float64 `json:"discount"` + GetEndTime int64 `json:"getEndTime"` + GetStartTime int64 `json:"getStartTime"` + HotValue int `json:"hotValue"` + IsBest int `json:"isBest"` + Link string `json:"link"` + PlatformType int `json:"platformType"` + Quota float64 `json:"quota"` + UseEndTime int64 `json:"useEndTime"` + UseStartTime int64 `json:"useStartTime"` + } `json:"couponList"` + } `json:"couponInfo"` + GoodCommentsShare float64 `json:"goodCommentsShare"` + ImageInfo struct { + ImageList []struct { + URL string `json:"url"` + } `json:"imageList"` + } `json:"imageInfo"` + InOrderCount30Days int `json:"inOrderCount30Days"` + InOrderCount30DaysSku int `json:"inOrderCount30DaysSku"` + IsHot int `json:"isHot"` + MaterialURL string `json:"materialUrl"` + Owner string `json:"owner"` + PinGouInfo struct { + } `json:"pinGouInfo"` + PriceInfo struct { + LowestCouponPrice float64 `json:"lowestCouponPrice"` + LowestPrice float64 `json:"lowestPrice"` + LowestPriceType int `json:"lowestPriceType"` + Price float64 `json:"price"` + } `json:"priceInfo"` + ResourceInfo struct { + EliteID int `json:"eliteId"` + EliteName string `json:"eliteName"` + } `json:"resourceInfo"` + ShopInfo struct { + ShopID int `json:"shopId"` + ShopLevel float64 `json:"shopLevel"` + ShopName string `json:"shopName"` + } `json:"shopInfo"` + SkuID int64 `json:"skuId"` + SkuName string `json:"skuName"` + Spuid int64 `json:"spuid"` +} diff --git a/jd/order_track.go b/jd/order_track.go new file mode 100644 index 0000000..f65bf6f --- /dev/null +++ b/jd/order_track.go @@ -0,0 +1,13 @@ +package jd + +func OrderTrack() { + method := "jd.union.open.order.query" + args := map[string]interface{}{ + "pageNo": "1", + "pageSize": "100", + "type": "3", + "key": "", + } + send(method, args) + return +} diff --git a/jd/recommend.go b/jd/recommend.go new file mode 100644 index 0000000..07064d4 --- /dev/null +++ b/jd/recommend.go @@ -0,0 +1,15 @@ +package jd + +// Recommend is 京东推荐商品https://open.jd.com/home/home#/doc/api?apiCateId=461&apiId=3588&apiName=jd.union.open.goods.jingfen.query +func Recommend(r *RequestJD) ([]byte, error) { + method := "jd.kpl.open.union.search.byelited" + args := map[string]interface{}{ + "pageIndex": r.PageIndex, + "pageSize": r.PageSize, + // 1-好券商品,2-超级大卖场,10-9.9专区,22-热销爆品,23-为你推荐,24-数码家电,25-超市,26-母婴玩具,27-家具日用,28-美妆穿搭,29-医药保健,30-图书文具,31-今日必推,32-品牌好货,33-秒杀商品,34-拼购商品,109-新品首发,110-自营,125-首购商品,129-高佣榜单,130-视频商品 + "eliteId": r.EliteID, + // 排序字段price:单价, commissionShare:佣金比例, commission:佣金, inOrderCount30DaysSku:sku维度30天引单量,comments:评论数,goodComments:好评数 + "sortName": r.SortName, + } + return send(method, args) +} diff --git a/jd/sdk.go b/jd/sdk.go new file mode 100644 index 0000000..d3c8928 --- /dev/null +++ b/jd/sdk.go @@ -0,0 +1,95 @@ +package jd + +import ( + "encoding/json" +) + +//SDK is sdk for jd +type SDK struct { + response []byte + fmap map[string]func(*RequestJD) + fname string + err error +} + +//Init is init sdk +func (s *SDK) Init() { + s.fmap = make(map[string]func(*RequestJD)) +} + +//SelectFunction is select func +func (s *SDK) SelectFunction(fname string) *SDK { + s.fname = fname + return s +} + +//WithArgs is request args +func (s *SDK) WithArgs(args *RequestJD) *SDK { + f := s.fmap[s.fname] + f(args) + return s +} + +// Result is func result +func (s *SDK) Result() (*SDK, error) { + return s, s.err +} + +// Register is register func +func (s *SDK) Register(name string, f func(*RequestJD)) { + s.fmap[name] = f +} + +//ToBytes is return []byte +func (s *SDK) ToBytes() []byte { + return s.response +} + +// ToString is return string +func (s *SDK) ToString() string { + return string(s.response) +} + +//ToMapInterface is return map[string]interface{} +func (s *SDK) ToMapInterface() map[string]interface{} { + m := make(map[string]interface{}) + json.Unmarshal(s.response, &m) + return m +} + +// Featured is jd 精选列表 +func (s *SDK) Featured(r *RequestJD) { + d, err := Featured(r) + if err != nil { + s.err = err + } + s.response = d +} + +// Guess is 猜你喜欢列表 +func (s *SDK) Guess(r *RequestJD) { + d, err := Guess(r) + if err != nil { + s.err = err + } + s.response = d +} + +// Recommend is 推荐列表 +func (s *SDK) Recommend(r *RequestJD) { + d, err := Recommend(r) + if err != nil { + s.err = err + } + s.response = d +} + +//NewJDSDK is jingdong sdk +func NewJDSDK() *SDK { + sdk := new(SDK) + sdk.Init() + sdk.Register("featured", sdk.Featured) + sdk.Register("guess", sdk.Guess) + sdk.Register("recommend", sdk.Recommend) + return sdk +} diff --git a/md/kuaishou.go b/md/kuaishou.go new file mode 100644 index 0000000..9c377c4 --- /dev/null +++ b/md/kuaishou.go @@ -0,0 +1,101 @@ +package md + +type KuaishouOrder struct { + Pcursor string `json:"pcursor"` + OrderView []OrderView `json:"orderView"` +} +type OrderView struct { + Oid int `json:"oid"` + ActivityUserId int `json:"activityUserId"` + ActivityId int `json:"activityId"` + CpsOrderStatus int `json:"cpsOrderStatus"` + OrderCreateTime int64 `json:"orderCreateTime"` + OrderTradeAmount int64 `json:"orderTradeAmount"` + PayAmount int `json:"payAmount"` + RegimentalPromotionRate int `json:"regimentalPromotionRate"` + RegimentalPromotionAmount int `json:"regimentalPromotionAmount"` + CpsOrderProductView []struct { + Oid int64 `json:"oid"` + ItemId int64 `json:"itemId"` + ItemTitle string `json:"itemTitle"` + ItemPrice int64 `json:"itemPrice"` + SellerId int64 `json:"sellerId"` + SellerNickName string `json:"sellerNickName"` + SkuId int `json:"skuId"` + } `json:"cpsOrderProductView"` + CreateTime int64 `json:"createTime"` + UpdateTime int64 `json:"updateTime"` + SendTime int64 `json:"sendTime"` + SendStatus int `json:"sendStatus"` + RecvTime int64 `json:"recvTime"` + PromotionId int `json:"promotionId"` + PromotionNickName string `json:"promotionNickName"` + PromotionType int `json:"promotionType"` + SettlementAmount int `json:"settlementAmount"` + SettlementTime int64 `json:"settlementTime"` + SettlementSuccessTime int64 `json:"settlementSuccessTime"` + BuyerOpenId string `json:"buyerOpenId"` + PromotionKwaiId string `json:"promotionKwaiId"` + ExpendRegimentalSettleAmount int `json:"expendRegimentalSettleAmount"` + ExpendEstimateSettleAmount int `json:"expendEstimateSettleAmount"` + ExpendRegimentalPromotionRate int `json:"expendRegimentalPromotionRate"` + BaseAmount int `json:"baseAmount"` + ShareRateStr string `json:"shareRateStr"` + ExcitationInCome int `json:"excitationInCome"` + ServiceIncome int `json:"serviceIncome"` + SettlementBizType int `json:"settlementBizType"` + FundType int `json:"fundType"` + KwaimoneyUserId int `json:"kwaimoneyUserId"` + KwaimoneyUserNickName string `json:"kwaimoneyUserNickName"` +} + +type KuaishouGoods struct { + GoodsId int `json:"goodsId"` + GoodsPrice int `json:"goodsPrice"` + GoodsTitle string `json:"goodsTitle"` + GoodsDesc string `json:"goodsDesc"` + MallId int `json:"mallId"` + MallName string `json:"mallName"` + MallType int `json:"mallType"` + GoodsImageUrl string `json:"goodsImageUrl"` + CategoryId int `json:"categoryId"` + PromotionRate int `json:"promotionRate"` + SalesTip int `json:"salesTip"` + GoodsGalleryUrls interface{} `json:"goodsGalleryUrls"` + PromotionAmount int `json:"promotionAmount"` + ItemDescUrls interface{} `json:"itemDescUrls"` + ExpressId int `json:"expressId"` + ZkGoodsPrice int `json:"zkGoodsPrice"` +} +type KuaishouCpsOrder struct { + Oid int `json:"oid"` + CpsOrderStatus int `json:"cpsOrderStatus"` + OrderCreateTime int `json:"orderCreateTime"` + PayTime int `json:"payTime"` + OrderTradeAmount int `json:"orderTradeAmount"` + CreateTime int64 `json:"createTime"` + UpdateTime int64 `json:"updateTime"` + SettlementSuccessTime int64 `json:"settlementSuccessTime"` + SettlementAmount int `json:"settlementAmount"` + CpsKwaimoneyOrderProductView []struct { + Oid int `json:"oid"` + ItemId int `json:"itemId"` + ItemTitle string `json:"itemTitle"` + ItemPicUrl string `json:"itemPicUrl"` + ItemPrice int `json:"itemPrice"` + SkuDesc string `json:"skuDesc"` + EstimatedIncome int `json:"estimatedIncome"` + CommissionRate int `json:"commissionRate"` + PaymentFee int `json:"paymentFee"` + CpsPid string `json:"cpsPid"` + SellerId int `json:"sellerId"` + SellerNickname string `json:"sellerNickname"` + Num int `json:"num"` + CpsType int `json:"cpsType"` + DistributorId int `json:"distributorId"` + DistributorNickname string `json:"distributorNickname"` + Comments string `json:"comments"` + } `json:"cpsKwaimoneyOrderProductView"` + BaseAmount int `json:"baseAmount"` + ShareRateStr string `json:"shareRateStr"` +} diff --git a/md/md_chain.go b/md/md_chain.go new file mode 100644 index 0000000..f663f19 --- /dev/null +++ b/md/md_chain.go @@ -0,0 +1,98 @@ +package md + +type TCPrase struct { + Count string `json:"count"` //转链内容 + SuccessCount string `json:"success_count"` //转链内容 + FailCount string `json:"fail_count"` //转链内容 + GID string `json:"gid"` //商品id + GoodsMinImg string `json:"goods_min_img"` //商品小图片 + GoodsImg string `json:"goods_img"` //商品图片 + GoodsTitle string `json:"goods_title"` //商品标题 + Provider string `json:"provider"` //渠道代码 + ProviderName string `json:"provider_name"` //渠道名字 + GoodsCostPrice string `json:"goods_cost_price"` //原价 + Commission string `json:"commission"` //反的价钱 + FCommission string `json:"f_commission"` //反的价钱 + WlGoodsPrice string `json:"wl_goods_price"` //卷后价 + CouponPrice string `json:"coupon_price"` //优惠券价 + ShareValue string `json:"share_value"` //分享赚 + ProductDetail *ProductDetailResponse `json:"detail_data"` //商品详情 + TurnChainLink string `json:"turn_chain_link"` // 转链后的链接 + CommissionRate string `json:"commission_rate"` + Tkl string `json:"tkl"` // 淘口令 + IsTkl string `json:"is_tkl"` // 淘口令 + DownloadLink string `json:"downloadLink"` + InviteCode string `json:"invite_code"` + IsNeedAuth string `json:"is_need_auth"` + PlatType string `json:"plat_type"` + TurnGoods []TurnGoods `json:"turn_goods"` +} +type TurnGoods struct { + GID string `json:"gid"` //商品id + GoodsMinImg string `json:"goods_min_img"` //商品小图片 + GoodsImg string `json:"goods_img"` //商品图片 + GoodsTitle string `json:"goods_title"` //商品标题 + Provider string `json:"provider"` //渠道代码 + ProviderName string `json:"provider_name"` //渠道名字 + GoodsCostPrice string `json:"goods_cost_price"` //原价 + Commission string `json:"commission"` //反的价钱 + FCommission string `json:"f_commission"` //反的价钱 + WlGoodsPrice string `json:"wl_goods_price"` //卷后价 + CouponPrice string `json:"coupon_price"` //优惠券价 + ShareValue string `json:"share_value"` //分享赚 + ProductDetail *ProductDetailResponse `json:"detail_data"` //商品详情 + TurnChainLink string `json:"turn_chain_link"` // 转链后的链接 + CommissionRate string `json:"commission_rate"` + Tkl string `json:"tkl"` // 淘口令 + IsTkl string `json:"is_tkl"` // 淘口令 + Url string `json:"url"` +} + +type ItemParseInfo struct { + ItemId string `json:"item_id"` // 商品ID + Title string `json:"title"` // 标题 + CategoryId string `json:"category_id"` // 目录ID + CategoryName string `json:"category_name"` // 目录名 + Price string `json:"price"` // 价格 + PriceOriginal string `json:"price_original"` // 原价 + Commission string `json:"commission"` // 可赚取佣金 + CommissionRate string `json:"commission_rate"` // 佣金比例 + CouponUrl string `json:"coupon_url"` // 优惠券地址 + DetailUrl string `json:"detail_url"` // 优惠券地址 + APPUrl string `json:"app_url"` // 唤起app地址 + CouponPrice float64 `json:"coupon_price"` // 优惠券面值 + FinalPrice string `json:"final_price"` // 券后价 + EarnPrice string `json:"earn_price"` //立省 + Thumbnail string `json:"thumbnail"` // 缩略图 + Provider string `json:"provider"` // 供应商 + ProviderName string `json:"providerName"` // 供应商名称 + GoodsDesc string `json:"goodsDesc"` //描述 + GoodsImgList []string `json:"goodsImgList"` //商品多组图片 + ImageList []string `json:"imgList"` + Video []interface{} `json:"video"` + InOrderCount string `json:"inOrderCount"` + DetailImgList []string `json:"detailImgList"` + GoodsSales string `json:"goods_sales"` + ShopName string `json:"shop_name"` + Word string `json:"word"` + Param ParamData `json:"param"` + IsNeedChangeUrl string `json:"is_need_change_url"` + Pvd string `json:"pvd"` + IsFav string `json:"is_fav"` + ShareUrlArgs map[string]interface{} `json:"share_url_args"` + FavArgs interface{} `json:"fav_args"` + ActivityId string `json:"activity_id"` + Url string `json:"url"` + NewProvider string `json:"new_provider"` +} +type ParamData struct { + GID string `json:"gid"` + GoodURL string `json:"good_url"` + CouponURL string `json:"coupon_url"` + CouponPrice string `json:"coupon_price"` + ActivityURL string `json:"activity_url"` + IsShare string `json:"is_share"` + IsFree string `json:"is_free"` + IsWxMini string `json:"is_wx_mini"` + Commission string `json:"commission"` +} diff --git a/md/official_recommend_list.go b/md/official_recommend_list.go new file mode 100644 index 0000000..568543a --- /dev/null +++ b/md/official_recommend_list.go @@ -0,0 +1,26 @@ +package md + +// 美团 + +type OfficialRecommendUrl struct { + Url string // 链接 + WxQrcodeUrl string + WxMiniprogramPath string + AppUrl string + Appid string + Id string //小程序原始id + TaobaoWord string + ClickUrl string + Seq string + Title string + Content string + SuccessContent string +} +type ActivityPlatform struct { + ActivityPlatformId string `json:"activity_id"` + MaterialId string `json:"material_id"` + ActivityPlatformUrl string `json:"url"` +} +type KaolaActivityList struct { + Url string `json:"shareLink"` +} diff --git a/md/product_detail.go b/md/product_detail.go index b63c981..5933b87 100644 --- a/md/product_detail.go +++ b/md/product_detail.go @@ -65,6 +65,7 @@ type DetailResponse struct { // MoreDetailResponse is for response detail type MoreDetailResponse struct { + ClickUrl string `json:"click_url"` GID string `json:"gid"` GoodsImg string `json:"goods_img"` GoodsTitle string `json:"goods_title"` @@ -162,6 +163,8 @@ type PlatformCss struct { // ProductDetailResponse productdetail type ProductDetailResponse struct { + ClickUrl string `json:"click_url"` + IsNull string `json:"is_null"` IsCanBuy string `json:"is_can_buy"` //是否能购买 IsShowCouponList string `json:"is_show_coupon_list"` //是否展示优惠券弹出 UserCouponAmount string `json:"user_coupon_amount"` //优惠券额度 diff --git a/md/provider.go b/md/provider.go index f64a9e7..ff3a9b9 100644 --- a/md/provider.go +++ b/md/provider.go @@ -18,6 +18,7 @@ const ( PVD_STARBUCKS = "starbucks" PVD_MCDONALD = "mcdonald" PVD_NAYUKI = "nayuki" + PVD_TIKTOKLIFE = "tikTok_life" PVD_BURGERKING = "burger_king" PVD_HEYTEA = "heytea" PVD_PIZZA = "pizza" diff --git a/md/tik_tok.go b/md/tik_tok.go index 4f4c53e..e9ec1cc 100644 --- a/md/tik_tok.go +++ b/md/tik_tok.go @@ -1,29 +1,30 @@ package md type TikTokBase struct { - AuthType string `json:"auth_type"` - LiveAuthType string `json:"live_auth_type"` - ApiGoodsAppKey string `json:"api_goods_app_key"` - ApiGoodsAppSecret string `json:"api_goods_app_secret"` - ApiTeamAppKey string `json:"api_team_app_key"` - ApiTeamAppSecret string `json:"api_team_app_secret"` - ApiLiveAppKey string `json:"api_live_app_key"` - ApiLiveAppSecret string `json:"api_live_app_secret"` - GoodsAccessToken string `json:"goods_access_token"` - LiveAccessToken string `json:"live_access_token"` - TeamAccessToken string `json:"team_access_token"` - GoodsPid string `json:"goods_pid"` - LivePid string `json:"live_pid"` - SysApiGoodsAppKey string `json:"sys_api_goods_app_key"` - SysApiGoodsAppSecret string `json:"sys_api_goods_app_secret"` - SysApiTeamAppKey string `json:"sys_api_team_app_key"` - SysApiTeamAppSecret string `json:"sys_api_team_app_secret"` - SysApiLiveAppKey string `json:"sys_api_live_app_key"` - SysApiLiveAppSecret string `json:"sys_api_live_app_secret"` - SysGoodsAccessToken string `json:"sys_goods_access_token"` - SysLiveAccessToken string `json:"sys_live_access_token"` - SysGoodsPid string `json:"sys_goods_pid"` - SysLivePid string `json:"sys_live_pid"` - AuthSubjectType string `json:"auth_subject_type"` - LiveAuthSubjectType string `json:"live_auth_subject_type"` + AuthType string `json:"auth_type"` + LiveAuthType string `json:"live_auth_type"` + ApiGoodsAppKey string `json:"api_goods_app_key"` + ApiGoodsAppSecret string `json:"api_goods_app_secret"` + ApiTeamAppKey string `json:"api_team_app_key"` + ApiTeamAppSecret string `json:"api_team_app_secret"` + ApiLiveAppKey string `json:"api_live_app_key"` + ApiLiveAppSecret string `json:"api_live_app_secret"` + GoodsAccessToken string `json:"goods_access_token"` + LiveAccessToken string `json:"live_access_token"` + TeamAccessToken string `json:"team_access_token"` + GoodsPid string `json:"goods_pid"` + LivePid string `json:"live_pid"` + SysApiGoodsAppKey string `json:"sys_api_goods_app_key"` + SysApiGoodsAppSecret string `json:"sys_api_goods_app_secret"` + SysApiTeamAppKey string `json:"sys_api_team_app_key"` + SysApiTeamAppSecret string `json:"sys_api_team_app_secret"` + SysApiLiveAppKey string `json:"sys_api_live_app_key"` + SysApiLiveAppSecret string `json:"sys_api_live_app_secret"` + SysGoodsAccessToken string `json:"sys_goods_access_token"` + SysLiveAccessToken string `json:"sys_live_access_token"` + SysGoodsPid string `json:"sys_goods_pid"` + SysLivePid string `json:"sys_live_pid"` + AuthSubjectType string `json:"auth_subject_type"` + LiveAuthSubjectType string `json:"live_auth_subject_type"` + ExtendTeamTokenMap map[string]interface{} `json:"extend_team_token_map"` } diff --git a/md/url.go b/md/url.go index 056d2f0..8fd82d3 100644 --- a/md/url.go +++ b/md/url.go @@ -9,6 +9,7 @@ type ExtraData struct { // 转链后链接 type ConvertedUrls struct { ItemId string `json:"item_id"` + ItemUrl string `json:"item_url"` NumGoodsId string `json:"num_goods_id"` URL string `json:"url"` // 短链接 ShortenURL string `json:"open_app_url"` // 会打开app的长链接 diff --git a/pdd/api.go b/pdd/api.go new file mode 100644 index 0000000..945df6d --- /dev/null +++ b/pdd/api.go @@ -0,0 +1,49 @@ +package pdd + +import ( + zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" + "encoding/json" + "sort" + "strings" + "time" +) + +var ( + PDD_HOST = "http://gw-api.pinduoduo.com/api/router" + PDD_AK = "43eed45f20d94fbf828744a77a45e3e2" + PDD_SK = "6ccdd6614f804ed8b0e23c2721be857da3a04b5b" + PDD_CS = "4ee672167e1ee51aa3a9ea864d33629a230a114c" +) + +func send(args map[string]interface{}, method string) ([]byte, error) { + args["timestamp"] = zhios_third_party_utils.Int64ToStr(time.Now().UnixNano() / 1e6) + args["data_type"] = "JSON" + args["client_id"] = PDD_AK + args["type"] = method + args["sign"] = sign(args, PDD_CS) + bargs, err := json.Marshal(args) + if err != nil { + return nil, err + } + return zhios_third_party_utils.CurlPost(PDD_HOST, bargs, nil) +} + +func sign(m map[string]interface{}, sk string) string { + // key sort + keys := make([]string, 0, len(m)) + for k := range m { + keys = append(keys, k) + } + sort.Strings(keys) + str := "" + for _, k := range keys { + switch m[k].(type) { + case int: + str += k + zhios_third_party_utils.IntToStr(m[k].(int)) + case string: + str += k + m[k].(string) + } + } + str = sk + str + sk + return strings.ToUpper(zhios_third_party_utils.Md5(str)) +} diff --git a/pdd/detail.go b/pdd/detail.go new file mode 100644 index 0000000..7113a24 --- /dev/null +++ b/pdd/detail.go @@ -0,0 +1,13 @@ +package pdd + +// 多多进宝API +// https://open.pinduoduo.com/application/document/api?id=pdd.ddk.goods.recommend.get +//func Detail() { +// method := "pdd.ddk.goods.recommend.get" +// args := map[string]interface{}{ +// "channel_type": "", // 非必填, 0-1.9包邮, 1-今日爆款, 2-品牌清仓,3-相似商品推荐,4-猜你喜欢,5-实时热销,6-实时收益,7-今日畅销,8-高佣榜单,默认1 +// "limit": 400, // 非必填, 请求数量;默认值 : 400 +// "offset": 400, // 非必填, 从多少位置开始请求;默认值 : 0,offset需是limit的整数倍,仅支持整页翻页 +// //"list_id": "", // 非必填,翻页时建议填写前页返回的list_id值 +// } +//} diff --git a/pdd/pdd_zhimeng.go b/pdd/pdd_zhimeng.go new file mode 100644 index 0000000..af9f389 --- /dev/null +++ b/pdd/pdd_zhimeng.go @@ -0,0 +1,10 @@ +package pdd + +import "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/zhimeng" + +// NewZhiMengJingDongSDK is constructor +func NewZhiMengPDDSDK() *zhimeng.SDK { + pdd := &zhimeng.SDK{} + pdd.Init("pdd") + return pdd +} diff --git a/pdd/recommend.go b/pdd/recommend.go new file mode 100644 index 0000000..cc90189 --- /dev/null +++ b/pdd/recommend.go @@ -0,0 +1,91 @@ +package pdd + +import ( + "encoding/json" +) + +type PddRecommendItem struct { + CouponRemainQuantity int `json:"coupon_remain_quantity"` + PromotionRate int `json:"promotion_rate"` + CatIds []int `json:"cat_ids"` + CouponMinOrderAmount int `json:"coupon_min_order_amount"` + MallID int `json:"mall_id"` + MallName string `json:"mall_name"` + CouponTotalQuantity int `json:"coupon_total_quantity"` + MerchantType string `json:"merchant_type"` + LgstTxt string `json:"lgst_txt"` + GoodsName string `json:"goods_name"` + SalesTip string `json:"sales_tip"` + GoodsID string `json:"goods_sign"` + DescTxt string `json:"desc_txt"` + PredictPromotionRate int `json:"predict_promotion_rate"` + GoodsDesc string `json:"goods_desc"` + OptName string `json:"opt_name"` + GoodsThumbnailURL string `json:"goods_thumbnail_url"` + OptID string `json:"opt_id"` + OptIds []int `json:"opt_ids"` + SearchID string `json:"search_id"` + GoodsImageURL string `json:"goods_image_url"` + HasCoupon bool `json:"has_coupon"` + MinNormalPrice float64 `json:"min_normal_price"` + ServTxt string `json:"serv_txt"` + CouponStartTime int `json:"coupon_start_time"` + MinGroupPrice float64 `json:"min_group_price"` + CouponDiscount int `json:"coupon_discount"` + CouponEndTime int `json:"coupon_end_time"` +} +type PddRecommend struct { + GoodsBasicDetailResponse struct { + Total int `json:"total"` + ListID string `json:"list_id"` + List []PddRecommendItem `json:"list"` + RequestID string `json:"request_id"` + SearchID string `json:"search_id"` + } `json:"goods_basic_detail_response"` +} + +// 多多进宝API +// https://open.pinduoduo.com/application/document/api?id=pdd.ddk.goods.recommend.get +func Recommend(page, size, id, gid, cid string) (*PddRecommend, error) { + method := "pdd.ddk.goods.recommend.get" + args := map[string]interface{}{ + //"channel_type": id, // 非必填, 0-1.9包邮, 1-今日爆款, 2-品牌清仓,3-相似商品推荐,4-猜你喜欢,5-实时热销,6-实时收益,7-今日畅销,8-高佣榜单,默认1 + "limit": size, // 非必填, 请求数量;默认值 : 400 + "offset": page, // 非必填, 从多少位置开始请求;默认值 : 0,offset需是limit的整数倍,仅支持整页翻页 + //"list_id": "", // 非必填,翻页时建议填写前页返回的list_id值 + } + //fmt.Println(gid) + if id != "" { + args["channel_type"] = id + } + if gid != "" { + args["goods_ids"] = []string{gid} + args["channel_type"] = "3" + } + if cid != "" { + //20100-百货,20200-母婴,20300-食品,20400-女装,20500-电器,20600-鞋包,20700-内衣,20800-美妆,20900-男装,21000-水果,21100-家纺,21200-文具,21300-运动,21400-虚拟,21500-汽车,21600-家装,21700-家具,21800-医药; + args["cat_id"] = cid + args["channel_type"] = "4" + } + // fmt.Println(args) + data, err := send(args, method) + if err != nil { + return nil, err + } + // fmt.Println(string(data)) + r := new(PddRecommend) + if err := json.Unmarshal(data, &r); err != nil { + return nil, err + } + return r, nil +} + +// 爆款排行商品接口 +//func Hot() { +// method := "pdd.ddk.top.goods.list.query" +// args := map[string]interface{}{ +// "limit": 400, // 非必填, 请求数量;默认值 : 400 +// "offset": 400, // 非必填, 从多少位置开始请求;默认值 : 0,offset需是limit的整数倍,仅支持整页翻页 +// "sort_type": "", // 非必填, 1-实时热销榜;2-实时收益榜 +// } +//} diff --git a/tik_tok/svc_tik_tok_convert.go b/tik_tok/svc_tik_tok_convert.go index c9c78b2..dbcd3e3 100644 --- a/tik_tok/svc_tik_tok_convert.go +++ b/tik_tok/svc_tik_tok_convert.go @@ -180,3 +180,39 @@ func OwnTikTokUrl(tikTokBase *md.TikTokBase, tikTokArgs map[string]interface{}) H5Url: url["share_link"], }, nil } +func OwnTikTokActUrl(tikTokBase *md.TikTokBase, tikTokArgs map[string]interface{}) (*md.ConvertedUrls, error) { + args := map[string]string{ + "appkey": tikTokBase.ApiGoodsAppKey, + "appSecret": tikTokBase.ApiGoodsAppSecret, + "activity_id": zhios_third_party_utils.AnyToString(tikTokArgs["activity_id"]), + "mix_activity_id": zhios_third_party_utils.AnyToString(tikTokArgs["mix_activity_id"]), + "need_qr_code": zhios_third_party_utils.AnyToString(tikTokArgs["need_qr_code"]), + "external_info": zhios_third_party_utils.AnyToString(tikTokArgs["external_info"]), + "pid": tikTokBase.GoodsPid, + "acctoken": tikTokBase.GoodsAccessToken, + } + fmt.Println("抖音", args) + var url map[string]string + var err string + if tikTokBase.AuthSubjectType == "DouKe" { + args["material_id"] = zhios_third_party_utils.AnyToString(tikTokArgs["material_id"]) + url, err = DkActConvertUrl(args) + } else { + url, err = ActConvertUrl(args) + } + //url, err = tik_tok.ActConvertUrl(args) + + if err != "" { + return nil, errors.New(err) + } + content, _ := php2go.Base64Decode(url["content"]) + return &md.ConvertedUrls{ + URL: url["deeplink"], + ShortenURL: url["deeplink"], + NoOpenAppURL: url["deeplink"], + AppURL: url["deeplink"], + ClickUrl: url["deeplink"], + QrcodeUrl: url["qr_code"], + Content: content, + }, nil +} diff --git a/tik_tok/svc_tik_tok_goods.go b/tik_tok/svc_tik_tok_goods.go index 15cf9b5..1adf2d9 100644 --- a/tik_tok/svc_tik_tok_goods.go +++ b/tik_tok/svc_tik_tok_goods.go @@ -3,8 +3,10 @@ package tik_tok import ( "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md" zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/zhimeng" "encoding/json" "fmt" + "github.com/jinzhu/copier" "github.com/syyongx/php2go" "github.com/tidwall/gjson" "strings" @@ -280,3 +282,34 @@ func CommGoodsDetail(goods TikTokGoodsLm) TikTokGoods { return tmp } +func OwnTikTokGoodsKlNew(tikTokBase *md.TikTokBase, tikTokArgs map[string]interface{}) (*zhimeng.TikTokDetailData, error) { + args := map[string]string{ + "appkey": tikTokBase.ApiGoodsAppKey, + "appSecret": tikTokBase.ApiGoodsAppSecret, + "content": php2go.Base64Encode(tikTokArgs["content"].(string)), + "acctoken": tikTokBase.SysGoodsAccessToken, + } + for k, v := range args { + if v == "" { + args[k] = "" + } + } + var data = zhimeng.TikTokDetailData{} + goods := GetKlGoodsNew(args) + if goods.ActivityId != "" { + data.ActivityId = goods.ActivityId + return &data, nil + } + + if goods.GoodsID == "" { + return nil, nil + } + err := copier.Copy(&data, goods) + if err != nil { + return nil, nil + } + if zhios_third_party_utils.StrToFloat64(data.YhqPrice) > 0 { + data.Price = data.CostPrice + } + return &data, nil +} diff --git a/utils/open_platform.go b/utils/open_platform.go new file mode 100644 index 0000000..2a59b1d --- /dev/null +++ b/utils/open_platform.go @@ -0,0 +1,135 @@ +package zhios_third_party_utils + +import ( + "encoding/json" + "errors" + "fmt" + "sort" + "time" +) + +// 调用开放平台的封装 +type OpenPlatformReqClient struct { + AppKey string + AppSecret string + Method string + Version string + Timestamp string + Nonce string + Url string + Sign string + BizData map[string]interface{} + params map[string]string + ReturnData ReturnDataResp +} + +type ReturnDataResp struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data interface{} `json:"data"` +} + +func NewOpenPlatformReqClient(appKey, method, version, appSecret string, bizData map[string]interface{}) (*OpenPlatformReqClient, error) { + if appKey == "" || appSecret == "" || method == "" || version == "" { + return nil, errors.New("appKey,method,version not allow empty") + } + nowStr := AnyToString(time.Now().Unix()) + nonce := UUIDString() + return &OpenPlatformReqClient{ + AppKey: appKey, + AppSecret: appSecret, + Method: method, + Version: version, + Nonce: nonce, + Timestamp: nowStr, + params: map[string]string{"app_key": appKey, "method": method, "version": version, "timestamp": nowStr, "nonce": nonce}, + BizData: bizData, + }, nil +} + +func (client *OpenPlatformReqClient) CurlOpen() error { + if client.params == nil { + return errors.New("params not allow empty") + } + url := client.Url + "/api/open/gw" + fmt.Printf("%#v\n", string(Serialize(client.params))) + resp, err := CurlPost(url, Serialize(client.params), nil) + if err != nil { + return err + } + err = json.Unmarshal(resp, &client.ReturnData) + if err != nil { + return err + } + return nil +} + +/*func (client *OpenPlatformReqClient) CreateParams() *OpenPlatformReqClient { + client.params["timestamp"] = client.Timestamp + client.params["nonce"] = client.Nonce + //client.params["biz_data"] = SerializeStr(client.BizData) + return client +}*/ + +func (client *OpenPlatformReqClient) SetBizDataToParams() *OpenPlatformReqClient { + client.params["biz_data"] = SerializeStr(client.BizData) + return client +} + +func (client *OpenPlatformReqClient) SetParams(key, value string) *OpenPlatformReqClient { + client.params[key] = value + return client +} + +func (client *OpenPlatformReqClient) GetParams(key string) string { + return client.params[key] +} + +func (client *OpenPlatformReqClient) CreateSign() *OpenPlatformReqClient { + /*if client.BizData != nil { + for key := range client.BizData { + client.params[key] = AnyToString2(client.BizData[key]) + } + }*/ + var keys []string + for key := range client.params { + keys = append(keys, key) + } + sort.Strings(keys) + str := "" + for _, key := range keys { + str += fmt.Sprintf("%v=%v&", key, client.params[key]) + } + str = client.AppSecret + str[:len(str)-1] + client.AppSecret + fmt.Printf("sign: %s\n", str) + client.Sign = Md5(str) + client.params["sign"] = client.Sign + if client.BizData != nil { + for key := range client.BizData { + if _, ok := client.params[key]; ok { + delete(client.params, key) + } + } + } + return client +} + +func (client *OpenPlatformReqClient) VerifySign(sign string) bool { + if sign == "" || client.Sign == "" { + return false + } + if client.Sign == sign { + return true + } + return false +} + +func (client *OpenPlatformReqClient) ResetNonce() *OpenPlatformReqClient { + client.Nonce = UUIDString() + return client +} + +func (client *OpenPlatformReqClient) ResetTimestamp() *OpenPlatformReqClient { + client.Timestamp = AnyToString(time.Now().Unix()) + return client +} diff --git a/utils/string.go b/utils/string.go index 585b55a..59a52ac 100644 --- a/utils/string.go +++ b/utils/string.go @@ -5,9 +5,12 @@ import ( "github.com/syyongx/php2go" "math/rand" "reflect" + "regexp" "sort" "strings" "time" + "unicode" + "unicode/utf8" ) func Implode(glue string, args ...interface{}) string { @@ -36,6 +39,43 @@ func InArrToInt(target int, str_array []int) bool { return false } +//是否有中文 +func IsChineseChar(str string) bool { + for _, r := range str { + if unicode.Is(unicode.Scripts["Han"], r) || (regexp.MustCompile("[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]").MatchString(string(r))) { + return true + } + } + return false +} + +func FilterEmoji(content string) string { + new_content := "" + for _, value := range content { + _, size := utf8.DecodeRuneInString(string(value)) + if size <= 3 { + new_content += string(value) + } + } + return new_content +} +func IsAllChinese(str string) bool { + str = FilterEmoji(str) + + arr := []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "/", ":"} + for _, v := range arr { + str = strings.ReplaceAll(str, v, "") + } + strNew := str + for _, c := range strNew { + if !unicode.Is(unicode.Scripts["Han"], c) { + return false + } + } + return true + +} + //把数组的值放到key里 func ArrayColumn(array interface{}, key string) (result map[string]interface{}, err error) { result = make(map[string]interface{}) diff --git a/zhimeng/kuaishou_goods.go b/zhimeng/kuaishou_goods.go index b14a095..c8ee232 100644 --- a/zhimeng/kuaishou_goods.go +++ b/zhimeng/kuaishou_goods.go @@ -56,3 +56,39 @@ func KuaiShouGoods(tikTokArgs map[string]interface{}) []map[string]string { } return goods } +func KuaiShouKlGoods(tikTokArgs map[string]interface{}) (*TikTokDetailData, error) { + args := map[string]interface{}{ + "appkey": tikTokArgs["appkey"], + "secret_key": tikTokArgs["secret_key"], + "content": tikTokArgs["content"], + } + resp, err := Send("kuaishou", "getKlGoods", args) + if err != nil { + return nil, err + } + var tmp struct { + Data TikTokDetailData `json:"data"` + } + if err = json.Unmarshal(resp, &tmp); err != nil { + return nil, err + } + return &tmp.Data, nil +} +func KuaiShouDetail(tikTokArgs map[string]interface{}) (*TikTokDetailData, error) { + args := map[string]interface{}{ + "appkey": tikTokArgs["appkey"], + "secret_key": tikTokArgs["secret_key"], + "id": tikTokArgs["gid"], + } + resp, err := Send("kuaishou", "getGoodsDetail", args) + if err != nil { + return nil, err + } + var tmp struct { + Data TikTokDetailData `json:"data"` + } + if err = json.Unmarshal(resp, &tmp); err != nil { + return nil, err + } + return &tmp.Data, nil +} diff --git a/zhimeng/pdd_convert_url.go b/zhimeng/pdd_convert_url.go index 24fd93c..3ba80cd 100644 --- a/zhimeng/pdd_convert_url.go +++ b/zhimeng/pdd_convert_url.go @@ -2,6 +2,7 @@ package zhimeng import ( "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md" + zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" "encoding/json" "fmt" ) @@ -48,3 +49,118 @@ func PDDConvertUrl(ak, sk, itemId, promoId, couponPrice, isWxMini, isBindUrl, is CommissionRate: couponPrice, }, nil } + +//生成多多进宝频道推广 +func PDDActivityConvertUrl(ak, sk, resourceType, pid, promoId, url string, isShare int) (*md.ConvertedUrls, error) { + args := map[string]interface{}{ + "appkey": ak, + "secret_key": sk, + "resource_type": resourceType, + "pid": pid, + "url": url, + "custom_parameters": promoId, + "is_share": zhios_third_party_utils.IntToStr(isShare), + } + //generate_authority_url_onoff 0不会调授权链接 1会先跳授权链接 + fmt.Println("拼多多:", args) + + resp, err := Send("pdd", "get_main_theme_url", args) + if err != nil { + return nil, err + } + var tmp struct { + Data struct { + URL string `json:"url"` + OpenAppURL string `json:"open_app_url"` + NoOpenAppURL string `json:"no_open_app_url"` + SchemaURL string `json:"schema_url"` + PagePath string `json:"page_path"` + } `json:"data"` + } + if err = json.Unmarshal(resp, &tmp); err != nil { + return nil, err + } + return &md.ConvertedUrls{ + URL: tmp.Data.URL, + ShortenURL: tmp.Data.NoOpenAppURL, + NoOpenAppURL: tmp.Data.OpenAppURL, + AppURL: tmp.Data.SchemaURL, + WeChatMiniURL: tmp.Data.PagePath, + }, nil +} + +//生成商城-频道推广链接 +func PDDActivityStoreConvertUrl(ak, sk, resourceType, pid, promoId, url string, isShare int) (*md.ConvertedUrls, error) { + args := map[string]interface{}{ + "appkey": ak, + "secret_key": sk, + "channel_type": resourceType, + "pid": pid, + "custom_parameters": promoId, + "is_share": zhios_third_party_utils.IntToStr(isShare), + } + //generate_authority_url_onoff 0不会调授权链接 1会先跳授权链接 + fmt.Println("拼多多:", args) + + resp, err := Send("pdd", "get_prom_url", args) + if err != nil { + return nil, err + } + var tmp struct { + Data struct { + URL string `json:"url"` + OpenAppURL string `json:"open_app_url"` + NoOpenAppURL string `json:"no_open_app_url"` + SchemaURL string `json:"schema_url"` + PagePath string `json:"page_path"` + } `json:"data"` + } + if err = json.Unmarshal(resp, &tmp); err != nil { + return nil, err + } + return &md.ConvertedUrls{ + URL: tmp.Data.URL, + ShortenURL: tmp.Data.NoOpenAppURL, + NoOpenAppURL: tmp.Data.OpenAppURL, + AppURL: tmp.Data.SchemaURL, + WeChatMiniURL: tmp.Data.PagePath, + }, nil +} + +//生成营销工具推广链接 +func PDDActivitySaleConvertUrl(ak, sk, resourceType, pid, promoId, url string, isShare int) (*md.ConvertedUrls, error) { + args := map[string]interface{}{ + "appkey": ak, + "secret_key": sk, + "channel_type": resourceType, + "pid": pid, + "custom_parameters": promoId, + "is_share": zhios_third_party_utils.IntToStr(isShare), + } + //generate_authority_url_onoff 0不会调授权链接 1会先跳授权链接 + fmt.Println("拼多多:", args) + + resp, err := Send("pdd", "get_rp_url", args) + if err != nil { + return nil, err + } + var tmp struct { + Data struct { + URL string `json:"url"` + OpenAppURL string `json:"open_app_url"` + NoOpenAppURL string `json:"no_open_app_url"` + SchemaURL string `json:"schema_url"` + PagePath string `json:"page_path"` + } `json:"data"` + } + if err = json.Unmarshal(resp, &tmp); err != nil { + return nil, err + } + return &md.ConvertedUrls{ + URL: tmp.Data.URL, + ShortenURL: tmp.Data.NoOpenAppURL, + NoOpenAppURL: tmp.Data.OpenAppURL, + AppURL: tmp.Data.SchemaURL, + WeChatMiniURL: tmp.Data.PagePath, + }, nil +} diff --git a/zhimeng/tik_tok_goods.go b/zhimeng/tik_tok_goods.go index 43bacec..b35dc70 100644 --- a/zhimeng/tik_tok_goods.go +++ b/zhimeng/tik_tok_goods.go @@ -62,6 +62,7 @@ type TikTokDetailData struct { Imgs []string `json:"imgs"` DetailImgs []string `json:"detail_imgs"` ShopTotalScore interface{} `json:"shop_total_score"` + ActivityId string `json:"activity_id"` } type ShopTotalScore struct { LogisticsScore struct { diff --git a/zhimeng/word_parse.go b/zhimeng/word_parse.go new file mode 100644 index 0000000..3c3cc5a --- /dev/null +++ b/zhimeng/word_parse.go @@ -0,0 +1,54 @@ +package zhimeng + +import ( + zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" + "encoding/json" + "errors" +) + +// 搜索提示关键字 +func SearchTips(s string) ([]string, error) { + res, err := Send("tb_keyword", "index", map[string]interface{}{"keyword": s}) + if err != nil { + return nil, err + } + tmp := struct { + Success int `json:"success,omitempty"` + Msg string `json:"msg,omitempty"` + Data []string `json:"data,omitempty"` + }{} + err = json.Unmarshal(res, &tmp) + if err != nil { + return nil, err + } + if tmp.Success != StatusSuc { + return nil, errors.New(tmp.Msg) + } + return tmp.Data, nil +} + +// 解析淘口令, 成功返回产品goods_ID,失败返回空字符串 +func WordParse(ak, sk, pid, s, sid, tbAppKey string) struct { + Gid string `json:"gid"` +} { + resp, err := Send("agent_tb", "tkl_gid", map[string]interface{}{ + "appkey": ak, + "secret_key": sk, + "session": sid, + "keyword": s, + "pid": pid, + "tb_app_key": tbAppKey, + }) + if err != nil { + return struct { + Gid string `json:"gid"` + }{} + } + var tmp struct { + Data struct { + Gid string `json:"gid"` + } `json:"data"` + } + zhios_third_party_utils.Unserialize(resp, &tmp) + return tmp.Data +}