diff --git a/chain_transfer/chain_transfer.go b/chain_transfer/chain_transfer.go index 2c8cb97..3fb73d6 100644 --- a/chain_transfer/chain_transfer.go +++ b/chain_transfer/chain_transfer.go @@ -46,6 +46,8 @@ func ChainTransfer(eg *xorm.Engine, officialEg, zhimengEg *xorm.Engine, args map } args["acc_jd_share_id"] = userProfile.AccJdCloudId args["acc_pdd_self_id"] = userProfile.AccPddSelfId + args["acc_vip_self_id"] = userProfile.AccVipShareId + } switch args["provider"] { case md.PVD_TB, md.PVD_TM: diff --git a/chain_transfer/svc/svc_turnchain.go b/chain_transfer/svc/svc_turnchain.go index 75cbb86..7f08560 100644 --- a/chain_transfer/svc/svc_turnchain.go +++ b/chain_transfer/svc/svc_turnchain.go @@ -13,6 +13,7 @@ import ( "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/vip" "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/zhimeng" "encoding/json" "errors" @@ -53,6 +54,7 @@ func TurnChainFeatures(eg *xorm.Engine, officialEg, zhimengEg *xorm.Engine, tikT } tikTokBase["acc_jd_share_id"] = userProfile.AccJdCloudId tikTokBase["acc_pdd_self_id"] = userProfile.AccPddSelfId + tikTokBase["acc_vip_self_id"] = userProfile.AccVipShareId } tikTokBase["uid"] = zhios_third_party_utils.IntToStr(user.Uid) tikTokBase["gid"] = goodsId @@ -74,6 +76,8 @@ func TurnChainFeatures(eg *xorm.Engine, officialEg, zhimengEg *xorm.Engine, tikT case md.PVD_PDD: urls, err = PDDTurnChain(eg, dbName, tikTokBase) + case md.PVD_VIP: + urls, err = VipTurnChain(eg, dbName, tikTokBase) default: return nil, errors.New("失败") } @@ -145,6 +149,40 @@ func JDTurnChain(eg *xorm.Engine, dbName string, args map[string]string) (*md.Co } return urls, nil } +func VipTurnChain(eg *xorm.Engine, dbName string, args map[string]string) (*md.ConvertedUrls, error) { + // 初始化vip配置 + pid := args["acc_vip_share_id"] + openId := pid + pidType := "cloud" + auth, _ := db.SysUnionByPVDByUse(eg, dbName, "vip") + unionType := "" + if auth != nil { + if auth.AuthType == 2 { + pid = zhimeng.GetWphPid(zhios_third_party_utils.StrToInt(args["uid"]), pidType, dbName) + openId = pid + } + unionType = zhios_third_party_utils.IntToStr(auth.AuthType) + } + var urls *md.ConvertedUrls + var err error + if unionType == "2" { + urls, err = zhimeng.OwnWphConvertUrl(auth, + args["gid"], + pid, + "", "vendoapi", openId, "1") + } else { + urls, err = zhimeng.VipConvertUrl( + db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_AK), + db.SysCfgGetWithDb(eg, dbName, md.KEY_CFG_ZM_SK), + args["gid"], + pid, + "", "vendoapi", openId, "1") + } + if err != nil { + return nil, err + } + return urls, nil +} // pdd转链 func PDDTurnChain(eg *xorm.Engine, dbName string, args map[string]string) (*md.ConvertedUrls, error) { @@ -382,23 +420,38 @@ func ConvertUrl(eg *xorm.Engine, officialEg, zhimengEg *xorm.Engine, args map[st } 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") + union, _ := db.SysUnionByPVDByUse(eg, args["master_id"], "vip") + authType := "0" + if union != nil && union.AuthType == 2 { + pid = "own_cloud_" + args["master_id"] + "_" + args["uid"] + authType = "2" + openId = pid + } + if authType == "2" { + urls, err = zhimeng.OwnWphConvertUrl(union, args["gid"], + pid, + "", "vendoapi", openId, "1") + } else { + 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.VipConvertUrl( + thirdZmAppKeyData.Val, + thirdZmAppSecretData.Val, + args["gid"], + pid, + "", "vendoapi", openId, "1") + } + case md.PVD_PDD: pid := args["acc_pdd_self_id"] union, _ := db.SysUnionByPVDByUse(eg, args["master_id"], "pdd") @@ -843,6 +896,8 @@ func FindTaobaoWord(eg *xorm.Engine, officialEg, zhimengEg *xorm.Engine, tmp map } goodsParam["acc_jd_share_id"] = userProfile.AccJdCloudId goodsParam["acc_pdd_self_id"] = userProfile.AccPddSelfId + goodsParam["acc_vip_self_id"] = userProfile.AccVipShareId + } //判断如果是有纯字母 字母+数字的内容 并且没有链接的 都调淘宝接口 split := regexp.MustCompile("[a-zA-Z0-9]{9,14}").FindAllString(reqCount, -1) @@ -1165,6 +1220,8 @@ func CheckKuaishouWord(eg *xorm.Engine, officialEg, zhimengEg *xorm.Engine, dbNa } args["acc_jd_share_id"] = userProfile.AccJdCloudId args["acc_pdd_self_id"] = userProfile.AccPddSelfId + args["acc_vip_self_id"] = userProfile.AccVipShareId + } args["gid"] = itemData.GoodsID args["master_id"] = dbName @@ -1225,7 +1282,13 @@ func ProcessTurnChainByGoodsId(eg *xorm.Engine, officialEg *xorm.Engine, tmp map } else { return } - + case md.PVD_VIP: + vipResponse, vipProvider := VIPByGoodsID(eg, officialEg, tmp, goodsId, url, mdData) + if vipResponse != nil && vipProvider != "" { + return vipResponse, vipProvider, "", "", "", "", "", mdData + } else { + return + } case md.PVD_PDD: pddResponse, pddProvider := PDDByGoodsId(eg, officialEg, tmp, goodsId, url, mdData) if pddResponse != nil && pddProvider != "" { @@ -1458,6 +1521,90 @@ func PDDByGoodsId(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]strin return nil, "" } +func VIPByGoodsID(eg *xorm.Engine, officialEg *xorm.Engine, tmp map[string]string, goodsId, url string, mdData *md.MoreDetailResponse) (*md.ProductDetailResponse, string) { + postData := make(map[string]interface{}) + union, _ := db.SysUnionByPVDByUse(eg, tmp["master_id"], "vip") + if zhios_third_party_utils.StrToInt(goodsId) > 0 { + postData["gid"] = goodsId + } else { + postData1 := make(map[string]interface{}) + postData1["url"] = url + 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) + + if union != nil { + if union.AuthType == 2 { + uid := zhios_third_party_utils.StrToInt(tmp["uid"]) + postData["pid"] = zhimeng.GetWphPid(uid, "self", tmp["master_id"]) + postData["openId"] = postData["pid"] + } + postData["union_type"] = zhios_third_party_utils.IntToStr(union.AuthType) + } + if postData["union_type"] == "2" { + gid := zhimeng.OwnWphParseUrl(union, url) + postData["gid"] = gid + } else { + //改 + vipData1, err1 := vip.NewZhiMengVIPSDK(). + SelectFunction("parse_url"). + WithArgs(postData1). + Result() + if err1 != nil || vipData1 == nil { + //e.OutErr(c, e.ERR_API_RESPONSE, e.NewErr(400, "商品已下架")) + return nil, "" + } + stringInterface := vipData1.VipToMapStringInterface() + postData["gid"] = stringInterface["gid"] + } + } + 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) + postData["realCall"] = "1" + postData["openId"] = "default_open_id" + postData["pid"] = "default_pid" + if tmp["acc_vip_self_id"] != "" { + postData["openId"] = strings.ReplaceAll(tmp["acc_vip_self_id"], "self_", "") + postData["pid"] = tmp["acc_vip_self_id"] + } + if union != nil { + if union.AuthType == 2 { + uid := zhios_third_party_utils.StrToInt(tmp["uid"]) + postData["pid"] = zhimeng.GetWphPid(uid, "self", tmp["master_id"]) + postData["openId"] = postData["pid"] + } + postData["union_type"] = zhios_third_party_utils.IntToStr(union.AuthType) + } + if postData["union_type"] == "2" { + slist := zhimeng.OwnWphDetail(union, postData) + err := zhimeng.OwnPddToStruct(slist, mdData) + if err != nil { + return nil, "" + } + } else { + //改 + vipData, err := vip.NewZhiMengVIPSDK(). + SelectFunction("goods_info"). + WithArgs(postData). + Result() + if err != nil || vipData == nil { + //e.OutErr(c, e.ERR_API_RESPONSE, e.NewErr(400, "商品已下架")) + return nil, "" + } + // to struct + err = vipData.ToObject().ToStruct(mdData) + if err != nil { + //e.OutErr(c, e.ERR_INVALID_ARGS, err) + return nil, "" + } + } + if mdData != nil { + // to response + r := &md.ProductDetailResponse{} + r.GoodID = mdData.GID + return r, md.PVD_VIP + } + 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 ( diff --git a/chain_transfer/turn_chain.go b/chain_transfer/turn_chain.go index 57bb35c..e3bab5d 100644 --- a/chain_transfer/turn_chain.go +++ b/chain_transfer/turn_chain.go @@ -45,12 +45,17 @@ func TurnChain(eg *xorm.Engine, officialEg, zhimengEg *xorm.Engine, args map[str } args["acc_jd_share_id"] = userProfile.AccJdCloudId args["acc_pdd_self_id"] = userProfile.AccPddSelfId + args["acc_vip_self_id"] = userProfile.AccVipShareId + } //1、识别出对应平台的口令或链接 reqCount := args["content"] if reqCount == "" { return tcPrase } + if strings.Contains(reqCount, "http") == false { + reqCount = strings.ReplaceAll(reqCount, "p.pinduoduo.com", "https://p.pinduoduo.com") + } reqCount = strings.ReplaceAll(reqCount, "\n¥", "¥") reqCount = strings.ReplaceAll(reqCount, "http", "\nhttp") reqCounts := reqCount @@ -68,6 +73,7 @@ func TurnChain(eg *xorm.Engine, officialEg, zhimengEg *xorm.Engine, args map[str } } reqCount = reqCounts + findAllUrl := xurls.Strict.FindAllString(reqCount, -1) var pvd, goodsId, tklWord string reg1 := regexp.MustCompile(`¥.*?¥`) diff --git a/vip/vip_zhimeng.go b/vip/vip_zhimeng.go new file mode 100644 index 0000000..c0bf28a --- /dev/null +++ b/vip/vip_zhimeng.go @@ -0,0 +1,10 @@ +package vip + +import "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/zhimeng" + +// NewZhiMengVIPSDK is constructor +func NewZhiMengVIPSDK() *zhimeng.SDK { + vip := &zhimeng.SDK{} + vip.Init("wph_new") + return vip +} diff --git a/zhimeng/own_wph_goods.go b/zhimeng/own_wph_goods.go new file mode 100644 index 0000000..0667750 --- /dev/null +++ b/zhimeng/own_wph_goods.go @@ -0,0 +1,68 @@ +package zhimeng + +import ( + "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/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/wph" + "encoding/json" + "github.com/syyongx/php2go" + "github.com/tidwall/gjson" + "time" +) + +func GetWphPid(uid int, shareType, dbName string) string { + newpid := "own_" + shareType + "_" + dbName + "_0" + if uid > 0 { + newpid = "own_" + shareType + "_" + dbName + "_" + zhios_third_party_utils.IntToStr(uid) + } + return newpid + +} +func OwnWphToStruct(data string, r *md.MoreDetailResponse) error { + + if err := json.Unmarshal([]byte(data), r); err != nil { + return err + } + return nil +} +func OwnWphDetail(auth *model.SysUnionSet, postData map[string]interface{}) string { + serviceParam := CommWph(auth) + realCall := "false" + if postData["realCall"] == "1" { + realCall = "true" + } + serviceParam["token"] = gjson.Get(auth.KeyData, "accessToken").String() + paramData := map[string]interface{}{ + "goodsIdList": []string{zhios_third_party_utils.AnyToString(postData["gid"])}, + "requestId": serviceParam["uuid"] + zhios_third_party_utils.Int64ToStr(time.Now().Unix()) + zhios_third_party_utils.IntToStr(php2go.Rand(1000, 9999)), + "request": map[string]string{ + "realCall": realCall, + "openId": zhios_third_party_utils.AnyToString(postData["openId"]), + }, + "chanTag": zhios_third_party_utils.AnyToString(postData["pid"]), + } + param := zhios_third_party_utils.SerializeStr(paramData) + res1 := wph.GetByGoodsIdsWithOauth(serviceParam, param) + if len(res1) > 0 { + return zhios_third_party_utils.SerializeStr(res1[0]) + + } + return "" + +} + +func OwnWphParseUrl(auth *model.SysUnionSet, content string) string { + serviceParam := CommWph(auth) + serviceParam["token"] = gjson.Get(auth.KeyData, "accessToken").String() + paramData := map[string]interface{}{ + "vipLinkCheckReq": map[string]string{ + "source": "唯品会", + "content": content, + }, + } + param := zhios_third_party_utils.SerializeStr(paramData) + res1 := wph.GetParseUrl(serviceParam, param) + return zhios_third_party_utils.AnyToString(res1["goodsId"]) + +} diff --git a/zhimeng/vip_convert_url.go b/zhimeng/vip_convert_url.go index 5d64ef9..3ab0169 100644 --- a/zhimeng/vip_convert_url.go +++ b/zhimeng/vip_convert_url.go @@ -1,10 +1,63 @@ package zhimeng import ( + "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/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/wph" "encoding/json" + "errors" + "github.com/syyongx/php2go" + "github.com/tidwall/gjson" + "time" ) +func CommWph(auth *model.SysUnionSet) map[string]string { + serviceParam := map[string]string{ + "token": "", + "uuid": "353543142", + "key": "8f8c427e", + "secret": "DB9C5A92480618101A15835DD9E8AF69", + } + if auth != nil { + serviceParam["token"] = gjson.Get(auth.KeyData, "accessToken").String() + } + return serviceParam +} + +func OwnWphConvertUrl(auth *model.SysUnionSet, itemId, pid, couponPrice, adCode, openId, realCall string) (*md.ConvertedUrls, error) { + urlGenByGoodsIdRequest := map[string]string{ + "realCall": "false", + "openId": openId, + "adCode": adCode, + } + if realCall == "1" { + urlGenByGoodsIdRequest["realCall"] = "true" + } + serviceParam := CommWph(auth) + paramData := map[string]interface{}{ + "goodsIdList": []string{itemId}, + "requestId": serviceParam["uuid"] + zhios_third_party_utils.Int64ToStr(time.Now().Unix()) + zhios_third_party_utils.IntToStr(php2go.Rand(1000, 9999)), + "urlGenByGoodsIdRequest": urlGenByGoodsIdRequest, + "chanTag": pid, + } + param := zhios_third_party_utils.SerializeStr(paramData) + url := wph.GetUrl(serviceParam, param) + if url.Url == "" { + return nil, errors.New("转链失败") + } + return &md.ConvertedUrls{ + ItemId: itemId, + URL: url.Url, + ShortenURL: url.Url, + NoOpenAppURL: url.Url, + AppURL: url.DeeplinkUrl, + HasCoupon: false, + CommissionRate: couponPrice, + WeChatMiniURL: url.VipWxUrl, + }, nil +} + // todo func VipConvertUrl(ak, sk, itemId, pid, couponPrice, adCode, openId, realCall string) (*md.ConvertedUrls, error) { args := map[string]interface{}{