From 0217acf694ba7f916735b203e030013092a894aa Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Mon, 14 Oct 2024 17:24:19 +0800 Subject: [PATCH] 1 --- jd_union/api.go | 2 + kuaishou/kuaishou.go | 25 +++++---- sms/agent_api.go | 8 +-- taobao/search_list.go | 56 +++++++++++++++++---- utils/crypto.go | 114 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 180 insertions(+), 25 deletions(-) create mode 100644 utils/crypto.go diff --git a/jd_union/api.go b/jd_union/api.go index 3ef13bb..7a0b6de 100644 --- a/jd_union/api.go +++ b/jd_union/api.go @@ -2,6 +2,7 @@ package jd_union import ( zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" + "fmt" "github.com/syyongx/php2go" "sort" "strings" @@ -77,5 +78,6 @@ func SendGet(keyArr map[string]string, method, paramJson, version string) (strin } } post, err := zhios_third_party_utils.CurlGet(url, nil) + fmt.Println(string(post)) return string(post), err } diff --git a/kuaishou/kuaishou.go b/kuaishou/kuaishou.go index 56cd8fd..95bf441 100644 --- a/kuaishou/kuaishou.go +++ b/kuaishou/kuaishou.go @@ -32,7 +32,6 @@ func GetKuaishouToken(args map[string]string) (string, error) { } /* - */ func GetKuaishouRefreshToken(args map[string]string) (string, error) { url := "https://openapi.kwaixiaodian.com/oauth2/refresh_token" @@ -43,49 +42,53 @@ func GetKuaishouRefreshToken(args map[string]string) (string, error) { return string(get), err } -//https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.investment.activity.open.list&version=1 +// https://open.kwaixiaodian.com/zone/new/docs/api?name=open.distribution.selection.offline&version=1 +func GetKuishouSelectionPickOffline(signSecret string, param map[string]string) (string, error) { + return SendPost("open.distribution.selection.offline", signSecret, param) +} + +// https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.investment.activity.open.list&version=1 func GetKuishouActivity(signSecret string, param map[string]string) (string, error) { return SendGet("open.distribution.investment.activity.open.list", signSecret, param) } -//https://open.kwaixiaodian.com/zone/new/docs/api?name=open.distribution.investment.activity.item.detail&version=1 +// https://open.kwaixiaodian.com/zone/new/docs/api?name=open.distribution.investment.activity.item.detail&version=1 func GetKuishouGoodsDetail(signSecret string, param map[string]string) (string, error) { return SendGet("open.distribution.investment.activity.item.detail", signSecret, param) } -//https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.investment.activity.open.list&version=1 +// https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.investment.activity.open.list&version=1 func GetKuishouGoods(signSecret string, param map[string]string) (string, error) { return SendGet("open.distribution.investment.activity.open.item.list", signSecret, param) } -////https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.second.apply.investment.activity.list&version=1 +// //https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.second.apply.investment.activity.list&version=1 func GetKuishouMyActivity(signSecret string, param map[string]string) (string, error) { return SendGet("open.distribution.second.apply.investment.activity.list", signSecret, param) } -// -////https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.second.apply.investment.activity.item.list&version=1 +// //https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.second.apply.investment.activity.item.list&version=1 func GetKuishouMyGoods(signSecret string, param map[string]string) (string, error) { return SendGet("open.distribution.second.apply.investment.activity.item.list", signSecret, param) } -//https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.cps.leader.order.cursor.list&version=1 +// https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.cps.leader.order.cursor.list&version=1 func GetKuishouOrder(signSecret string, param map[string]string) (string, error) { return SendGet("open.distribution.cps.leader.order.cursor.list", signSecret, param) } //https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.cps.leader.order.detail&version=1 -//https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.selection.pick&version=1 橱窗 +// https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.selection.pick&version=1 橱窗 func GetKuishouSelectionPick(signSecret string, param map[string]string) (string, error) { return SendPost("open.distribution.selection.pick", signSecret, param) } -//https://open.kwaixiaodian.com/zone/docs/api?name=open.user.info.get&version=1 用户信息 +// https://open.kwaixiaodian.com/zone/docs/api?name=open.user.info.get&version=1 用户信息 func GetKuishouUser(signSecret string, param map[string]string) (string, error) { return SendGet("open.user.info.get", signSecret, param) } @@ -93,7 +96,7 @@ func GetKuishouOrderDetail(signSecret string, param map[string]string) (string, return SendGet("open.distribution.cps.leader.order.detail", signSecret, param) } -//https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.cps.kwaimoney.selection.item.list&version=1 +// https://open.kwaixiaodian.com/zone/docs/api?name=open.distribution.cps.kwaimoney.selection.item.list&version=1 func GetKuishouCpsGoods(signSecret string, param map[string]string) (string, error) { return SendGet("open.distribution.cps.kwaimoney.selection.item.list", signSecret, param) } diff --git a/sms/agent_api.go b/sms/agent_api.go index 50b7fcc..2ce6d39 100644 --- a/sms/agent_api.go +++ b/sms/agent_api.go @@ -14,7 +14,7 @@ import ( "xorm.io/xorm" ) -//短信数量 +// 短信数量 func AgentSmsNumGetSmsNum(engine *xorm.Engine, smsType, uid interface{}) int { numData := offical.GetAgentSmsNum(engine, smsType, uid) num := 0 @@ -27,7 +27,7 @@ func AgentSmsNumGetSmsNum(engine *xorm.Engine, smsType, uid interface{}) int { return num } -//发送短信 +// 发送短信 func AgentSmsSend(engine *xorm.Engine, args map[string]interface{}) error { num := AgentSmsNumGetSmsNum(engine, args["sms_type"], args["uid"]) ex := strings.Split(args["mobile"].(string), ",") @@ -43,7 +43,7 @@ func AgentSmsSend(engine *xorm.Engine, args map[string]interface{}) error { return errors.New("短信不足") } if args["type"] != "mob" { //联江短信数量 - send, err := SmsApiSend(engine, "api.v1.accountNum", map[string]interface{}{}) + send, err := SmsApiSend(engine, "v1.accountNum", map[string]interface{}{}) if err != nil { return err } @@ -92,7 +92,7 @@ func AgentSmsSend(engine *xorm.Engine, args map[string]interface{}) error { return errors.New(msg) } } else { - send, err = SmsApiSend(engine, "api.v1.sms", where) + send, err = SmsApiSend(engine, "v1.sms", where) if err != nil { return err } diff --git a/taobao/search_list.go b/taobao/search_list.go index 083f05c..b908f6b 100644 --- a/taobao/search_list.go +++ b/taobao/search_list.go @@ -1,11 +1,14 @@ package taobao import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/e" "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" "github.com/jinzhu/copier" + "strings" + "time" ) // 淘宝物料 @@ -80,7 +83,7 @@ type NewMarterial struct { SubTitle string `json:"sub_title"` Title string `json:"title"` UserType int `json:"user_type"` - Volume int `json:"volume"` + Volume string `json:"annual_vol"` TkTotalSales string `json:"tk_total_sales"` WhiteImage string `json:"white_image"` SmallImages struct { @@ -256,21 +259,54 @@ func (t *TB) SearchList(args map[string]string) (*[]Material, error) { resp, err := t.GetList(args, "") //如果是跟随官方 结构不一样 if t.AuthType == 1 { - var tmp scMaterialOptionalStruct + var tmp scTbkScMaterialOptionalUpgradeResponse if err = json.Unmarshal(resp, &tmp); err != nil { return nil, err } - if len(tmp.TbkScMaterialOptionalResponse.ResultList.MapData) == 0 { - return nil, err + if len(tmp.TbkScMaterialOptionalUpgradeResponse.ResultList.MapData) == 0 { + return nil, e.NewErr(400, "获取失败") } - data := tmp.TbkScMaterialOptionalResponse.ResultList.MapData - for k, v := range data { - itemID, ok := v.ItemID.(float64) - if ok { - data[k].ItemID = int64(itemID) + data := tmp.TbkScMaterialOptionalUpgradeResponse.ResultList.MapData + list := make([]Material, 0) + for _, v := range data { + if strings.Contains(v.ItemBasicInfo.Volume, "万+") { + v.ItemBasicInfo.Volume = zhios_third_party_utils.IntToStr(zhios_third_party_utils.StrToInt(strings.ReplaceAll(v.ItemBasicInfo.Volume, "万+", "")) * 10000) + } + v.ItemBasicInfo.Volume = strings.ReplaceAll(v.ItemBasicInfo.Volume, "+", "") + + tmp1 := Material{ + CategoryID: v.ItemBasicInfo.CategoryId, + CategoryName: v.ItemBasicInfo.CategoryName, + CommissionRate: zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(v.PublishInfo.IncomeRate) * 100), + ItemID: v.ItemId, + Nick: v.ItemBasicInfo.ShopTitle, + PictURL: v.ItemBasicInfo.PictUrl, + SellerID: int(v.ItemBasicInfo.SellerId), + ShopTitle: v.ItemBasicInfo.ShopTitle, + ShortTitle: v.ItemBasicInfo.ShortTitle, + Title: v.ItemBasicInfo.Title, + ZkFinalPrice: v.PricePromotionInfo.ZkFinalPrice, + ReservePrice: v.PricePromotionInfo.ReservePrice, + Volume: zhios_third_party_utils.StrToInt(v.ItemBasicInfo.Volume), } + tmp1.SmallImages.String = []string{tmp1.PictURL} + + if zhios_third_party_utils.StrToFloat64(v.PricePromotionInfo.FinalPromotionPrice) > 0 { + for _, v1 := range v.PricePromotionInfo.FinalPromotionPathList.FinalPromotionPathMapData { + tmp1.CouponAmount = zhios_third_party_utils.Float64ToStrByPrec(zhios_third_party_utils.StrToFloat64(v1.PromotionFee)+zhios_third_party_utils.StrToFloat64(tmp1.CouponAmount), 2) + tmp1.CouponStartTime = zhios_third_party_utils.IntToStr(zhios_third_party_utils.StrToInt(v1.PromotionStartTime) / 1000) + tmp1.CouponEndTime = zhios_third_party_utils.IntToStr(zhios_third_party_utils.StrToInt(v1.PromotionEndTime) / 1000) + tmp1.CouponID = v1.PromotionId + if v1.PromotionTitle == "商品券" || v1.PromotionTitle == "店铺券" { + if zhios_third_party_utils.StrToInt64(v1.PromotionEndTime)/1000 > time.Now().Unix() { + tmp1.GoodsCoupon = "1" + } + } + } + } + list = append(list, tmp1) } - return &data, nil + return &list, nil } else { var tmp wrapperStruct if err = json.Unmarshal(resp, &tmp); err != nil { diff --git a/utils/crypto.go b/utils/crypto.go new file mode 100644 index 0000000..cb88af5 --- /dev/null +++ b/utils/crypto.go @@ -0,0 +1,114 @@ +package zhios_third_party_utils + +import ( + "bytes" + "crypto/aes" + "crypto/cipher" + "crypto/rand" + "crypto/sha1" + "encoding/hex" + "errors" + "io" + "sort" + "strings" +) + +const pkcs7blocksize = 32 + +// pkcs7encode 对需要加密的明文进行填充补位 +// plaintext 需要进行填充补位操作的明文 +// 返回补齐明文字符串 +func pkcs7encode(plaintext []byte) []byte { + //计算需要填充的位数 + pad := pkcs7blocksize - len(plaintext)%pkcs7blocksize + if pad == 0 { + pad = pkcs7blocksize + } + + //获得补位所用的字符 + text := bytes.Repeat([]byte{byte(pad)}, pad) + + return append(plaintext, text...) +} + +// pkcs7decode 对解密后的明文进行补位删除 +// plaintext 解密后的明文 +// 返回删除填充补位后的明文和 +func pkcs7decode(plaintext []byte) []byte { + ln := len(plaintext) + + // 获取最后一个字符的 ASCII + pad := int(plaintext[ln-1]) + if pad < 1 || pad > pkcs7blocksize { + pad = 0 + } + + return plaintext[:(ln - pad)] +} + +// 对加密数据包进行签名校验,确保数据的完整性。 +func validateSignature(signature string, parts ...string) bool { + return signature == createSignature(parts...) +} + +// 校验用户数据数据 +func validateUserInfo(signature, rawData, ssk string) bool { + raw := sha1.Sum([]byte(rawData + ssk)) + return signature == hex.EncodeToString(raw[:]) +} + +// 拼凑签名 +func createSignature(parts ...string) string { + sort.Strings(parts) + raw := sha1.Sum([]byte(strings.Join(parts, ""))) + + return hex.EncodeToString(raw[:]) +} + +// cbcEncrypt CBC 加密数据 +func cbcEncrypt(key, plaintext, iv []byte) ([]byte, error) { + if len(plaintext)%aes.BlockSize != 0 { + return nil, errors.New("plaintext is not a multiple of the block size") + } + + block, err := aes.NewCipher(key) + if err != nil { + return nil, err + } + + ciphertext := make([]byte, aes.BlockSize+len(plaintext)) + iv = iv[:aes.BlockSize] + if _, err := io.ReadFull(rand.Reader, iv); err != nil { + return nil, err + } + + mode := cipher.NewCBCEncrypter(block, iv) + mode.CryptBlocks(ciphertext[aes.BlockSize:], plaintext) + + return ciphertext, nil +} + +// CBC解密数据 +func CbcDecrypt(key, ciphertext, iv []byte) ([]byte, error) { + block, err := aes.NewCipher(key) + if err != nil { + return nil, err + } + + size := aes.BlockSize + iv = iv[:size] + // ciphertext = ciphertext[size:] TODO: really useless? + + if len(ciphertext) < size { + return nil, errors.New("ciphertext too short") + } + + if len(ciphertext)%size != 0 { + return nil, errors.New("ciphertext is not a multiple of the block size") + } + + mode := cipher.NewCBCDecrypter(block, iv) + mode.CryptBlocks(ciphertext, ciphertext) + + return pkcs7decode(ciphertext), nil +}