提交 3e6bc5ce authored 作者: 屈传平's avatar 屈传平

ikucun

上级 d50d8663
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
}
...@@ -23,6 +23,7 @@ const ( ...@@ -23,6 +23,7 @@ const (
Tmv3 = 20 //天猫优选 Tmv3 = 20 //天猫优选
Suning = 21 //苏宁有货 Suning = 21 //苏宁有货
Yonghui = 22 //永辉 Yonghui = 22 //永辉
Ikucun = 23 //爱库存
) )
var ( var (
...@@ -116,6 +117,10 @@ func GetUpstreamList() (res interface{}, err error) { ...@@ -116,6 +117,10 @@ func GetUpstreamList() (res interface{}, err error) {
"key": Yonghui, "key": Yonghui,
"name": GetUpstreamName(Yonghui), "name": GetUpstreamName(Yonghui),
}, },
g.Map{
"key": Ikucun,
"name": GetUpstreamName(Ikucun),
},
} }
return return
} }
...@@ -158,6 +163,8 @@ func GetUpstreamName(source int) string { ...@@ -158,6 +163,8 @@ func GetUpstreamName(source int) string {
return "苏宁易购" return "苏宁易购"
case Yonghui: case Yonghui:
return "永辉" return "永辉"
case Ikucun:
return "爱库存"
default: default:
return "未知来源" return "未知来源"
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论