From 3e6bc5ce4cd6feedc64b56a1d6cc6f89b716d4ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E5=B0=8F=E6=AF=85?= <quchuanping@qq.com> Date: Tue, 18 Mar 2025 15:02:02 +0800 Subject: [PATCH] ikucun --- upstream/ikucun/ikucun.go | 74 +++++++++++++++++++++++++++++++++ upstream/ikucun/ikucun_goods.go | 1 + upstream/upstream.go | 7 ++++ 3 files changed, 82 insertions(+) create mode 100644 upstream/ikucun/ikucun.go create mode 100644 upstream/ikucun/ikucun_goods.go diff --git a/upstream/ikucun/ikucun.go b/upstream/ikucun/ikucun.go new file mode 100644 index 0000000..6316536 --- /dev/null +++ b/upstream/ikucun/ikucun.go @@ -0,0 +1,74 @@ +package ikucun + +import ( + "context" + "github.com/gogf/gf/crypto/gsha1" + "github.com/gogf/gf/encoding/gjson" + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/util/gconv" + "math/rand" + "time" +) + +var server *Config + +const pkgName = "ikucun" + +type Config struct { + AppId string + AppSecret string + ApiUrl string +} + +func makeNonceStr() string { + str := "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789" + rand.Seed(time.Now().UnixNano()) // åˆå§‹åŒ–éšæœºæ•°ç§å + + // 打乱å—符串 + shuffledStr := shuffleString(str) + + // éšæœºèµ·å§‹ä½ç½® + startIndex := rand.Intn(len(shuffledStr) - 10) + + // æˆªå– 10 ä½å—符 + return shuffledStr[startIndex : startIndex+10] +} + +// 打乱å—符串 +func shuffleString(str string) string { + strRunes := []rune(str) + rand.Shuffle(len(strRunes), func(i, j int) { + strRunes[i], strRunes[j] = strRunes[j], strRunes[i] + }) + return string(strRunes) +} + +func sign(req string) string { + res := gsha1.Encrypt(req) + return res +} + +func post(ctx context.Context, method string, req interface{}) (res string, err error) { + Start := gtime.TimestampMilli() + reqMap := gconv.Map(req) + reqMap["appId"] = server.AppId + param := gjson.New(reqMap) + Url := server.ApiUrl + method + Request := g.Client() + Request.SetHeader("Content-Type", "application/json") + Request.SetHeader("sign", sign(param.MustToJsonString())) + resp, err := Request.Timeout(time.Second*5).Post(Url, param.MustToJsonString()) + defer func() { + _ = resp.Close() + ctx = context.WithValue(ctx, "Method", "POST") + ctx = context.WithValue(ctx, "URI", Url) + if err != nil { + g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("傿•°ã€%v】错误ã€%v】å“应时间ã€%v ms】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start) + } else { + g.Log().Ctx(ctx).Cat(pkgName).Infof("傿•°ã€%v】å“应ã€%v】å“应时间ã€%v ms】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start) + } + }() + res = resp.ReadAllString() + return +} diff --git a/upstream/ikucun/ikucun_goods.go b/upstream/ikucun/ikucun_goods.go new file mode 100644 index 0000000..e823cb9 --- /dev/null +++ b/upstream/ikucun/ikucun_goods.go @@ -0,0 +1 @@ +package ikucun diff --git a/upstream/upstream.go b/upstream/upstream.go index a01c366..1173fbc 100644 --- a/upstream/upstream.go +++ b/upstream/upstream.go @@ -23,6 +23,7 @@ const ( Tmv3 = 20 //天猫优选 Suning = 21 //è‹å®æœ‰è´§ Yonghui = 22 //永辉 + Ikucun = 23 //çˆ±åº“å˜ ) var ( @@ -116,6 +117,10 @@ func GetUpstreamList() (res interface{}, err error) { "key": Yonghui, "name": GetUpstreamName(Yonghui), }, + g.Map{ + "key": Ikucun, + "name": GetUpstreamName(Ikucun), + }, } return } @@ -158,6 +163,8 @@ func GetUpstreamName(source int) string { return "è‹å®æ˜“è´" case Yonghui: return "永辉" + case Ikucun: + return "爱库å˜" default: return "æœªçŸ¥æ¥æº" } -- 2.18.1