Compare commits
56 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f7a1a30203 | ||
![]() |
9eecda8c5f | ||
![]() |
12db943012 | ||
![]() |
3676395e9f | ||
![]() |
2fd998b52d | ||
![]() |
2e8f0cb3f2 | ||
![]() |
992f39109d | ||
![]() |
db27554374 | ||
![]() |
e2d9685db3 | ||
![]() |
9656f69fea | ||
![]() |
695dcf3c49 | ||
![]() |
82caad9679 | ||
![]() |
9a27e529eb | ||
![]() |
e41a3c8600 | ||
![]() |
ebe8aff954 | ||
![]() |
3d62321146 | ||
![]() |
12e627aac6 | ||
![]() |
842e6d94aa | ||
![]() |
9e328b469b | ||
![]() |
36664d298e | ||
![]() |
0bbbfa3c1e | ||
![]() |
169996cc8a | ||
![]() |
6d3891390f | ||
![]() |
5574b1ba4e | ||
![]() |
0b6b76c708 | ||
![]() |
d4bc04dbe5 | ||
![]() |
4c27cecde1 | ||
![]() |
1b97811c6a | ||
![]() |
2483d9c305 | ||
![]() |
e936dd6622 | ||
![]() |
3e765809e1 | ||
![]() |
ecfa733a9b | ||
![]() |
448d47d0cb | ||
![]() |
fa3ae27283 | ||
![]() |
094d4abdf4 | ||
![]() |
c9190ea4d4 | ||
![]() |
9fbd72fa16 | ||
![]() |
b535467e6f | ||
![]() |
3957f3b5b9 | ||
![]() |
79f36b239b | ||
![]() |
20a3b65f01 | ||
![]() |
58cf9d920d | ||
![]() |
fa19e791e0 | ||
![]() |
af3360113d | ||
![]() |
be569bda75 | ||
![]() |
160d955a0c | ||
![]() |
96c87f015d | ||
![]() |
9d348523e6 | ||
![]() |
c5b73fb675 | ||
![]() |
7ddebe6fc3 | ||
![]() |
225efe116d | ||
![]() |
af1abd701e | ||
![]() |
ccb2ae442a | ||
![]() |
68c47e1023 | ||
![]() |
c3a65f89c6 | ||
![]() |
f0241c27e3 |
50
common_fun/string_func.go
Normal file
50
common_fun/string_func.go
Normal file
@ -0,0 +1,50 @@
|
||||
package cf
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// 是否是手机号
|
||||
func IsMobile(str string) bool {
|
||||
return regexp.MustCompile(`^1[3-9]\d{9}$`).MatchString(str)
|
||||
}
|
||||
|
||||
// 随机字符串
|
||||
var letters = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
|
||||
// 获取随机字符串
|
||||
func StrRand(strLen int) string {
|
||||
randBytes := make([]rune, strLen)
|
||||
for i := range randBytes {
|
||||
randBytes[i] = letters[rand.Intn(len(letters))]
|
||||
}
|
||||
return string(randBytes)
|
||||
}
|
||||
|
||||
// 随机字母字符串
|
||||
var charLetters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
|
||||
// 随机字母字符串
|
||||
func StrCharRand(strLen int) string {
|
||||
randBytes := make([]rune, strLen)
|
||||
for i := range randBytes {
|
||||
randBytes[i] = charLetters[rand.Intn(len(charLetters))]
|
||||
}
|
||||
return string(randBytes)
|
||||
}
|
||||
|
||||
// 随机数字字符串
|
||||
// 第一位不能是0
|
||||
func StrNumberRand(strLen int) string {
|
||||
numberLetters := []rune("0123456789")
|
||||
randBytes := make([]rune, strLen)
|
||||
for i := range randBytes {
|
||||
if i == 0 {
|
||||
randBytes[i] = letters[rand.Intn(9)]
|
||||
} else {
|
||||
randBytes[i] = letters[rand.Intn(len(numberLetters))]
|
||||
}
|
||||
}
|
||||
return string(randBytes)
|
||||
}
|
78
common_fun/string_func_test.go
Normal file
78
common_fun/string_func_test.go
Normal file
@ -0,0 +1,78 @@
|
||||
package cf
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Test IsMobile
|
||||
func TestIsMobile(t *testing.T) {
|
||||
valid := []string{
|
||||
"13800138000",
|
||||
"19999999999",
|
||||
"18888888888",
|
||||
}
|
||||
invalid := []string{
|
||||
"23800138000",
|
||||
"10000000000",
|
||||
"12345",
|
||||
"abc13800138000",
|
||||
"",
|
||||
}
|
||||
|
||||
for _, v := range valid {
|
||||
if !IsMobile(v) {
|
||||
t.Errorf("IsMobile(%q) = false, want true", v)
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range invalid {
|
||||
if IsMobile(v) {
|
||||
t.Errorf("IsMobile(%q) = true, want false", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test StrRand
|
||||
func TestStrRand(t *testing.T) {
|
||||
length := 16
|
||||
s := StrRand(length)
|
||||
if len(s) != length {
|
||||
t.Errorf("StrRand length = %d, want %d", len(s), length)
|
||||
}
|
||||
|
||||
// check character set
|
||||
matched, _ := regexp.MatchString(`^[0-9a-zA-Z]+$`, s)
|
||||
if !matched {
|
||||
t.Errorf("StrRand returned invalid characters: %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
// Test StrCharRand
|
||||
func TestStrCharRand(t *testing.T) {
|
||||
length := 10
|
||||
s := StrCharRand(length)
|
||||
if len(s) != length {
|
||||
t.Errorf("StrCharRand length = %d, want %d", len(s), length)
|
||||
}
|
||||
matched, _ := regexp.MatchString(`^[a-zA-Z]+$`, s)
|
||||
if !matched {
|
||||
t.Errorf("StrCharRand returned invalid characters: %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
// Test StrNumberRand
|
||||
func TestStrNumberRand(t *testing.T) {
|
||||
length := 8
|
||||
s := StrNumberRand(length)
|
||||
if len(s) != length {
|
||||
t.Errorf("StrNumberRand length = %d, want %d", len(s), length)
|
||||
}
|
||||
matched, _ := regexp.MatchString(`^[0-9]+$`, s)
|
||||
if !matched {
|
||||
t.Errorf("StrNumberRand returned invalid characters: %s", s)
|
||||
}
|
||||
if s[0] == '0' {
|
||||
t.Errorf("StrNumberRand starts with 0, which is not allowed: %s", s)
|
||||
}
|
||||
}
|
161
express_tool/ali_cloud_client.go
Normal file
161
express_tool/ali_cloud_client.go
Normal file
@ -0,0 +1,161 @@
|
||||
package express_tool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
type AliCloudExpressClient struct {
|
||||
AppCode string
|
||||
Host string
|
||||
cache ICacheAdapter
|
||||
}
|
||||
|
||||
func NewAliCloudExpressClient(host, appCode string) *AliCloudExpressClient {
|
||||
return &AliCloudExpressClient{
|
||||
AppCode: appCode,
|
||||
Host: host,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *AliCloudExpressClient) GetLogisticsInfo(mobile, number string) (res *ExpressRes, err error) {
|
||||
if mobile == "" || number == "" {
|
||||
return nil, errors.New("请输入手机号和物流单号")
|
||||
}
|
||||
// 设置参数
|
||||
params := url.Values{}
|
||||
params.Add("mobile", mobile)
|
||||
params.Add("number", number)
|
||||
// 拼接URL
|
||||
var fullURL string
|
||||
fullURL, err = url.JoinPath(a.Host)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "查询物流信息失败, 拼接路径错误! 手机号:%s, 物流单号:%s", mobile, number)
|
||||
}
|
||||
// 拼接参数
|
||||
fullURL = fmt.Sprintf("%s?%s", fullURL, params.Encode())
|
||||
// 创建HTTP客户端
|
||||
client := &http.Client{}
|
||||
// 创建请求
|
||||
var req *http.Request
|
||||
req, err = http.NewRequest(http.MethodGet, fullURL, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "查询物流信息失败, 创建请求失败! 手机号:%s, 物流单号:%s", mobile, number)
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
req.Header.Add("Authorization", "APPCODE "+a.AppCode)
|
||||
|
||||
// 发送请求
|
||||
client.Timeout = 2 * time.Second
|
||||
var resp *http.Response
|
||||
resp, err = client.Do(req)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "查询物流信息失败, 发送请求失败! 手机号:%s, 物流单号:%s", mobile, number)
|
||||
}
|
||||
defer func(Body io.ReadCloser) {
|
||||
err = Body.Close()
|
||||
if err != nil {
|
||||
log.Printf("查询物流信息失败, 关闭响应体失败! 手机号:%s, 物流单号:%s , %+v\n", mobile, number, err)
|
||||
}
|
||||
}(resp.Body)
|
||||
|
||||
// 读取响应体
|
||||
var body []byte
|
||||
body, err = io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "查询物流信息失败, 读取响应体失败! 手机号:%s, 物流单号:%s", mobile, number)
|
||||
}
|
||||
//log.Printf("查询物流信息成功! %s\n", string(body))
|
||||
|
||||
// 解析JSON响应
|
||||
var expressRes ExpressRes
|
||||
err = json.Unmarshal(body, &expressRes)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "查询物流信息失败, 解析JSON响应失败, %s! 手机号:%s, 物流单号:%s", string(body), mobile, number)
|
||||
}
|
||||
|
||||
if expressRes.Code != 0 {
|
||||
return &expressRes, errors.Wrapf(err, "查询物流信息失败! expressRes:%+v 手机号:%s, 物流单号:%s", expressRes, mobile, number)
|
||||
}
|
||||
|
||||
if expressRes.Data == nil {
|
||||
return &expressRes, errors.Wrapf(err, "查询物流信息失败,没有查询到物流信息! expressRes:%+v 手机号:%s, 物流单号:%s", expressRes, mobile, number)
|
||||
}
|
||||
|
||||
return &expressRes, nil
|
||||
}
|
||||
|
||||
func (a *AliCloudExpressClient) Set(cache ICacheAdapter) {
|
||||
a.cache = cache
|
||||
}
|
||||
|
||||
func (a *AliCloudExpressClient) GetLogisticsInfoFormCache(ctx context.Context, mobile, prefix, number string, opt ...time.Duration) (res *ExpressRes, err error) {
|
||||
if a.cache != nil {
|
||||
res, err = a.cache.Get(ctx, a.numberKey(prefix, number))
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "获取缓存失败, number:%s", number)
|
||||
}
|
||||
if res != nil {
|
||||
return res, nil
|
||||
}
|
||||
}
|
||||
res, err = a.GetLogisticsInfo(mobile, number)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "获取物流信息失败, number:%s", number)
|
||||
}
|
||||
|
||||
var infoJson []byte
|
||||
infoJson, err = json.Marshal(res)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "无法将物流信息转换为JSON, number:%s", number)
|
||||
}
|
||||
|
||||
if len(opt) > 0 {
|
||||
err = a.cache.Set(ctx, a.numberKey(prefix, number), string(infoJson), opt[0])
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "缓存物流信息失败, number:%s", number)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (a *AliCloudExpressClient) DeleteLogisticsInfoCache(ctx context.Context, prefix, number string) (err error) {
|
||||
if a.cache == nil {
|
||||
return errors.New("缓存不能为空")
|
||||
}
|
||||
err = a.cache.Del(ctx, a.numberKey(prefix, number))
|
||||
return err
|
||||
}
|
||||
|
||||
// ipKey 生成Redis key
|
||||
func (a *AliCloudExpressClient) numberKey(prefix, number string) string {
|
||||
return fmt.Sprintf("%s:number:%s", prefix, number)
|
||||
}
|
||||
|
||||
type ExpressRes struct {
|
||||
Code int `json:"code"`
|
||||
Desc string `json:"desc"`
|
||||
Data *Data `json:"data"`
|
||||
}
|
||||
|
||||
type Data struct {
|
||||
State int `json:"state" dc:"物流状态【1在途中,2派件中,3已签收,4派送失败,5揽收,6退回,7转单,8疑难,9退签,10待清关,11清关中,12已清关,13清关异常】"`
|
||||
Name string `json:"name" dc:"物流名"`
|
||||
Com string `json:"com"`
|
||||
Number string `json:"number" dc:"单号"`
|
||||
Logo string `json:"logo" dc:"图标地址"`
|
||||
List []*List `json:"list"`
|
||||
}
|
||||
|
||||
type List struct {
|
||||
Time string `json:"time"`
|
||||
Status string `json:"status"`
|
||||
}
|
130
express_tool/ali_cloud_client_test.go
Normal file
130
express_tool/ali_cloud_client_test.go
Normal file
@ -0,0 +1,130 @@
|
||||
package express_tool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"log"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestAliCloudExpressClient_GetLogisticsInfo(t *testing.T) {
|
||||
type fields struct {
|
||||
AppCode string
|
||||
Host string
|
||||
}
|
||||
type args struct {
|
||||
mobile string
|
||||
number string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantRes *ExpressRes
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
AppCode: "",
|
||||
Host: "",
|
||||
},
|
||||
args: args{
|
||||
mobile: "",
|
||||
number: "",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
a := &AliCloudExpressClient{
|
||||
AppCode: tt.fields.AppCode,
|
||||
Host: tt.fields.Host,
|
||||
}
|
||||
gotRes, err := a.GetLogisticsInfo(tt.args.mobile, tt.args.number)
|
||||
log.Println(gotRes, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAliCloudExpressClient_GetLogisticsInfoFormCache(t *testing.T) {
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "",
|
||||
Password: "",
|
||||
DB: 1,
|
||||
})
|
||||
|
||||
// 创建缓存实例
|
||||
cache := NewRedisCache(rdb)
|
||||
a := &AliCloudExpressClient{
|
||||
AppCode: "",
|
||||
Host: "",
|
||||
cache: cache,
|
||||
}
|
||||
gotRes, err := a.GetLogisticsInfoFormCache(context.Background(), "", "", "", time.Minute)
|
||||
log.Println(gotRes, err)
|
||||
}
|
||||
|
||||
func TestAliCloudExpressClient_DeleteLogisticsInfoCache(t *testing.T) {
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "",
|
||||
Password: "",
|
||||
DB: 1,
|
||||
})
|
||||
|
||||
// 创建缓存实例
|
||||
cache := NewRedisCache(rdb)
|
||||
a := &AliCloudExpressClient{
|
||||
AppCode: "",
|
||||
Host: "",
|
||||
cache: cache,
|
||||
}
|
||||
err := a.DeleteLogisticsInfoCache(context.Background(), "", "")
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
type RedisCache struct {
|
||||
client *redis.Client
|
||||
}
|
||||
|
||||
func (r *RedisCache) Del(ctx context.Context, number string) error {
|
||||
return r.client.Del(ctx, number).Err()
|
||||
}
|
||||
|
||||
func NewRedisCache(client *redis.Client) *RedisCache {
|
||||
return &RedisCache{client: client}
|
||||
}
|
||||
|
||||
func (r *RedisCache) Set(ctx context.Context, number string, res string, ttl time.Duration) error {
|
||||
if number == "" {
|
||||
return errors.New("number不能为空")
|
||||
}
|
||||
|
||||
return r.client.Set(ctx, number, res, ttl).Err()
|
||||
}
|
||||
|
||||
// Get 从Redis获取IP信息
|
||||
func (r *RedisCache) Get(ctx context.Context, number string) (*ExpressRes, error) {
|
||||
if number == "" {
|
||||
return nil, errors.New("number不能为空")
|
||||
}
|
||||
|
||||
data, err := r.client.Get(ctx, number).Bytes()
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, nil // 键不存在,返回nil而不是错误
|
||||
}
|
||||
return nil, fmt.Errorf("无法获取物流信息: %w", err)
|
||||
}
|
||||
|
||||
var info ExpressRes
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
return nil, fmt.Errorf("无法解析物流信息: %w", err)
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
12
express_tool/express_cache.go
Normal file
12
express_tool/express_cache.go
Normal file
@ -0,0 +1,12 @@
|
||||
package express_tool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ICacheAdapter interface {
|
||||
Set(ctx context.Context, key string, res string, ttl time.Duration) error
|
||||
Get(ctx context.Context, key string) (*ExpressRes, error)
|
||||
Del(ctx context.Context, key string) error
|
||||
}
|
32
go.mod
32
go.mod
@ -1,5 +1,33 @@
|
||||
module git.ssgfgtfy.com/public/ssgf_utils
|
||||
|
||||
go 1.24.0
|
||||
go 1.18.0
|
||||
|
||||
require github.com/pkg/errors v0.9.1
|
||||
require (
|
||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.1.7
|
||||
github.com/alibabacloud-go/dysmsapi-20170525/v5 v5.1.1
|
||||
github.com/alibabacloud-go/tea v1.3.8
|
||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.7
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/redis/go-redis/v9 v9.10.0
|
||||
github.com/stretchr/testify v1.10.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.5 // indirect
|
||||
github.com/alibabacloud-go/debug v1.0.1 // indirect
|
||||
github.com/alibabacloud-go/endpoint-util v1.1.0 // indirect
|
||||
github.com/alibabacloud-go/openapi-util v0.1.1 // indirect
|
||||
github.com/aliyun/credentials-go v1.4.5 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/tjfoc/gmsm v1.4.1 // indirect
|
||||
golang.org/x/net v0.26.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
264
go.sum
264
go.sum
@ -1,2 +1,266 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/alibabacloud-go/alibabacloud-gateway-pop v0.0.6 h1:eIf+iGJxdU4U9ypaUfbtOWCsZSbTb8AUHvyPrxu6mAA=
|
||||
github.com/alibabacloud-go/alibabacloud-gateway-pop v0.0.6/go.mod h1:4EUIoxs/do24zMOGGqYVWgw0s9NtiylnJglOeEB5UJo=
|
||||
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4/go.mod h1:sCavSAvdzOjul4cEqeVtvlSaSScfNsTQ+46HwlTL1hc=
|
||||
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.5 h1:zE8vH9C7JiZLNJJQ5OwjU9mSi4T9ef9u3BURT6LCLC8=
|
||||
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.5/go.mod h1:tWnyE9AjF8J8qqLk645oUmVUnFybApTQWklQmi5tY6g=
|
||||
github.com/alibabacloud-go/darabonba-array v0.1.0 h1:vR8s7b1fWAQIjEjWnuF0JiKsCvclSRTfDzZHTYqfufY=
|
||||
github.com/alibabacloud-go/darabonba-array v0.1.0/go.mod h1:BLKxr0brnggqOJPqT09DFJ8g3fsDshapUD3C3aOEFaI=
|
||||
github.com/alibabacloud-go/darabonba-encode-util v0.0.2 h1:1uJGrbsGEVqWcWxrS9MyC2NG0Ax+GpOM5gtupki31XE=
|
||||
github.com/alibabacloud-go/darabonba-encode-util v0.0.2/go.mod h1:JiW9higWHYXm7F4PKuMgEUETNZasrDM6vqVr/Can7H8=
|
||||
github.com/alibabacloud-go/darabonba-map v0.0.2 h1:qvPnGB4+dJbJIxOOfawxzF3hzMnIpjmafa0qOTp6udc=
|
||||
github.com/alibabacloud-go/darabonba-map v0.0.2/go.mod h1:28AJaX8FOE/ym8OUFWga+MtEzBunJwQGceGQlvaPGPc=
|
||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.11/go.mod h1:wHxkgZT1ClZdcwEVP/pDgYK/9HucsnCfMipmJgCz4xY=
|
||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.1.7 h1:ASXSBga98QrGMxbIThCD6jAti09gedLfvry6yJtsoBE=
|
||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.1.7/go.mod h1:TBpgqm3XofZz2LCYjZhektGPU7ArEgascyzbm4SjFo4=
|
||||
github.com/alibabacloud-go/darabonba-signature-util v0.0.7 h1:UzCnKvsjPFzApvODDNEYqBHMFt1w98wC7FOo0InLyxg=
|
||||
github.com/alibabacloud-go/darabonba-signature-util v0.0.7/go.mod h1:oUzCYV2fcCH797xKdL6BDH8ADIHlzrtKVjeRtunBNTQ=
|
||||
github.com/alibabacloud-go/darabonba-string v1.0.2 h1:E714wms5ibdzCqGeYJ9JCFywE5nDyvIXIIQbZVFkkqo=
|
||||
github.com/alibabacloud-go/darabonba-string v1.0.2/go.mod h1:93cTfV3vuPhhEwGGpKKqhVW4jLe7tDpo3LUM0i0g6mA=
|
||||
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68/go.mod h1:6pb/Qy8c+lqua8cFpEy7g39NRRqOWc3rOwAy8m5Y2BY=
|
||||
github.com/alibabacloud-go/debug v1.0.0/go.mod h1:8gfgZCCAC3+SCzjWtY053FrOcd4/qlH6IHTI4QyICOc=
|
||||
github.com/alibabacloud-go/debug v1.0.1 h1:MsW9SmUtbb1Fnt3ieC6NNZi6aEwrXfDksD4QA6GSbPg=
|
||||
github.com/alibabacloud-go/debug v1.0.1/go.mod h1:8gfgZCCAC3+SCzjWtY053FrOcd4/qlH6IHTI4QyICOc=
|
||||
github.com/alibabacloud-go/dysmsapi-20170525/v5 v5.1.1 h1:Kle0H03Z85fDLHnO3dadhSGMzOnEOcUbHCjbDjvY9lc=
|
||||
github.com/alibabacloud-go/dysmsapi-20170525/v5 v5.1.1/go.mod h1:mYOaEwXaib4RLB2NY8cXFjKbxPQHUqt6lhPEOvqR8aw=
|
||||
github.com/alibabacloud-go/endpoint-util v1.1.0 h1:r/4D3VSw888XGaeNpP994zDUaxdgTSHBbVfZlzf6b5Q=
|
||||
github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE=
|
||||
github.com/alibabacloud-go/openapi-util v0.1.0/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
|
||||
github.com/alibabacloud-go/openapi-util v0.1.1 h1:ujGErJjG8ncRW6XtBBMphzHTvCxn4DjrVw4m04HsS28=
|
||||
github.com/alibabacloud-go/openapi-util v0.1.1/go.mod h1:/UehBSE2cf1gYT43GV4E+RxTdLRzURImCYY0aRmlXpw=
|
||||
github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg=
|
||||
github.com/alibabacloud-go/tea v1.1.7/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
|
||||
github.com/alibabacloud-go/tea v1.1.8/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
|
||||
github.com/alibabacloud-go/tea v1.1.11/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
|
||||
github.com/alibabacloud-go/tea v1.1.17/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A=
|
||||
github.com/alibabacloud-go/tea v1.1.20/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A=
|
||||
github.com/alibabacloud-go/tea v1.2.2/go.mod h1:CF3vOzEMAG+bR4WOql8gc2G9H3EkH3ZLAQdpmpXMgwk=
|
||||
github.com/alibabacloud-go/tea v1.3.8 h1:Sk2+BDJC//xJ1/Eljf+Dlg2u2tgWpA9P7mlb87AEcEs=
|
||||
github.com/alibabacloud-go/tea v1.3.8/go.mod h1:A560v/JTQ1n5zklt2BEpurJzZTI8TUT+Psg2drWlxRg=
|
||||
github.com/alibabacloud-go/tea-utils v1.3.1/go.mod h1:EI/o33aBfj3hETm4RLiAxF/ThQdSngxrpF8rKUDJjPE=
|
||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.5/go.mod h1:dL6vbUT35E4F4bFTHL845eUloqaerYBYPsdWR2/jhe4=
|
||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.6/go.mod h1:qxn986l+q33J5VkialKMqT/TTs3E+U9MJpd001iWQ9I=
|
||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.7 h1:WDx5qW3Xa5ZgJ1c8NfqJkF6w+AU5wB8835UdhPr6Ax0=
|
||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.7/go.mod h1:qxn986l+q33J5VkialKMqT/TTs3E+U9MJpd001iWQ9I=
|
||||
github.com/alibabacloud-go/tea-xml v1.1.3/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCEtyBy9+DPF6GgEu8=
|
||||
github.com/aliyun/credentials-go v1.1.2/go.mod h1:ozcZaMR5kLM7pwtCMEpVmQ242suV6qTJya2bDq4X1Tw=
|
||||
github.com/aliyun/credentials-go v1.3.1/go.mod h1:8jKYhQuDawt8x2+fusqa1Y6mPxemTsBEN04dgcAcYz0=
|
||||
github.com/aliyun/credentials-go v1.3.6/go.mod h1:1LxUuX7L5YrZUWzBrRyk0SwSdH4OmPrib8NVePL3fxM=
|
||||
github.com/aliyun/credentials-go v1.4.5 h1:O76WYKgdy1oQYYiJkERjlA2dxGuvLRrzuO2ScrtGWSk=
|
||||
github.com/aliyun/credentials-go v1.4.5/go.mod h1:Jm6d+xIgwJVLVWT561vy67ZRP4lPTQxMbEYRuT2Ti1U=
|
||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
|
||||
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
|
||||
github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
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/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/redis/go-redis/v9 v9.10.0 h1:FxwK3eV8p/CQa0Ch276C7u2d0eNC9kCmAYQ7mCXCzVs=
|
||||
github.com/redis/go-redis/v9 v9.10.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/assertions v1.1.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tjfoc/gmsm v1.3.2/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w=
|
||||
github.com/tjfoc/gmsm v1.4.1 h1:aMe1GlZb+0bLjn+cKTPEvvn9oUEBlJitaZiiBwsbgho=
|
||||
github.com/tjfoc/gmsm v1.4.1/go.mod h1:j4INPkHWMrhJb38G+J6W4Tw0AbuN8Thu3PbdVYhVcTE=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.30/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
|
||||
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
|
||||
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
|
||||
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
|
||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
|
||||
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
|
||||
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/ini.v1 v1.56.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
142
gps_tool/an_na_qi_client.go
Normal file
142
gps_tool/an_na_qi_client.go
Normal file
@ -0,0 +1,142 @@
|
||||
package gps_tool
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type AnNaQiGpsClient struct {
|
||||
AppCode string
|
||||
Host string
|
||||
}
|
||||
|
||||
func NewAnNaQiGpsClient(appCode string) *AnNaQiGpsClient {
|
||||
return &AnNaQiGpsClient{
|
||||
AppCode: appCode,
|
||||
Host: "https://jmgeocode.market.alicloudapi.com",
|
||||
}
|
||||
}
|
||||
|
||||
func (n *AnNaQiGpsClient) GetGpsInfo(longitude, latitude float64) (res *AddressComponent, err error) {
|
||||
lo := strconv.FormatFloat(longitude, 'f', 6, 64)
|
||||
la := strconv.FormatFloat(latitude, 'f', 6, 64)
|
||||
location := lo + "," + la
|
||||
// 拼接URL
|
||||
var fullURL string
|
||||
fullURL, err = url.JoinPath(n.Host, "geocode/regeo_query")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "获取gps:%s信息失败,拼接路径错误", location)
|
||||
}
|
||||
param := "location=" + location
|
||||
// 创建请求
|
||||
var req *http.Request
|
||||
req, err = http.NewRequest(http.MethodPost, fullURL, bytes.NewBuffer([]byte(param)))
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "获取gps:%s信息失败,创建请求失败", location)
|
||||
}
|
||||
// 设置请求头
|
||||
req.Header.Add("Authorization", "APPCODE "+n.AppCode)
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
|
||||
|
||||
// 发送请求
|
||||
// 创建HTTP客户端
|
||||
client := &http.Client{}
|
||||
client.Timeout = 5 * time.Second
|
||||
var resp *http.Response
|
||||
resp, err = client.Do(req)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "获取gps:%s信息失败,发送请求失败", location)
|
||||
}
|
||||
defer func(Body io.ReadCloser) {
|
||||
err = Body.Close()
|
||||
if err != nil {
|
||||
log.Printf("获取gps:%s信息,关闭响应体失败: %+v\n", location, err)
|
||||
}
|
||||
}(resp.Body)
|
||||
// 读取响应体
|
||||
var body []byte
|
||||
body, err = io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "获取gps:%s信息失败,读取响应体失败", location)
|
||||
}
|
||||
|
||||
// 解析JSON响应
|
||||
var apiResult ApiResult
|
||||
err = json.Unmarshal(body, &apiResult)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "获取gps:%s信息失败,解析JSON响应失败,%s", location, string(body))
|
||||
}
|
||||
// 检查API返回状态
|
||||
if apiResult.Code != 200 {
|
||||
return nil, errors.New(fmt.Sprintf("获取gps:%s信息失败,%+v", location, apiResult))
|
||||
}
|
||||
|
||||
if len(apiResult.Data.Regeocodes) > 0 {
|
||||
return &apiResult.Data.Regeocodes[0].AddressComponent, nil
|
||||
}
|
||||
return nil, errors.New(fmt.Sprintf("获取gps:%s信息失败,%+v", location, apiResult))
|
||||
}
|
||||
|
||||
type ApiResult struct {
|
||||
Data Data `json:"data"`
|
||||
Msg string `json:"msg"`
|
||||
Success bool `json:"success"`
|
||||
Code int `json:"code"`
|
||||
TaskNo string `json:"taskNo"`
|
||||
}
|
||||
|
||||
type Data struct {
|
||||
Regeocodes []Regeocode `json:"regeocodes"`
|
||||
}
|
||||
|
||||
type Regeocode struct {
|
||||
FormattedAddress string `json:"formatted_address"`
|
||||
AddressComponent AddressComponent `json:"addressComponent"`
|
||||
}
|
||||
|
||||
type AddressComponent struct {
|
||||
// BusinessAreas []interface{} `json:"businessAreas"`
|
||||
Country string `json:"country"`
|
||||
Province string `json:"province"`
|
||||
Citycode string `json:"citycode"`
|
||||
City string `json:"city"`
|
||||
Adcode string `json:"adcode"`
|
||||
// StreetNumber StreetNumber `json:"streetNumber"`
|
||||
// Towncode string `json:"towncode"`
|
||||
// District string `json:"district"`
|
||||
// Neighborhood Neighborhood `json:"neighborhood"`
|
||||
// Township string `json:"township"`
|
||||
// Building Building `json:"building"`
|
||||
}
|
||||
|
||||
type BusinessArea struct {
|
||||
Name string `json:"name"`
|
||||
Location string `json:"location"`
|
||||
Id string `json:"id"`
|
||||
}
|
||||
type StreetNumber struct {
|
||||
Number string `json:"number"`
|
||||
Distance string `json:"distance"`
|
||||
Street string `json:"street"`
|
||||
Location string `json:"location"`
|
||||
Direction string `json:"direction"`
|
||||
}
|
||||
|
||||
type Neighborhood struct {
|
||||
Name interface{} `json:"name"`
|
||||
Type interface{} `json:"type"`
|
||||
}
|
||||
|
||||
type Building struct {
|
||||
Name interface{} `json:"name"`
|
||||
Type interface{} `json:"type"`
|
||||
}
|
177
gps_tool/an_na_qi_client_test.go
Normal file
177
gps_tool/an_na_qi_client_test.go
Normal file
@ -0,0 +1,177 @@
|
||||
package gps_tool
|
||||
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAnNaQiGpsClient_GetGpsInfo(t *testing.T) {
|
||||
type fields struct {
|
||||
AppCode string
|
||||
Host string
|
||||
}
|
||||
type args struct {
|
||||
longitude float64
|
||||
latitude float64
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantRes interface{}
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
AppCode: "",
|
||||
Host: "https://jmgeocode.market.alicloudapi.com",
|
||||
},
|
||||
args: args{
|
||||
longitude: 113.419152,
|
||||
latitude: 23.186899,
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "test2",
|
||||
fields: fields{
|
||||
AppCode: "",
|
||||
Host: "https://jmgeocode.market.alicloudapi.com",
|
||||
},
|
||||
args: args{
|
||||
longitude: 110.165223,
|
||||
latitude: 25.258515,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "test2",
|
||||
fields: fields{
|
||||
AppCode: "",
|
||||
Host: "https://jmgeocode.market.alicloudapi.com",
|
||||
},
|
||||
args: args{
|
||||
longitude: 115.928973,
|
||||
latitude: 28.625388,
|
||||
},
|
||||
},
|
||||
// 107.397284,40.739490
|
||||
{
|
||||
name: "test3",
|
||||
fields: fields{
|
||||
AppCode: "",
|
||||
Host: "https://jmgeocode.market.alicloudapi.com",
|
||||
},
|
||||
args: args{
|
||||
longitude: 107.397284,
|
||||
latitude: 40.739490,
|
||||
},
|
||||
},
|
||||
// 115.929015,28.625383
|
||||
{
|
||||
name: "test4",
|
||||
fields: fields{
|
||||
AppCode: "",
|
||||
Host: "https://jmgeocode.market.alicloudapi.com",
|
||||
},
|
||||
args: args{
|
||||
longitude: 115.929015,
|
||||
latitude: 28.625383,
|
||||
},
|
||||
},
|
||||
// 115.929100,28.625452
|
||||
{
|
||||
name: "test5",
|
||||
fields: fields{
|
||||
AppCode: "",
|
||||
Host: "https://jmgeocode.market.alicloudapi.com",
|
||||
},
|
||||
args: args{
|
||||
longitude: 115.929100,
|
||||
latitude: 28.625452,
|
||||
},
|
||||
},
|
||||
// 126.587051,45.739880
|
||||
{
|
||||
name: "test6",
|
||||
fields: fields{
|
||||
AppCode: "",
|
||||
Host: "https://jmgeocode.market.alicloudapi.com",
|
||||
},
|
||||
args: args{
|
||||
longitude: 126.587051,
|
||||
latitude: 45.739880,
|
||||
},
|
||||
},
|
||||
// 126.587051,45.739880
|
||||
{
|
||||
name: "test7",
|
||||
fields: fields{
|
||||
AppCode: "",
|
||||
Host: "https://jmgeocode.market.alicloudapi.com",
|
||||
},
|
||||
args: args{
|
||||
longitude: 126.595051,
|
||||
latitude: 45.740537,
|
||||
},
|
||||
},
|
||||
// 126.595051,45.740537
|
||||
{
|
||||
name: "test8",
|
||||
fields: fields{
|
||||
AppCode: "",
|
||||
Host: "https://jmgeocode.market.alicloudapi.com",
|
||||
},
|
||||
args: args{
|
||||
longitude: 125.342693,
|
||||
latitude: 43.879634,
|
||||
},
|
||||
},
|
||||
// 125.342693,43.879634
|
||||
{
|
||||
name: "test9",
|
||||
fields: fields{
|
||||
AppCode: "",
|
||||
Host: "https://jmgeocode.market.alicloudapi.com",
|
||||
},
|
||||
args: args{
|
||||
longitude: 112.485550,
|
||||
latitude: 23.061314,
|
||||
},
|
||||
},
|
||||
// 112.485550,23.061314
|
||||
{
|
||||
name: "test10",
|
||||
fields: fields{
|
||||
AppCode: "",
|
||||
Host: "https://jmgeocode.market.alicloudapi.com",
|
||||
},
|
||||
args: args{
|
||||
longitude: 115.928821,
|
||||
latitude: 28.625069,
|
||||
},
|
||||
},
|
||||
// 115.928821,28.625069
|
||||
{
|
||||
name: "test11",
|
||||
fields: fields{
|
||||
AppCode: "",
|
||||
Host: "https://jmgeocode.market.alicloudapi.com",
|
||||
},
|
||||
args: args{
|
||||
longitude: 115.928821,
|
||||
latitude: 28.625069,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
n := &AnNaQiGpsClient{
|
||||
AppCode: tt.fields.AppCode,
|
||||
Host: tt.fields.Host,
|
||||
}
|
||||
gotRes, err := n.GetGpsInfo(tt.args.longitude, tt.args.latitude)
|
||||
log.Println(gotRes, err)
|
||||
})
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package ip_client
|
||||
package ip_tool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -12,19 +13,20 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type HuaChenIpInfo struct {
|
||||
type HuaChenIpClient struct {
|
||||
AppCode string
|
||||
Host string
|
||||
cache ICacheAdapter
|
||||
}
|
||||
|
||||
func NewHuaChenIpInfo(appCode string) *HuaChenIpInfo {
|
||||
return &HuaChenIpInfo{
|
||||
func NewHuaChenIpClient(appCode string) *HuaChenIpClient {
|
||||
return &HuaChenIpClient{
|
||||
AppCode: appCode,
|
||||
Host: "https://c2ba.api.huachen.cn",
|
||||
}
|
||||
}
|
||||
|
||||
func (h *HuaChenIpInfo) GetIpInfo(ip string) (res *ApiResult, err error) {
|
||||
func (h *HuaChenIpClient) GetIpInfo(ip string) (res *ApiResult, err error) {
|
||||
if ip == "" {
|
||||
return nil, errors.New("请输入ip地址")
|
||||
}
|
||||
@ -43,7 +45,7 @@ func (h *HuaChenIpInfo) GetIpInfo(ip string) (res *ApiResult, err error) {
|
||||
client := &http.Client{}
|
||||
// 创建请求
|
||||
var req *http.Request
|
||||
req, err = http.NewRequest("GET", fullURL, nil)
|
||||
req, err = http.NewRequest(http.MethodGet, fullURL, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "获取ip:%s信息失败,创建请求失败", ip)
|
||||
}
|
||||
@ -87,6 +89,45 @@ func (h *HuaChenIpInfo) GetIpInfo(ip string) (res *ApiResult, err error) {
|
||||
return &apiResult, nil
|
||||
}
|
||||
|
||||
func (h *HuaChenIpClient) Set(cache ICacheAdapter) {
|
||||
h.cache = cache
|
||||
}
|
||||
|
||||
func (h *HuaChenIpClient) GetIpInfoFormCache(ctx context.Context, ip string, opt ...time.Duration) (res *ApiResult, err error) {
|
||||
if h.cache != nil {
|
||||
res, err = h.cache.Get(ctx, h.ipKey(ip))
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "获取缓存失败,ip:%s", ip)
|
||||
}
|
||||
if res != nil {
|
||||
return res, nil
|
||||
}
|
||||
}
|
||||
res, err = h.GetIpInfo(ip)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "获取ip:%s信息失败,", ip)
|
||||
}
|
||||
|
||||
var infoJson []byte
|
||||
infoJson, err = json.Marshal(res)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "无法将IP信息转换为JSON,ip:%s", ip)
|
||||
}
|
||||
|
||||
if len(opt) == 0 {
|
||||
err = h.cache.Set(ctx, h.ipKey(ip), string(infoJson), opt[0])
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "缓存ip:%s信息失败,", ip)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ipKey 生成Redis key
|
||||
func (h *HuaChenIpClient) ipKey(ip string) string {
|
||||
return fmt.Sprintf("ip:%s", ip)
|
||||
}
|
||||
|
||||
type ApiResult struct {
|
||||
Ret int `json:"ret"`
|
||||
Msg string `json:"msg"`
|
120
ip_tool/hua_chen_client_test.go
Normal file
120
ip_tool/hua_chen_client_test.go
Normal file
@ -0,0 +1,120 @@
|
||||
package ip_tool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"log"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHuaChenIpClient_GetIpInfo(t *testing.T) {
|
||||
type fields struct {
|
||||
AppCode string
|
||||
Host string
|
||||
}
|
||||
type args struct {
|
||||
ip string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantRes *ApiResult
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
AppCode: "",
|
||||
Host: "https://c2ba.api.huachen.cn",
|
||||
},
|
||||
args: args{
|
||||
ip: "8.138.116.112",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
h := &HuaChenIpClient{
|
||||
AppCode: tt.fields.AppCode,
|
||||
Host: tt.fields.Host,
|
||||
}
|
||||
gotRes, err := h.GetIpInfo(tt.args.ip)
|
||||
log.Println(gotRes, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHuaChenIpClient_GetIpInfo1(t *testing.T) {
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "",
|
||||
Password: "",
|
||||
DB: 1,
|
||||
})
|
||||
|
||||
// 创建IP缓存实例
|
||||
ipCache := NewRedisCache(rdb)
|
||||
h := &HuaChenIpClient{
|
||||
AppCode: "",
|
||||
Host: "https://c2ba.api.huachen.cn",
|
||||
cache: ipCache,
|
||||
}
|
||||
gotRes, err := h.GetIpInfoFormCache(context.Background(), "8.138.116.112")
|
||||
log.Println(gotRes, err)
|
||||
}
|
||||
|
||||
type RedisCache struct {
|
||||
client *redis.Client
|
||||
}
|
||||
|
||||
func NewRedisCache(client *redis.Client) *RedisCache {
|
||||
return &RedisCache{client: client}
|
||||
}
|
||||
|
||||
func (r *RedisCache) Set(ctx context.Context, ip string, info string, ttl time.Duration) error {
|
||||
if ip == "" {
|
||||
return errors.New("ip不能为空")
|
||||
}
|
||||
|
||||
return r.client.Set(ctx, ip, info, ttl).Err()
|
||||
}
|
||||
|
||||
// Get 从Redis获取IP信息
|
||||
func (r *RedisCache) Get(ctx context.Context, ip string) (*ApiResult, error) {
|
||||
if ip == "" {
|
||||
return nil, errors.New("ip不能为空")
|
||||
}
|
||||
|
||||
data, err := r.client.Get(ctx, ip).Bytes()
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, nil // 键不存在,返回nil而不是错误
|
||||
}
|
||||
return nil, fmt.Errorf("无法获取IP信息: %w", err)
|
||||
}
|
||||
|
||||
var info ApiResult
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
return nil, fmt.Errorf("无法解析IP信息: %w", err)
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// Exists 检查IP是否存在缓存中
|
||||
func (r *RedisCache) Exists(ctx context.Context, ip string) (bool, error) {
|
||||
if ip == "" {
|
||||
return false, errors.New("ip不能为空")
|
||||
}
|
||||
|
||||
exists, err := r.client.Exists(ctx, ip).Result()
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("无法检查IP是否存在: %w", err)
|
||||
}
|
||||
|
||||
return exists > 0, nil
|
||||
}
|
13
ip_tool/ip_cache.go
Normal file
13
ip_tool/ip_cache.go
Normal file
@ -0,0 +1,13 @@
|
||||
package ip_tool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Cache 定义缓存接口,遵循接口隔离原则
|
||||
type ICacheAdapter interface {
|
||||
Set(ctx context.Context, ip string, info string, ttl time.Duration) error
|
||||
Get(ctx context.Context, ip string) (*ApiResult, error)
|
||||
Exists(ctx context.Context, ip string) (bool, error)
|
||||
}
|
13
sms_tool/cache_model.go
Normal file
13
sms_tool/cache_model.go
Normal file
@ -0,0 +1,13 @@
|
||||
package sms_tool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ICacheAdapter interface {
|
||||
Get(ctx context.Context, key string) (value interface{}, err error)
|
||||
Set(ctx context.Context, key string, value interface{}, expire time.Duration) (err error)
|
||||
Del(ctx context.Context, key string) (err error)
|
||||
SetNX(ctx context.Context, key string, value interface{}, expire time.Duration) (ok bool, err error)
|
||||
}
|
137
sms_tool/sms_client.go
Normal file
137
sms_tool/sms_client.go
Normal file
@ -0,0 +1,137 @@
|
||||
package sms_tool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||
dysmsapi20170525 "github.com/alibabacloud-go/dysmsapi-20170525/v5/client"
|
||||
util "github.com/alibabacloud-go/tea-utils/v2/service"
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SmsClient struct {
|
||||
SmsConfig
|
||||
Cache ICacheAdapter
|
||||
client *dysmsapi20170525.Client
|
||||
}
|
||||
|
||||
type SmsConfig struct {
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
AccessKeySecret string `json:"accessKeySecret"`
|
||||
Endpoint string `json:"endpoint"`
|
||||
}
|
||||
|
||||
func NewSmsClient(smsConfig *SmsConfig) (smsClient SmsClient, err error) {
|
||||
config := &openapi.Config{}
|
||||
if smsConfig.AccessKeyId == "" {
|
||||
return SmsClient{}, errors.New("AccessKeyId 不能为空")
|
||||
}
|
||||
if smsConfig.AccessKeySecret == "" {
|
||||
return SmsClient{}, errors.New("AccessKeySecret 不能为空")
|
||||
}
|
||||
if smsConfig.Endpoint == "" {
|
||||
smsConfig.Endpoint = "dysmsapi.aliyuncs.com"
|
||||
}
|
||||
config.AccessKeyId = tea.String(smsConfig.AccessKeyId)
|
||||
config.AccessKeySecret = tea.String(smsConfig.AccessKeySecret)
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
|
||||
config.Endpoint = tea.String(smsConfig.Endpoint)
|
||||
|
||||
smsClient.client = &dysmsapi20170525.Client{}
|
||||
smsClient.client, err = dysmsapi20170525.NewClient(config)
|
||||
return smsClient, err
|
||||
}
|
||||
|
||||
// SendSms 发送短信
|
||||
func (c *SmsClient) SendSms(params *SendSmsParams) (res *dysmsapi20170525.SendSmsResponse, err error) {
|
||||
smsParams := &dysmsapi20170525.SendSmsRequest{
|
||||
OutId: tea.String(params.OutId),
|
||||
OwnerId: tea.Int64(params.OwnerId),
|
||||
PhoneNumbers: tea.String(params.PhoneNumbers),
|
||||
ResourceOwnerAccount: tea.String(params.ResourceOwnerAccount),
|
||||
ResourceOwnerId: tea.Int64(params.ResourceOwnerId),
|
||||
SignName: tea.String(params.SignName),
|
||||
SmsUpExtendCode: tea.String(params.SmsUpExtendCode),
|
||||
TemplateCode: tea.String(params.TemplateCode),
|
||||
TemplateParam: tea.String(params.TemplateParam),
|
||||
}
|
||||
runtime := &util.RuntimeOptions{}
|
||||
return c.client.SendSmsWithOptions(smsParams, runtime)
|
||||
}
|
||||
|
||||
// GetCode 获取验证码
|
||||
func (c *SmsClient) GetCode(ctx context.Context, key string) (code string, err error) {
|
||||
if c.Cache == nil {
|
||||
return "", errors.New("缓存不能为空")
|
||||
}
|
||||
value, err := c.Cache.Get(ctx, key)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if value == nil {
|
||||
return "", errors.New("验证码不存在,请重新发送")
|
||||
}
|
||||
switch value.(type) {
|
||||
case string:
|
||||
return value.(string), nil
|
||||
default:
|
||||
return "", errors.New("验证码类型错误,请联系管理员")
|
||||
}
|
||||
}
|
||||
|
||||
// SaveCode 保存验证码
|
||||
func (c *SmsClient) SaveCode(ctx context.Context, key string, code string, expire time.Duration) (err error) {
|
||||
if c.Cache == nil {
|
||||
return errors.New("缓存不能为空")
|
||||
}
|
||||
//保存code
|
||||
err = c.Cache.Set(ctx, key, code, expire)
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteCode 删除验证码
|
||||
func (c *SmsClient) DeleteCode(ctx context.Context, key string) (err error) {
|
||||
if c.Cache == nil {
|
||||
return errors.New("缓存不能为空")
|
||||
}
|
||||
err = c.Cache.Del(ctx, key)
|
||||
return err
|
||||
}
|
||||
|
||||
// SaveCodeWithFrequency 保存验证码并限制请求频率
|
||||
func (c *SmsClient) SaveCodeWithFrequency(ctx context.Context, key string, code string, expire time.Duration, frequency time.Duration) (err error) {
|
||||
if c.Cache == nil {
|
||||
return errors.New("缓存不能为空")
|
||||
}
|
||||
frequencyKey := fmt.Sprintf(CodeFrequencyKey, key)
|
||||
if frequency <= 0 {
|
||||
return errors.New("频率不能小于0")
|
||||
}
|
||||
ok, err := c.Cache.SetNX(ctx, frequencyKey, CodeFrequencyValue, frequency)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
return errors.New("code发送频繁,请稍后再试")
|
||||
}
|
||||
err = c.SaveCode(ctx, key, code, expire)
|
||||
return err
|
||||
}
|
||||
|
||||
// VerifyCode 校验验证码
|
||||
func (c *SmsClient) VerifyCode(ctx context.Context, key string, verifyCode string) (ok bool, err error) {
|
||||
//获取验证码
|
||||
code, err := c.GetCode(ctx, key)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
//校验验证码
|
||||
if code != verifyCode {
|
||||
return false, errors.New("code不一致")
|
||||
}
|
||||
//删除验证码
|
||||
_ = c.DeleteCode(ctx, key)
|
||||
return true, nil
|
||||
}
|
221
sms_tool/sms_client_test.go
Normal file
221
sms_tool/sms_client_test.go
Normal file
@ -0,0 +1,221 @@
|
||||
package sms_tool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"os"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RedisCacheAdapter struct {
|
||||
client *redis.Client
|
||||
}
|
||||
|
||||
func NewRedisCacheAdapter(addr string, password string, db int) *RedisCacheAdapter {
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: addr,
|
||||
Password: password,
|
||||
DB: db,
|
||||
})
|
||||
return &RedisCacheAdapter{client: rdb}
|
||||
}
|
||||
func (r *RedisCacheAdapter) Set(ctx context.Context, key string, value interface{}, expire time.Duration) error {
|
||||
data, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return r.client.Set(ctx, key, data, expire).Err()
|
||||
}
|
||||
func (r *RedisCacheAdapter) Get(ctx context.Context, key string) (interface{}, error) {
|
||||
data, err := r.client.Get(ctx, key).Bytes()
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var value interface{}
|
||||
err = json.Unmarshal(data, &value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
func (r *RedisCacheAdapter) Del(ctx context.Context, key string) error {
|
||||
return r.client.Del(ctx, key).Err()
|
||||
}
|
||||
|
||||
func (r *RedisCacheAdapter) SetNX(ctx context.Context, key string, value interface{}, expire time.Duration) (ok bool, err error) {
|
||||
data, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return r.client.SetNX(ctx, key, data, expire).Result()
|
||||
}
|
||||
|
||||
var (
|
||||
//SMS
|
||||
accessKeyId = os.Getenv("SMS_ALIBABA_CLOUD_ACCESS_KEY_ID")
|
||||
accessKeySecret = os.Getenv("SMS_ALIBABA_CLOUD_ACCESS_KEY_SECRET")
|
||||
phoneNumbers = os.Getenv("SMS_PHONE_NUMBERS")
|
||||
signName = os.Getenv("SMS_SIGN_NAME")
|
||||
templateCode = os.Getenv("SMS_TEMPLATE_CODE")
|
||||
|
||||
//REDIS
|
||||
redisHost = os.Getenv("REDIS_HOST")
|
||||
redisPort = os.Getenv("REDIS_PORT")
|
||||
redisPassword = os.Getenv("REDIS_PASSWORD")
|
||||
redisDb = os.Getenv("REDIS_DB")
|
||||
//redisKeyPrefix = os.Getenv("REDIS_KEY_PREFIX")
|
||||
|
||||
codeKey = fmt.Sprintf("User:Login:Code:%v", phoneNumbers)
|
||||
)
|
||||
|
||||
func TestSmsClient_SendSms(t *testing.T) {
|
||||
config := &SmsConfig{
|
||||
AccessKeyId: accessKeyId,
|
||||
AccessKeySecret: accessKeySecret,
|
||||
}
|
||||
smsClient, err := NewSmsClient(config)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
templateParam := make(map[string]interface{})
|
||||
templateParam["code"] = "123456"
|
||||
templateParamStr, err := json.Marshal(templateParam)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
params := &SendSmsParams{
|
||||
PhoneNumbers: phoneNumbers,
|
||||
SignName: signName,
|
||||
TemplateCode: templateCode,
|
||||
TemplateParam: string(templateParamStr),
|
||||
}
|
||||
res, err := smsClient.SendSms(params)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Println(res)
|
||||
}
|
||||
|
||||
func TestSmsClient_GetCode(t *testing.T) {
|
||||
config := &SmsConfig{
|
||||
AccessKeyId: accessKeyId,
|
||||
AccessKeySecret: accessKeySecret,
|
||||
}
|
||||
smsClient, err := NewSmsClient(config)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
addr := fmt.Sprintf("%s:%s", redisHost, redisPort)
|
||||
db, _ := strconv.Atoi(redisDb)
|
||||
goRedis := NewRedisCacheAdapter(addr, redisPassword, db)
|
||||
smsClient.Cache = goRedis
|
||||
code, err := smsClient.GetCode(context.Background(), codeKey)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Println(code)
|
||||
}
|
||||
|
||||
func TestSmsClient_SaveCode(t *testing.T) {
|
||||
config := &SmsConfig{
|
||||
AccessKeyId: accessKeyId,
|
||||
AccessKeySecret: accessKeySecret,
|
||||
}
|
||||
smsClient, err := NewSmsClient(config)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
addr := fmt.Sprintf("%s:%s", redisHost, redisPort)
|
||||
db, _ := strconv.Atoi(redisDb)
|
||||
goRedis := NewRedisCacheAdapter(addr, redisPassword, db)
|
||||
smsClient.Cache = goRedis
|
||||
|
||||
err = smsClient.SaveCode(context.Background(), codeKey, "123456", time.Minute*5)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Println("保存成功")
|
||||
}
|
||||
|
||||
func TestSmsClient_SaveCodeWithFrequency(t *testing.T) {
|
||||
config := &SmsConfig{
|
||||
AccessKeyId: accessKeyId,
|
||||
AccessKeySecret: accessKeySecret,
|
||||
}
|
||||
smsClient, err := NewSmsClient(config)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
addr := fmt.Sprintf("%s:%s", redisHost, redisPort)
|
||||
db, _ := strconv.Atoi(redisDb)
|
||||
goRedis := NewRedisCacheAdapter(addr, redisPassword, db)
|
||||
smsClient.Cache = goRedis
|
||||
|
||||
err = smsClient.SaveCodeWithFrequency(context.Background(), codeKey, "123456", time.Minute*5, time.Minute)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Println("保存成功")
|
||||
}
|
||||
|
||||
func TestSmsClient_VerifyCode(t *testing.T) {
|
||||
config := &SmsConfig{
|
||||
AccessKeyId: accessKeyId,
|
||||
AccessKeySecret: accessKeySecret,
|
||||
}
|
||||
smsClient, err := NewSmsClient(config)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
addr := fmt.Sprintf("%s:%s", redisHost, redisPort)
|
||||
db, _ := strconv.Atoi(redisDb)
|
||||
goRedis := NewRedisCacheAdapter(addr, redisPassword, db)
|
||||
smsClient.Cache = goRedis
|
||||
ok, err := smsClient.VerifyCode(context.Background(), codeKey, "123456")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Println(ok)
|
||||
}
|
||||
|
||||
func TestSmsClient_DeleteCode(t *testing.T) {
|
||||
config := &SmsConfig{
|
||||
AccessKeyId: accessKeyId,
|
||||
AccessKeySecret: accessKeySecret,
|
||||
}
|
||||
smsClient, err := NewSmsClient(config)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
addr := fmt.Sprintf("%s:%s", redisHost, redisPort)
|
||||
db, _ := strconv.Atoi(redisDb)
|
||||
goRedis := NewRedisCacheAdapter(addr, redisPassword, db)
|
||||
smsClient.Cache = goRedis
|
||||
err = smsClient.DeleteCode(context.Background(), codeKey)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Println("删除成功")
|
||||
}
|
18
sms_tool/sms_model.go
Normal file
18
sms_tool/sms_model.go
Normal file
@ -0,0 +1,18 @@
|
||||
package sms_tool
|
||||
|
||||
type SendSmsParams struct {
|
||||
OutId string `json:"OutId,omitempty" xml:"OutId,omitempty"`
|
||||
OwnerId int64 `json:"OwnerId,omitempty" xml:"OwnerId,omitempty"`
|
||||
PhoneNumbers string `json:"PhoneNumbers,omitempty" xml:"PhoneNumbers,omitempty"`
|
||||
ResourceOwnerAccount string `json:"ResourceOwnerAccount,omitempty" xml:"ResourceOwnerAccount,omitempty"`
|
||||
ResourceOwnerId int64 `json:"ResourceOwnerId,omitempty" xml:"ResourceOwnerId,omitempty"`
|
||||
SignName string `json:"SignName,omitempty" xml:"SignName,omitempty"`
|
||||
SmsUpExtendCode string `json:"SmsUpExtendCode,omitempty" xml:"SmsUpExtendCode,omitempty"`
|
||||
TemplateCode string `json:"TemplateCode,omitempty" xml:"TemplateCode,omitempty"`
|
||||
TemplateParam string `json:"TemplateParam,omitempty" xml:"TemplateParam,omitempty"`
|
||||
}
|
||||
|
||||
const (
|
||||
CodeFrequencyKey = "%s_frequency" // code频率限制key
|
||||
CodeFrequencyValue = "1" // code频率限制值
|
||||
)
|
107
weipinshang/goods_api.go
Normal file
107
weipinshang/goods_api.go
Normal file
@ -0,0 +1,107 @@
|
||||
package wps
|
||||
|
||||
import "fmt"
|
||||
|
||||
// GetGoodBrand 查询商品的品牌
|
||||
func (c *WeiPinShangClient) GetGoodBrand(req GoodBrandReq) (*GoodBrandList, error) {
|
||||
param := StructToMapString(req)
|
||||
out := GoodBrandRes{}
|
||||
err := c.PostAndParse(GetGoodBrandURL, param, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out.Code != 0 {
|
||||
return nil, fmt.Errorf(out.Msg)
|
||||
}
|
||||
res := out.Data
|
||||
return &res, err
|
||||
}
|
||||
|
||||
// GetGoodsClassify 查询商品分类
|
||||
func (c *WeiPinShangClient) GetGoodsClassify(req GetGoodsClassifyReq) (*[]GoodsClassify, error) {
|
||||
param := StructToMapString(req)
|
||||
out := GetGoodsClassifyRes{}
|
||||
err := c.PostAndParse(GetGoodsClassifyURL, param, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out.Code != 0 {
|
||||
return nil, fmt.Errorf(out.Msg)
|
||||
}
|
||||
res := out.Data
|
||||
return &res, err
|
||||
}
|
||||
|
||||
// GetGoodsList 获取全部商品列表接口
|
||||
func (c *WeiPinShangClient) GetGoodsList(req GetGoodsListReq) (*GetGoodsList, error) {
|
||||
param := StructToMapString(req)
|
||||
out := GetGoodsListRes{}
|
||||
err := c.PostAndParse(GetGoodsListURL, param, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out.Code != 0 {
|
||||
return nil, fmt.Errorf(out.Msg)
|
||||
}
|
||||
res := out.Data
|
||||
return &res, err
|
||||
}
|
||||
|
||||
// GetGoodsdept (推荐使用)获取后台已选商品列表接口
|
||||
func (c *WeiPinShangClient) GetGoodsdept(req GetGoodsdeptReq) (*Goodsdept, error) {
|
||||
param := StructToMapString(req)
|
||||
out := GetGoodsdeptRes{}
|
||||
err := c.PostAndParse(GetGoodsdeptURL, param, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out.Code != 0 {
|
||||
return nil, fmt.Errorf(out.Msg)
|
||||
}
|
||||
res := out.Data
|
||||
return &res, err
|
||||
}
|
||||
|
||||
// GetDetailsGoods 获取批量商品详情
|
||||
func (c *WeiPinShangClient) GetDetailsGoods(req GetDetailsGoodsReq) (*[]GoodsItem, error) {
|
||||
param := StructToMapString(req)
|
||||
out := GetDetailsGoodsRes{}
|
||||
err := c.PostAndParse(GetDetailsGoodsUrl, param, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out.Code != 0 {
|
||||
return nil, fmt.Errorf(out.Msg)
|
||||
}
|
||||
res := out.Data
|
||||
return &res, err
|
||||
}
|
||||
|
||||
// GetGoodsDetails 获取单个商品详情接口
|
||||
func (c *WeiPinShangClient) GetGoodsDetails(req GetGoodsDetailsReq) (*GoodsItem, error) {
|
||||
param := StructToMapString(req)
|
||||
out := GetGoodsDetailsRes{}
|
||||
err := c.PostAndParse(GetGoodsDetailsURL, param, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out.Code != 0 {
|
||||
return nil, fmt.Errorf(out.Msg)
|
||||
}
|
||||
res := out.Data
|
||||
return &res, err
|
||||
}
|
||||
|
||||
func (c *WeiPinShangClient) GetGoodsStock(req GetGoodsStockReq) (*[]GoodsStock, error) {
|
||||
param := StructToMapString(req)
|
||||
out := GetGoodsStockRes{}
|
||||
err := c.PostAndParse(GetGoodsStockURL, param, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out.Code != 0 {
|
||||
return nil, fmt.Errorf(out.Msg)
|
||||
}
|
||||
res := out.Data
|
||||
return &res, err
|
||||
}
|
115
weipinshang/goods_api_test.go
Normal file
115
weipinshang/goods_api_test.go
Normal file
@ -0,0 +1,115 @@
|
||||
package wps_test
|
||||
|
||||
import (
|
||||
wps "git.ssgfgtfy.com/public/ssgf_utils/weipinshang"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func setupMockServer(path string, method string, response string, t *testing.T) *httptest.Server {
|
||||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "/"+path, r.URL.Path)
|
||||
assert.Equal(t, method, r.Method)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(response))
|
||||
}))
|
||||
}
|
||||
|
||||
func newClientWithServer(ts *httptest.Server) *wps.WeiPinShangClient {
|
||||
return wps.NewWeiPinShangClient(wps.WpsConfig{
|
||||
BaseURL: wps.DevHost,
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetGoodBrand(t *testing.T) {
|
||||
ts := setupMockServer(wps.GetGoodBrandURL, http.MethodPost, `{"code":200,"data":{"brands":[]}}`, t)
|
||||
defer ts.Close()
|
||||
client := newClientWithServer(ts)
|
||||
res, err := client.GetGoodBrand(wps.GoodBrandReq{
|
||||
PageNo: "1",
|
||||
PageSize: "100",
|
||||
CBrandName: "",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
||||
|
||||
func TestGetGoodsClassify(t *testing.T) {
|
||||
ts := setupMockServer(wps.GetGoodsClassifyURL, http.MethodPost, `{"code":200,"data":{"classify":[]}}`, t)
|
||||
defer ts.Close()
|
||||
|
||||
client := newClientWithServer(ts)
|
||||
res, err := client.GetGoodsClassify(wps.GetGoodsClassifyReq{
|
||||
CLevel: "2",
|
||||
CParentCode: "13315",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
||||
|
||||
func TestGetGoodsList(t *testing.T) {
|
||||
ts := setupMockServer(wps.GetGoodsListURL, http.MethodPost, `{"code":200,"data":{"goods":[]}}`, t)
|
||||
defer ts.Close()
|
||||
|
||||
client := newClientWithServer(ts)
|
||||
res, err := client.GetGoodsList(wps.GetGoodsListReq{
|
||||
PageNo: "1",
|
||||
PageSize: "10",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
||||
|
||||
func TestGetGoodsdept(t *testing.T) {
|
||||
ts := setupMockServer(wps.GetGoodsdeptURL, http.MethodPost, `{"code":200,"data":{"list":[]}}`, t)
|
||||
defer ts.Close()
|
||||
|
||||
client := newClientWithServer(ts)
|
||||
res, err := client.GetGoodsdept(wps.GetGoodsdeptReq{
|
||||
PageNo: "1",
|
||||
PageSize: "100",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
||||
|
||||
func TestGetDetailsGoods(t *testing.T) {
|
||||
ts := setupMockServer(wps.GetDetailsGoodsUrl, http.MethodPost, `{"code":200,"data":{"details":[]}}`, t)
|
||||
defer ts.Close()
|
||||
|
||||
client := newClientWithServer(ts)
|
||||
res, err := client.GetDetailsGoods(wps.GetDetailsGoodsReq{
|
||||
FatherId: "WPS9_54846554",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
||||
|
||||
func TestGetGoodsDetails(t *testing.T) {
|
||||
ts := setupMockServer(wps.GetGoodsDetailsURL, http.MethodPost, `{"code":200,"data":{"goodsInfo":{}}}`, t)
|
||||
defer ts.Close()
|
||||
|
||||
client := newClientWithServer(ts)
|
||||
res, err := client.GetGoodsDetails(wps.GetGoodsDetailsReq{
|
||||
FatherId: "WPS9_282520",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
||||
|
||||
func TestGetGoodsStock(t *testing.T) {
|
||||
ts := setupMockServer(wps.GetGoodsStockURL, http.MethodPost, `{"code":200,"data":{"stocks":[]}}`, t)
|
||||
defer ts.Close()
|
||||
|
||||
client := newClientWithServer(ts)
|
||||
res, err := client.GetGoodsStock(wps.GetGoodsStockReq{
|
||||
FatherId: "WPS9_282520",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, res)
|
||||
}
|
201
weipinshang/model.go
Normal file
201
weipinshang/model.go
Normal file
@ -0,0 +1,201 @@
|
||||
package wps
|
||||
|
||||
//type BaseRes struct {
|
||||
// Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||
// Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||
// Data interface{} `json:"data"` //返回数据
|
||||
//}
|
||||
|
||||
// GoodBrandReq 查询商品的品牌
|
||||
type GoodBrandReq struct {
|
||||
PageNo string `json:"pageNo"` //页码
|
||||
PageSize string `json:"pageSize"` //条数
|
||||
CBrandName string `json:"c_brand_name"` //品牌名称 模糊查询
|
||||
}
|
||||
|
||||
type GoodBrandRes struct {
|
||||
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||
Data GoodBrandList `json:"data"` //返回数据
|
||||
}
|
||||
|
||||
type GoodBrandList struct {
|
||||
PageIndex interface{} `json:"pageIndex"` //有时是字符串,有时是int
|
||||
PageCount int `json:"pageCount"`
|
||||
DataCount int `json:"dataCount"`
|
||||
List []GoodBrand `json:"list"`
|
||||
}
|
||||
|
||||
type GoodBrand struct {
|
||||
CId int `json:"c_id"` //自增id
|
||||
CBrandName string `json:"c_brand_name"` //名称
|
||||
CBrandLogoUrl string `json:"c_brand_logo_url"` //logo地址
|
||||
CCreateTime string `json:"c_create_time"`
|
||||
CUpdateTime string `json:"c_update_time"`
|
||||
}
|
||||
|
||||
// GetGoodsClassifyReq 查询商品分类
|
||||
type GetGoodsClassifyReq struct {
|
||||
CLevel string `json:"c_level"` //分类层级,1为一级分类 2为二级分类 3为三级分类(不传默认为1)
|
||||
CParentCode string `json:"c_parent_code"` //上级分类code
|
||||
}
|
||||
|
||||
type GetGoodsClassifyRes struct {
|
||||
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||
Data []GoodsClassify `json:"data"` //返回数据
|
||||
}
|
||||
|
||||
type GoodsClassify struct {
|
||||
CId int `json:"c_id"` //自增id
|
||||
CName string `json:"c_name"` //名称
|
||||
CCode string `json:"c_code"` //分类code
|
||||
CLevel int `json:"c_level"` //层级
|
||||
CParentCode string `json:"c_parent_code"` //上级code
|
||||
}
|
||||
|
||||
// GetGoodsListReq 获取全部商品列表接口(若使用该接口 需跟对接人说明,开启商品消息全推)
|
||||
type GetGoodsListReq struct {
|
||||
PageNo string `json:"pageNo"` //页码 [默认查询第1页]
|
||||
PageSize string `json:"pageSize"` //显示条数 [默认显示10条 最大值100]
|
||||
IsSort int `json:"is_sort"` //排序 [不传默认为正序,传1为倒序]
|
||||
ProfitSpace int `json:"profitSpace"` //利润空间 [1=>5%以下,2=>5%-10%,3=>10%-20%,4=>20%-50%,5=>50%-100%,6=>100%-200%,7=>200%-500%,8=>500%-700%,9=>700%-900%,10=>900%以上]
|
||||
}
|
||||
|
||||
type GetGoodsListRes struct {
|
||||
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||
Data GetGoodsList `json:"data"` //返回数据
|
||||
}
|
||||
|
||||
type GetGoodsList struct {
|
||||
PageIndex string `json:"pageIndex"`
|
||||
PageCount int `json:"pageCount"`
|
||||
DataCount int `json:"dataCount"`
|
||||
List []Goods `json:"list"`
|
||||
}
|
||||
|
||||
type Goods struct {
|
||||
CId int `json:"c_id"` // 序号(商品ID)
|
||||
CFatherGoodsId string `json:"c_father_goods_id"` // 商品父类ID
|
||||
CGoodsName string `json:"c_goods_name"` // 商品名称
|
||||
CGoodsImage string `json:"c_goods_image"` // 商品图片(1张商品主图)
|
||||
CClassId int `json:"c_class_id"` // 分类ID(一级)
|
||||
CClassDesc string `json:"c_class_desc"` // 分类描述(一级)
|
||||
CClass2Id int `json:"c_class2_id"` // 二级分类ID
|
||||
CClass2Desc string `json:"c_class2_desc"` // 二级分类描述
|
||||
CBrandId int `json:"c_brand_id"` // 品牌ID
|
||||
CBrandName string `json:"c_brand_name"` // 品牌名称
|
||||
CNoDeliveryArea string `json:"c_no_delivery_area"` // 不发货地区,为 "0" 或 "" 表示不限
|
||||
CStartDatetime string `json:"c_start_datetime"` // 上架时间(格式:yyyy-MM-dd HH:mm:ss)
|
||||
CStopDatetime string `json:"c_stop_datetime"` // 下架时间(格式:yyyy-MM-dd HH:mm:ss)
|
||||
COriginalPrice string `json:"c_original_price"` // 商品原价(吊牌价)
|
||||
CSalePrice string `json:"c_sale_price"` // 建议售价
|
||||
CInPrice string `json:"c_in_price"` // 进货价格
|
||||
CGoodsStockValid int `json:"c_goods_stock_valid"` // 当前有效库存(下单库存,不足时下单失败)
|
||||
CGoodsStockStart int `json:"c_goods_stock_start"` // 原始库存(商品录入时库存)
|
||||
CSpecifications string `json:"c_specifications"` // 商品详细规格(商品属性描述)
|
||||
CCompanyCode string `json:"c_company_code"` // 供应商编码
|
||||
}
|
||||
|
||||
// GetGoodsdeptReq (推荐使用)获取后台已选商品列表接口
|
||||
type GetGoodsdeptReq struct {
|
||||
PageNo string `json:"pageNo"` //页码 [默认查询第1页]
|
||||
PageSize string `json:"pageSize"` //显示条数 [默认显示10条 最大值100]
|
||||
ProfitSpace int `json:"profitSpace"` //利润空间 [1=>5%以下,2=>5%-10%,3=>10%-20%,4=>20%-50%,5=>50%-100%,6=>100%-200%,7=>200%-500%,8=>500%-700%,9=>700%-900%,10=>900%以上]
|
||||
}
|
||||
|
||||
type GetGoodsdeptRes struct {
|
||||
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||
Data Goodsdept `json:"data"` //返回数据
|
||||
}
|
||||
|
||||
type Goodsdept struct {
|
||||
PageIndex interface{} `json:"pageIndex"`
|
||||
PageCount int `json:"pageCount"`
|
||||
DataCount int `json:"dataCount"`
|
||||
List []Goods `json:"list"`
|
||||
}
|
||||
|
||||
// GetDetailsGoodsReq 获取批量商品详情接口
|
||||
type GetDetailsGoodsReq struct {
|
||||
FatherId string `json:"father_id"` //商品父级ID Spu编码
|
||||
}
|
||||
|
||||
type GetDetailsGoodsRes struct {
|
||||
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||
Data []GoodsItem `json:"data"` //返回数据
|
||||
}
|
||||
|
||||
type GoodsItem struct {
|
||||
CExhibitionID string `json:"c_exhibition_id"` // 会场ID(特卖商品时有值)
|
||||
CFatherGoodsID string `json:"c_father_goods_id"` // 父级商品ID
|
||||
CGoodsName string `json:"c_goods_name"` // 商品名称
|
||||
CGoodsDescription string `json:"c_goods_description"` // 商品描述
|
||||
CNoDeliveryArea string `json:"c_no_delivery_area"` // 不发货地区,为"0"或""表示不限
|
||||
COriginalPrice string `json:"c_original_price"` // 商品原价(吊牌价)
|
||||
CInPrice string `json:"c_in_price"` // 商品进价
|
||||
CSalePrice string `json:"c_sale_price"` // 商品建议售价
|
||||
CGoodsImage string `json:"c_goods_image"` // 商品主图
|
||||
CDetailsImages string `json:"c_details_images"` // 商品详情图(多图用“;”分隔)
|
||||
CBannerImages string `json:"c_banner_images"` // 商品banner图(多图用“;”分隔)
|
||||
CBrandID int `json:"c_brand_id"` // 品牌ID
|
||||
CBrandIcon string `json:"c_brand_icon"` // 品牌图标
|
||||
CBrandName string `json:"c_brand_name"` // 品牌名称
|
||||
CClassID int `json:"c_class_id"` // 一级分类ID
|
||||
CClassDesc string `json:"c_class_desc"` // 一级分类描述
|
||||
CClass2ID int `json:"c_class2_id"` // 二级分类ID
|
||||
CClass2Desc string `json:"c_class2_desc"` // 二级分类描述
|
||||
CClass3ID int `json:"c_class3_id"` // 三级分类ID
|
||||
CClass3Desc string `json:"c_class3_desc"` // 三级分类描述
|
||||
CIsShow int `json:"c_is_show"` // 商品状态:0下架,1上架
|
||||
CStartDatetime string `json:"c_start_datetime"` // 上架时间
|
||||
CStopDatetime string `json:"c_stop_datetime"` // 下架时间
|
||||
CSpecifications string `json:"c_specifications"` // 商品详细规格(商品属性描述)
|
||||
CCompanyCode string `json:"c_company_code"` // 供应商编码
|
||||
GoodsSku []GoodsSkuItem `json:"goods_sku"` // 商品SKU列表
|
||||
}
|
||||
|
||||
// 商品SKU信息
|
||||
type GoodsSkuItem struct {
|
||||
CFatherGoodsID string `json:"c_father_goods_id"` // 父级商品ID
|
||||
CGoodsID string `json:"c_goods_id"` // 商品ID
|
||||
CGoodsName string `json:"c_goods_name"` // 商品规格名称
|
||||
COriginalPrice string `json:"c_original_price"` // 商品市场价
|
||||
CInPrice string `json:"c_in_price"` // 商品进价
|
||||
CSalePrice string `json:"c_sale_price"` // 商品建议售价
|
||||
CGoodsColor string `json:"c_goods_color"` // 商品颜色
|
||||
CGoodsSize string `json:"c_goods_size"` // 商品尺寸
|
||||
CGoodsImage string `json:"c_goods_image"` // 商品列表图片
|
||||
CGoodsStockStart int `json:"c_goods_stock_start"` // 初始总库存
|
||||
CGoodsStockValid int `json:"c_goods_stock_valid"` // 有效库存(下单库存参考)
|
||||
CBuyMinNum int `json:"c_buy_min_num"` // 最小购买数量
|
||||
CBuyMaxNum int `json:"c_buy_max_num"` // 最大购买数量
|
||||
}
|
||||
|
||||
type GetGoodsDetailsReq struct {
|
||||
FatherId string `json:"father_id"` //商品父级ID Spu编码
|
||||
}
|
||||
|
||||
type GetGoodsDetailsRes struct {
|
||||
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||
Data GoodsItem `json:"data"` //返回数据
|
||||
}
|
||||
|
||||
type GetGoodsStockReq struct {
|
||||
FatherId string `json:"father_id"` //商品父级ID Spu编码
|
||||
}
|
||||
|
||||
type GetGoodsStockRes struct {
|
||||
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||
Data []GoodsStock `json:"data"` //返回数据
|
||||
}
|
||||
|
||||
type GoodsStock struct {
|
||||
CGoodsId string `json:"c_goods_id"`
|
||||
CStock int `json:"c_stock"`
|
||||
}
|
223
weipinshang/wei_pin_shang_client.go
Normal file
223
weipinshang/wei_pin_shang_client.go
Normal file
@ -0,0 +1,223 @@
|
||||
package wps
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
DevHost = "https://uat.api.weipinshang.net/"
|
||||
ReleaseHost = "https://api.weipinshang.net/"
|
||||
)
|
||||
|
||||
const (
|
||||
GetGoodBrandURL = "mcang/Mcang/goodBrand" //查询商品的品牌
|
||||
GetGoodsClassifyURL = "mcang/Mcang/getGoodsClassify" //查询商品分类
|
||||
GetGoodsListURL = "mcang/Mcang/getGoodsList" //获取全部商品列表接口
|
||||
GetGoodsdeptURL = "mcang/Mcang/getGoodsdept" //(推荐使用)获取后台已选商品列表接口
|
||||
GetDetailsGoodsUrl = "mcang/Mcang/getDetailsGoods" //获取批量商品详情接口
|
||||
GetGoodsDetailsURL = "mcang/Mcang/getGoodsDetails" //获取单个商品详情接口
|
||||
GetGoodsStockURL = "mcang/Mcang/getGoodsStock" //获取单个商品详情接口
|
||||
)
|
||||
|
||||
// Config 客户端配置
|
||||
type WpsConfig struct {
|
||||
ChannelType string
|
||||
Key string
|
||||
BaseURL string
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
// WeiPinShangClient 客户端结构体
|
||||
type WeiPinShangClient struct {
|
||||
ChannelType string
|
||||
Key string
|
||||
BaseURL string
|
||||
HttpClient *http.Client
|
||||
}
|
||||
|
||||
// NewWeiPinShangClient 创建客户端
|
||||
func NewWeiPinShangClient(cfg WpsConfig) *WeiPinShangClient {
|
||||
if cfg.ChannelType == "" {
|
||||
cfg.ChannelType = "AILEHUI"
|
||||
}
|
||||
if cfg.BaseURL == "" {
|
||||
cfg.BaseURL = ReleaseHost
|
||||
}
|
||||
if cfg.Key == "" {
|
||||
cfg.Key = "f654ea5bde7635c3f46191191e5c4c8e"
|
||||
}
|
||||
if cfg.Timeout == 0 {
|
||||
cfg.Timeout = 10 * time.Second
|
||||
}
|
||||
return &WeiPinShangClient{
|
||||
ChannelType: cfg.ChannelType,
|
||||
Key: cfg.Key,
|
||||
BaseURL: cfg.BaseURL,
|
||||
HttpClient: &http.Client{Timeout: cfg.Timeout},
|
||||
}
|
||||
}
|
||||
|
||||
// sign 生成签名
|
||||
func (c *WeiPinShangClient) sign(params map[string]string) string {
|
||||
keys := make([]string, 0, len(params))
|
||||
for k := range params {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
var sb strings.Builder
|
||||
for _, k := range keys {
|
||||
v := params[k]
|
||||
if v == "" {
|
||||
continue
|
||||
}
|
||||
sb.WriteString(k)
|
||||
sb.WriteString("=")
|
||||
sb.WriteString(v)
|
||||
sb.WriteString("&")
|
||||
}
|
||||
signStr := strings.TrimRight(sb.String(), "&") + c.ChannelType + c.Key
|
||||
hash := md5.Sum([]byte(signStr))
|
||||
return hex.EncodeToString(hash[:])
|
||||
}
|
||||
|
||||
// buildHeaders 构建请求头
|
||||
func (c *WeiPinShangClient) buildHeaders(params map[string]string) http.Header {
|
||||
headers := http.Header{}
|
||||
headers.Set("channelType", c.ChannelType)
|
||||
headers.Set("md5", c.sign(params))
|
||||
headers.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
return headers
|
||||
}
|
||||
|
||||
// buildRequest 构造请求对象
|
||||
func (c *WeiPinShangClient) buildRequest(method, endpoint string, params map[string]string) (*http.Request, error) {
|
||||
var (
|
||||
req *http.Request
|
||||
err error
|
||||
)
|
||||
|
||||
if method == http.MethodPost {
|
||||
form := url.Values{}
|
||||
for k, v := range params {
|
||||
form.Set(k, v)
|
||||
}
|
||||
req, err = http.NewRequest(method, c.BaseURL+endpoint, strings.NewReader(form.Encode()))
|
||||
} else {
|
||||
query := url.Values{}
|
||||
for k, v := range params {
|
||||
query.Set(k, v)
|
||||
}
|
||||
req, err = http.NewRequest(method, fmt.Sprintf("%s%s?%s", c.BaseURL, endpoint, query.Encode()), nil)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("构建请求失败,地址:%s,err:%v", endpoint, err.Error())
|
||||
}
|
||||
req.Header = c.buildHeaders(params)
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// doRequest 执行请求并返回字符串响应
|
||||
func (c *WeiPinShangClient) doRequest(req *http.Request) (string, error) {
|
||||
resp, err := c.HttpClient.Do(req)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "HTTP request failed")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return "", fmt.Errorf("HTTP status error: %s", resp.Status)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("读取response body失败。err:%v", err.Error())
|
||||
}
|
||||
return string(body), nil
|
||||
}
|
||||
|
||||
// Post 发起 POST 请求
|
||||
func (c *WeiPinShangClient) Post(endpoint string, params map[string]string) (string, error) {
|
||||
req, err := c.buildRequest(http.MethodPost, endpoint, params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return c.doRequest(req)
|
||||
}
|
||||
|
||||
// Get 发起 GET 请求
|
||||
func (c *WeiPinShangClient) Get(endpoint string, params map[string]string) (string, error) {
|
||||
req, err := c.buildRequest(http.MethodGet, endpoint, params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return c.doRequest(req)
|
||||
}
|
||||
|
||||
// GetAndParse 发起 GET 请求并解析 JSON 响应
|
||||
func (c *WeiPinShangClient) GetAndParse(endpoint string, params map[string]string, out interface{}) error {
|
||||
respStr, err := c.Get(endpoint, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return json.Unmarshal([]byte(respStr), out)
|
||||
}
|
||||
|
||||
// PostAndParse 发起 POST 请求并解析 JSON 响应
|
||||
func (c *WeiPinShangClient) PostAndParse(endpoint string, params map[string]string, out interface{}) error {
|
||||
respStr, err := c.Post(endpoint, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return json.Unmarshal([]byte(respStr), out)
|
||||
}
|
||||
|
||||
func StructToMapString(obj interface{}) map[string]string {
|
||||
result := make(map[string]string)
|
||||
|
||||
v := reflect.ValueOf(obj)
|
||||
t := reflect.TypeOf(obj)
|
||||
|
||||
// 支持结构体指针
|
||||
if v.Kind() == reflect.Ptr {
|
||||
v = v.Elem()
|
||||
t = t.Elem()
|
||||
}
|
||||
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
field := t.Field(i)
|
||||
valueField := v.Field(i)
|
||||
|
||||
// 只导出可访问的字段
|
||||
if !valueField.CanInterface() {
|
||||
continue
|
||||
}
|
||||
|
||||
// 判断是否为零值
|
||||
if reflect.DeepEqual(valueField.Interface(), reflect.Zero(valueField.Type()).Interface()) {
|
||||
continue
|
||||
}
|
||||
|
||||
key := field.Tag.Get("json")
|
||||
if key == "" {
|
||||
key = field.Name
|
||||
}
|
||||
|
||||
result[key] = fmt.Sprintf("%v", valueField.Interface())
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
68
weipinshang_api/req.go
Normal file
68
weipinshang_api/req.go
Normal file
@ -0,0 +1,68 @@
|
||||
package weipinshang_api
|
||||
|
||||
type CreateAfsApplyReq struct {
|
||||
McOrderNo string `json:"mcOrderNo"` // 子订单号 是 int 下单时候返回子订单号 20190704124955600363
|
||||
CustomerExpect int `json:"customerExpect"` // 售后类型 是 int [退货(10)、仅退款(40)] 10
|
||||
QuestionDesc string `json:"questionDesc"` // 原因描述 否 String [产品问题描述,最多600字符] 看下面请求示例
|
||||
QuestionPic string `json:"questionPic"` //问题描述图片 否 String [问题描述图片.最多2000字符] 支持多张图片,用逗号分隔(英文逗号)
|
||||
CustomerContactName string `json:"customerContactName"` // 用户姓名 是 String [用户姓名] 张三
|
||||
CustomerTel string `json:"customerTel"` // 用户电话 是 String [用户电话] 18533136240
|
||||
CustomerMobilePhone string `json:"customerMobilePhone"` // 用户手机 是 String [用户手机] 18533136240
|
||||
PickwareProvince string `json:"pickwareProvince"` //省份 是 String [省份] 湖南
|
||||
PickwareCity string `json:"pickwareCity"` // 城市 是 String [城市] 长沙
|
||||
PickwareCounty string `json:"pickwareCounty"` // 县区 是 String [县区] 芙蓉区
|
||||
PickwareAddress string `json:"pickwareAddress"` //详细地址 是 String [县区] 塔南路59号2号楼2单元1301室
|
||||
}
|
||||
|
||||
type GetManyPostageReq struct {
|
||||
GoodsInfo string `json:"goodsInfo"` //商品数组 goodsInfo 是 json 需要转成json形式的字符串
|
||||
Address string `json:"address"` // 详细地址 address 是 String
|
||||
County string `json:"county"` // 区 county 是 String
|
||||
Province string `json:"province"` //省份 province 是 String
|
||||
City string `json:"city"` //城市 city 是 String
|
||||
}
|
||||
|
||||
type PreOrderReq struct {
|
||||
LockCode string `json:"lockCode"` //预下单编码 lockCode 是 String
|
||||
ConsigneeContacts string `json:"consigneeContacts"` //收货人姓名 consigneeContacts 是 String
|
||||
ConsigneePhone string `json:"consigneePhone"` //收货人手机号 consigneePhone 是 String
|
||||
Province string `json:"province"` //省份 province 是 String
|
||||
City string `json:"city"` //城市 city 是 String
|
||||
Address string `json:"address"` // 详细地址 address 是 String
|
||||
Area string `json:"area"` //区 area 是 String 区
|
||||
GoodsInfo string `json:"goodsInfo"` //商品数组 goodsInfo 是 json 需要转成json形式的字符串
|
||||
Source string `json:"source"` //订单来源 请求渠道号
|
||||
}
|
||||
|
||||
type GoodsInfo struct {
|
||||
GoodSpecId string `json:"goodSpecId"` //SKU ID goodSpecId 是 String 商品ID(c_goods_id)
|
||||
GoodsId string `json:"goodsId"` //商品ID goodsId 是 String 商品父ID(c_father_goods_id)
|
||||
Num string `json:"num"` // 数量
|
||||
}
|
||||
|
||||
type CreateOrderReq struct {
|
||||
LockCode string `json:"lockCode"` //预下单编码 lockCode 是 String
|
||||
OrderNo string `json:"orderNo"` //对接方业务单号 orderNo 是 String
|
||||
NoticeUrl string `json:"noticeUrl"` //合作方通知地址 noticeUrl 否 String 规定值 如支持,订单更新实时通知。此参数可不用传,统一走异步回调
|
||||
}
|
||||
|
||||
type RefundDeliveryReq struct {
|
||||
McOrderNo string `json:"mcOrderNo"` // 子订单号 是 int 下单时候返回子订单号 20190704124955600363
|
||||
DeliveryName string `json:"deliveryName"` // 快递公司
|
||||
DeliveryNo string `json:"deliveryNo"` // 快递单号
|
||||
Freight string `json:"freight"` // 运费金额 freight 否 string 单位:元
|
||||
FreightImg string `json:"freightImg"` // 运费支付凭证 freightImg 否 string 图片地址
|
||||
}
|
||||
|
||||
// test ------------------------------------------------
|
||||
|
||||
type DeliverGoodsReq struct {
|
||||
COrderItemNo string `json:"c_order_item_no"` //c_order_item_no 子订单号 是 int 下单时候返回子订单号 20190704124955600363
|
||||
CDeliveryName string `json:"c_delivery_name"` // 快递公司
|
||||
CDeliveryNo string `json:"c_delivery_no"` // 快递单号
|
||||
}
|
||||
|
||||
type UpdateServiceReq struct {
|
||||
COrderItemNo string `json:"c_order_item_no"` //c_order_item_no 子订单号 是 int 下单时候返回子订单号 20190704124955600363
|
||||
CType string `json:"c_type"` //c_type 快递名称 是 String [处理类型 1 同意售后 2 拒绝 3 退款完成]
|
||||
}
|
138
weipinshang_api/res.go
Normal file
138
weipinshang_api/res.go
Normal file
@ -0,0 +1,138 @@
|
||||
package weipinshang_api
|
||||
|
||||
type GetManyPostageRes struct {
|
||||
Code int `json:"code"` // 0为成功,其它为失败
|
||||
Msg string `json:"msg"` // 请求接口消息
|
||||
Data FreightData `json:"data"` // 返回数据 data array
|
||||
}
|
||||
type FreightData struct {
|
||||
Freight string `json:"freight"` // 邮费 freight 是 string 邮费
|
||||
}
|
||||
|
||||
type PreOrderRes struct {
|
||||
Code int `json:"code"` // 0为成功,其它为失败
|
||||
Msg string `json:"msg"` // 请求接口消息
|
||||
Data PreOrderFreightData `json:"data"` // 返回数据 data array
|
||||
}
|
||||
type PreOrderFreightData struct {
|
||||
Freight string `json:"freight"` // 邮费 freight 是 string 邮费
|
||||
FreightDesc string `json:"freight_desc"` // 邮费说明 freight_desc 是 string 邮费说明
|
||||
}
|
||||
|
||||
type CreateOrderRes struct {
|
||||
Code int `json:"code"` // 0为成功,其它为失败
|
||||
Msg string `json:"msg"` // 请求接口消息
|
||||
Data []CreateOrderData `json:"data"` // 返回数据 data array
|
||||
}
|
||||
type CreateOrderData struct {
|
||||
ThirdOrderNo string `json:"thirdOrderNo"` // 第三方订单号 本地订单号
|
||||
OrderNo string `json:"orderNo"` // 主订单号
|
||||
McOrderNo string `json:"mcOrderNo"` //蜜仓子订单号
|
||||
OrderAmount float64 `json:"orderAmount"` // 子订单总金额
|
||||
Sku []SkuData `json:"sku"` // 订单商品信息
|
||||
}
|
||||
|
||||
type SkuData struct {
|
||||
GoodSpecId string `json:"goodSpecId"` //商品ID(c_goods_id)
|
||||
GoodsId string `json:"goodsId"` //商品ID(c_father_goods_id)
|
||||
GoodName string `json:"goodName"` //商品名称
|
||||
Num interface{} `json:"num"` //数量
|
||||
//Num int `json:"num"` //数量
|
||||
Price string `json:"price"` //单价
|
||||
}
|
||||
|
||||
type GetOrderInfoRes struct {
|
||||
Code int `json:"code"` // 0为成功,其它为失败
|
||||
Msg string `json:"msg"` // 请求接口消息
|
||||
Data []Data `json:"data"` // 返回数据 data array
|
||||
}
|
||||
type Data struct {
|
||||
CThirdUserCode string `json:"c_third_user_code"` // 用户编码
|
||||
//COrderNoThird string `json:"c_order_no_third"` // 渠道订单号
|
||||
COrderNo string `json:"c_order_no"` // 渠道订单号
|
||||
COrderNoPayservice string `json:"c_order_no_payservice"` //支付订单号
|
||||
CSendStatus string `json:"c_send_status"` // 订单状态 订单所处阶段【’’CHECKED订单被创建’’,’INSTOCK已备货’,’’SENDED已发货’’,’’RECEIVED已收货’’】
|
||||
CIsPay int `json:"c_is_pay"` // 支付状态(0-未支付,1-已支付)
|
||||
CIsClose int `json:"c_is_close"` // 关闭状态 c_is_close 是否关闭【0未关闭,1,已经关闭】
|
||||
CShouldPay float64 `json:"c_should_pay"` // 订单应付金额 单位:元
|
||||
CRealPay float64 `json:"c_real_pay"` // 实际支付金额 c_real_pay 单位:元
|
||||
CMessage string `json:"c_message"` // 订单留言
|
||||
CComment string `json:"c_comment"` // 系统操作备注
|
||||
CDeliveryName string `json:"c_delivery_name"` // 快递公司
|
||||
CDeliveryNo string `json:"c_delivery_no"` // 快递单号
|
||||
CCreateDatetime string `json:"c_create_datetime"` // 订单创建时间
|
||||
CPayDatetime string `json:"c_pay_datetime"` // 订单支付时间
|
||||
CSendDatetime string `json:"c_send_datetime"` // 订单发货时间
|
||||
CReceiveDatetime string `json:"c_receive_datetime"` // 订单确认收货时间
|
||||
CReceiverName string `json:"c_receiver_name"` // 收货人姓名
|
||||
CReceiverMobile string `json:"c_receiver_mobile"` // 收货人联系方式
|
||||
}
|
||||
|
||||
type GetOrderInfoByItemNORes struct {
|
||||
Code int `json:"code"` // 0为成功,其它为失败
|
||||
Msg string `json:"msg"` // 请求接口消息
|
||||
Data OrderInfoByItemNOData `json:"data"` // 返回数据 data array
|
||||
|
||||
}
|
||||
type OrderInfoByItemNOData struct {
|
||||
OrderItemNo string `json:"order_item_no"` // 子订单号
|
||||
SendStatus string `json:"send_status"` //发货状态【’CHECKED订单被创建’,’INSTOCK已备货’,’SENDED已发货’,’RECEIVED已收货’】
|
||||
DeliveryName string `json:"delivery_name"` // 快递公司
|
||||
DeliveryNo string `json:"delivery_no"` // 快递单号
|
||||
RefuseStatus string `json:"refuse_status"` //售后状态【CREATED 创建售后单’,’ALLOW同意’,’SUCCESS成功’,’NOTALLOW拒绝’,’MONEY_RETURNED已操作退款’,’FAIL_RETURNED退款失败,线下退款’】
|
||||
RefuseType string `json:"refuse_type"` // 售后类型【’RETURN_MONEY 退款’,’RETURN_GOODS 退货’】
|
||||
}
|
||||
|
||||
type GetOrderInfoByThirdNORes struct {
|
||||
Code int `json:"code"` // 0为成功,其它为失败
|
||||
Msg string `json:"msg"` // 请求接口消息
|
||||
Data []OrderInfoData `json:"data"` // 返回数据 data array
|
||||
}
|
||||
type OrderInfoData struct {
|
||||
GoodsId string `json:"goodsId"` //商品ID goodsId 是 String 商品父ID(c_father_goods_id)
|
||||
GoodSpecId string `json:"goodSpecId"` //SKU ID goodSpecId 是 String 商品ID(c_goods_id)
|
||||
OrderItemNo string `json:"order_item_no"` // 子订单号
|
||||
SendStatus string `json:"send_status"` //发货状态【’CHECKED订单被创建’,’INSTOCK已备货’,’SENDED已发货’,’RECEIVED已收货’】
|
||||
DeliveryName string `json:"delivery_name"` // 快递公司
|
||||
DeliveryNo string `json:"delivery_no"` // 快递单号
|
||||
}
|
||||
|
||||
type IsRefundRes struct {
|
||||
Code int `json:"code"` // 0为成功,其它为失败
|
||||
Msg string `json:"msg"` // 请求接口消息
|
||||
Data IsRefundData `json:"data"` // 返回数据 data array
|
||||
|
||||
}
|
||||
|
||||
type IsRefundData struct {
|
||||
ResultType []Param `json:"resultType"` // 售后类型
|
||||
WareReturn []Param `json:"wareReturn"` // 服务类型
|
||||
}
|
||||
|
||||
type Param struct {
|
||||
Code int `json:"code"` // 服务类型码 4 [上门取件(4)、客户发货(40)、客户送货(7)]
|
||||
Name string `json:"name"` // 服务类型名称 上门取件 [上门取件、客户发货、客户送货]
|
||||
}
|
||||
|
||||
type CreateAfsApplyRes struct {
|
||||
Code int `json:"code"` // 0为成功,其它为失败
|
||||
Msg string `json:"msg"` // 请求接口消息
|
||||
Type string `json:"type"` // wait 等待。return_money:已退款
|
||||
}
|
||||
|
||||
type OrderCancelRes struct {
|
||||
Code int `json:"code"` // 0为成功,其它为失败
|
||||
Msg string `json:"msg"` // 请求接口消息
|
||||
}
|
||||
|
||||
type RefundDeliveryRes struct {
|
||||
Code int `json:"code"` // 0为成功,其它为失败
|
||||
Msg string `json:"msg"` // 请求接口消息
|
||||
}
|
||||
|
||||
// test -------------------------------------
|
||||
|
||||
type TestRes struct {
|
||||
Code int `json:"code"` // 0为成功,其它为失败
|
||||
Msg string `json:"msg"` // 请求接口消息
|
||||
}
|
75
weipinshang_api/sign.go
Normal file
75
weipinshang_api/sign.go
Normal file
@ -0,0 +1,75 @@
|
||||
package weipinshang_api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func SortedString(data any) string {
|
||||
// 1. 序列化成 JSON
|
||||
dataBytes, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 2. 反序列化成 map[string]interface{}
|
||||
var tmp map[string]interface{}
|
||||
if err = json.Unmarshal(dataBytes, &tmp); err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 3. 提取并排序 keys
|
||||
keys := make([]string, 0, len(tmp))
|
||||
for k := range tmp {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
// 4. 构建键值对字符串
|
||||
var sortedParams []string
|
||||
for _, key := range keys {
|
||||
if key == "hmac" {
|
||||
continue // 跳过 hmac 字段
|
||||
}
|
||||
|
||||
value := tmp[key]
|
||||
strValue, err := valueToString(value)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
sortedParams = append(sortedParams, fmt.Sprintf("%s=%s", key, strValue))
|
||||
}
|
||||
return strings.Join(sortedParams, "&")
|
||||
}
|
||||
|
||||
// valueToString 将任意 JSON 值转换为字符串
|
||||
func valueToString(v interface{}) (string, error) {
|
||||
switch i := v.(type) {
|
||||
case string:
|
||||
return i, nil
|
||||
case bool:
|
||||
return strconv.FormatBool(i), nil
|
||||
case float64:
|
||||
// 判断是否是整数(如 2.0 → "2")
|
||||
if i == float64(int64(i)) {
|
||||
return strconv.FormatInt(int64(i), 10), nil
|
||||
}
|
||||
return strconv.FormatFloat(i, 'f', -1, 64), nil
|
||||
case json.Number:
|
||||
return i.String(), nil // 如果使用 json.Number,直接返回其字符串形式
|
||||
case nil:
|
||||
return "", nil
|
||||
case map[string]interface{}, []interface{}:
|
||||
// 如果是嵌套结构,重新序列化成 JSON
|
||||
bytes, err := json.Marshal(i)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(bytes), nil
|
||||
default:
|
||||
return "", fmt.Errorf("unsupported type: %T", i)
|
||||
}
|
||||
}
|
348
weipinshang_api/wei_pin_shang_client.go
Normal file
348
weipinshang_api/wei_pin_shang_client.go
Normal file
@ -0,0 +1,348 @@
|
||||
package weipinshang_api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type WeiPinShangClient struct {
|
||||
Host string
|
||||
ChannelType string
|
||||
Key string
|
||||
}
|
||||
|
||||
func NewWeiPinShangClient(host, channelType, key string) *WeiPinShangClient {
|
||||
return &WeiPinShangClient{
|
||||
Host: host,
|
||||
ChannelType: channelType,
|
||||
Key: key,
|
||||
}
|
||||
}
|
||||
|
||||
// pay
|
||||
|
||||
func (w *WeiPinShangClient) GetManyPostage(getManyPostageReq *GetManyPostageReq) (res *GetManyPostageRes, err error) {
|
||||
fmt.Println("getManyPostageReq", getManyPostageReq)
|
||||
paramMap := make(map[string]any)
|
||||
|
||||
paramMap["goodsInfo"] = getManyPostageReq.GoodsInfo
|
||||
paramMap["address"] = getManyPostageReq.Address
|
||||
paramMap["province"] = getManyPostageReq.Province
|
||||
paramMap["county"] = getManyPostageReq.County
|
||||
paramMap["city"] = getManyPostageReq.City
|
||||
|
||||
postRes, err := w.WPSPost("mcang/Mcang/getManyPostage", paramMap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(postRes, &res)
|
||||
if err != nil || res == nil {
|
||||
err = fmt.Errorf("转换GetManyPostageRes结构体失败: %s", string(postRes))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (w *WeiPinShangClient) PreOrder(preOrderReq *PreOrderReq) (res *PreOrderRes, err error) {
|
||||
fmt.Println("preOrderReq", preOrderReq)
|
||||
paramMap := make(map[string]any)
|
||||
paramMap["lockCode"] = preOrderReq.LockCode
|
||||
paramMap["consigneeContacts"] = preOrderReq.ConsigneeContacts
|
||||
paramMap["consigneePhone"] = preOrderReq.ConsigneePhone
|
||||
|
||||
paramMap["address"] = preOrderReq.Address
|
||||
paramMap["province"] = preOrderReq.Province
|
||||
paramMap["area"] = preOrderReq.Area
|
||||
paramMap["city"] = preOrderReq.City
|
||||
|
||||
paramMap["goodInfo"] = preOrderReq.GoodsInfo
|
||||
paramMap["source"] = preOrderReq.Source
|
||||
postRes, err := w.WPSPost("mcang/Order/preOrder", paramMap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(postRes, &res)
|
||||
if err != nil || res == nil {
|
||||
err = fmt.Errorf("转换PreOrderRes结构体失败: %s", string(postRes))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (w *WeiPinShangClient) CreateOrder(createOrderReq *CreateOrderReq) (res *CreateOrderRes, err error) {
|
||||
fmt.Println("createOrderReq", createOrderReq)
|
||||
paramMap := make(map[string]any)
|
||||
paramMap["lockCode"] = createOrderReq.LockCode
|
||||
paramMap["orderNo"] = createOrderReq.OrderNo
|
||||
paramMap["noticeUrl"] = createOrderReq.NoticeUrl
|
||||
postRes, err := w.WPSPost("mcang/Order/createOrder", paramMap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(postRes, &res)
|
||||
if err != nil || res == nil {
|
||||
err = fmt.Errorf("转换CreateOrderRes结构体失败: %s", string(postRes))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetOrderInfo 1
|
||||
|
||||
func (w *WeiPinShangClient) GetOrderInfo(orderNo string) (res *GetOrderInfoRes, err error) {
|
||||
fmt.Println("orderNo", orderNo)
|
||||
paramMap := make(map[string]any)
|
||||
paramMap["orderNo"] = orderNo
|
||||
postRes, err := w.WPSPost("mcang/Mcang/getOrderInfo", paramMap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(postRes, &res)
|
||||
if err != nil || res == nil {
|
||||
err = fmt.Errorf("转换GetOrderInfoRes结构体失败: %s", string(postRes))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetOrderInfo n
|
||||
|
||||
func (w *WeiPinShangClient) GetOrderInfoByThirdNO(orderNo string) (res *GetOrderInfoByThirdNORes, err error) {
|
||||
fmt.Println("orderNo", orderNo)
|
||||
paramMap := make(map[string]any)
|
||||
paramMap["orderNo"] = orderNo
|
||||
postRes, err := w.WPSPost("mcang/Order/getOrderInfoByThirdNO", paramMap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(postRes, &res)
|
||||
if err != nil || res == nil {
|
||||
err = fmt.Errorf("转换GetOrderInfoByThirdNORes结构体失败: %s", string(postRes))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// refund
|
||||
|
||||
func (w *WeiPinShangClient) GetOrderInfoByItemNO(mcOrderNo string) (res *GetOrderInfoByItemNORes, err error) {
|
||||
fmt.Println("mcOrderNo", mcOrderNo)
|
||||
paramMap := make(map[string]any)
|
||||
paramMap["mcOrderNo"] = mcOrderNo
|
||||
|
||||
postRes, err := w.WPSPost("mcang/Order/getOrderInfoByItemNO", paramMap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(postRes, &res)
|
||||
if err != nil || res == nil {
|
||||
err = fmt.Errorf("转换GetOrderInfoByItemNORes结构体失败: %s", string(postRes))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (w *WeiPinShangClient) IsRefund(mcOrderNo string) (res *IsRefundRes, err error) {
|
||||
fmt.Println("mcOrderNo", mcOrderNo)
|
||||
paramMap := make(map[string]any)
|
||||
paramMap["mcOrderNo"] = mcOrderNo
|
||||
postRes, err := w.WPSPost("mcang/Refunds/IsRefund", paramMap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(postRes, &res)
|
||||
if err != nil || res == nil {
|
||||
err = fmt.Errorf("转换IsRefundRes结构体失败: %s", string(postRes))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (w *WeiPinShangClient) CreateAfsApply(createAfsApplyReq *CreateAfsApplyReq) (res *CreateAfsApplyRes, err error) {
|
||||
fmt.Println("createAfsApplyReq", createAfsApplyReq)
|
||||
paramMap := make(map[string]any)
|
||||
|
||||
paramMap["mcOrderNo"] = createAfsApplyReq.McOrderNo
|
||||
|
||||
paramMap["customerExpect"] = createAfsApplyReq.CustomerExpect
|
||||
paramMap["questionDesc"] = createAfsApplyReq.QuestionDesc
|
||||
paramMap["questionPic"] = createAfsApplyReq.QuestionPic
|
||||
paramMap["customerContactName"] = createAfsApplyReq.CustomerContactName
|
||||
paramMap["customerMobilePhone"] = createAfsApplyReq.CustomerMobilePhone
|
||||
paramMap["customerTel"] = createAfsApplyReq.CustomerTel
|
||||
|
||||
paramMap["pickwareProvince"] = createAfsApplyReq.PickwareProvince
|
||||
paramMap["pickwareCity"] = createAfsApplyReq.PickwareCity
|
||||
paramMap["pickwareCounty"] = createAfsApplyReq.PickwareCounty
|
||||
paramMap["pickwareAddress"] = createAfsApplyReq.PickwareAddress
|
||||
|
||||
postRes, err := w.WPSPost("mcang/Refunds/createAfsApply", paramMap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(postRes, &res)
|
||||
if err != nil || res == nil {
|
||||
err = fmt.Errorf("转换CreateAfsApplyRes结构体失败: %s", string(postRes))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (w *WeiPinShangClient) OrderCancel(mcOrderNo string) (res *OrderCancelRes, err error) {
|
||||
fmt.Println("mcOrderNo", mcOrderNo)
|
||||
paramMap := make(map[string]any)
|
||||
paramMap["mcOrderNo"] = mcOrderNo
|
||||
postRes, err := w.WPSPost("mcang/Refunds/orderCancel", paramMap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(postRes, &res)
|
||||
if err != nil || res == nil {
|
||||
err = fmt.Errorf("转换OrderCancelRes结构体失败: %s", string(postRes))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (w *WeiPinShangClient) RefundDelivery(refundDeliveryReq RefundDeliveryReq) (res *RefundDeliveryRes, err error) {
|
||||
fmt.Println("refundDeliveryReq", refundDeliveryReq)
|
||||
paramMap := make(map[string]any)
|
||||
paramMap["mcOrderNo"] = refundDeliveryReq.McOrderNo
|
||||
paramMap["deliveryName"] = refundDeliveryReq.DeliveryName
|
||||
paramMap["deliveryNo"] = refundDeliveryReq.DeliveryNo
|
||||
paramMap["freight"] = refundDeliveryReq.Freight
|
||||
paramMap["freightImg"] = refundDeliveryReq.FreightImg
|
||||
postRes, err := w.WPSPost("mcang/Refunds/refundDelivery", paramMap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(postRes, &res)
|
||||
if err != nil || res == nil {
|
||||
err = fmt.Errorf("转换RefundDeliveryRes结构体失败: %s", string(postRes))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (w *WeiPinShangClient) Sign(paramMap map[string]any) (res string, err error) {
|
||||
var sumParamString string
|
||||
if len(paramMap) != 0 {
|
||||
sumParamString = SortedString(paramMap) + w.ChannelType + w.Key
|
||||
} else {
|
||||
sumParamString = w.ChannelType + w.Key
|
||||
}
|
||||
md5Sum := md5.Sum([]byte(sumParamString))
|
||||
md5Str := hex.EncodeToString(md5Sum[:])
|
||||
md5Str = strings.ToLower(md5Str)
|
||||
return md5Str, nil
|
||||
}
|
||||
|
||||
func (w *WeiPinShangClient) WPSPost(url string, paramMap map[string]any) (res []byte, err error) {
|
||||
|
||||
bodyByte, _ := json.Marshal(paramMap)
|
||||
|
||||
req, err := http.NewRequest("POST", w.Host+url, bytes.NewBuffer(bodyByte))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
//req.Proto = "HTTP/2"
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("channelType", w.ChannelType)
|
||||
sign, err := w.Sign(paramMap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Set("md5", sign)
|
||||
//log.Printf("WPSPost req: %+v\n", req)
|
||||
// 创建 HTTP 客户端
|
||||
client := &http.Client{}
|
||||
//log.Printf("WPSPost client: %+v\n", client)
|
||||
// 发送请求
|
||||
resp, err := client.Do(req)
|
||||
//log.Printf("WPSPost resp: %+v\n", resp)
|
||||
if err != nil {
|
||||
log.Printf("发送请求失败: %+v\n", err)
|
||||
return
|
||||
}
|
||||
defer func(Body io.ReadCloser) {
|
||||
_ = Body.Close()
|
||||
}(resp.Body)
|
||||
|
||||
// 读取响应体
|
||||
res, err = io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("res: %s\n", string(res))
|
||||
|
||||
if !json.Valid(res) {
|
||||
return nil, errors.New("响应体不是有效的JSON格式")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Test ----------------------------------------------------------------------------------------------
|
||||
|
||||
func (w *WeiPinShangClient) DeliverGoods(deliverGoodsReq *DeliverGoodsReq) (res *TestRes, err error) {
|
||||
fmt.Println("deliverGoodsReq", deliverGoodsReq)
|
||||
paramMap := make(map[string]any)
|
||||
paramMap["c_order_item_no"] = deliverGoodsReq.COrderItemNo
|
||||
paramMap["c_delivery_name"] = deliverGoodsReq.CDeliveryName
|
||||
paramMap["c_delivery_no"] = deliverGoodsReq.CDeliveryNo
|
||||
postRes, err := w.WPSPost("mcang/Cycle/deliverGoods", paramMap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(postRes, &res)
|
||||
if err != nil || res == nil {
|
||||
err = fmt.Errorf("转换TestRes结构体失败: %s", string(postRes))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (w *WeiPinShangClient) UpdateService(updateServiceReq *UpdateServiceReq) (res *TestRes, err error) {
|
||||
fmt.Println("updateServiceReq", updateServiceReq)
|
||||
paramMap := make(map[string]any)
|
||||
paramMap["c_order_item_no"] = updateServiceReq.COrderItemNo
|
||||
paramMap["c_type"] = updateServiceReq.CType
|
||||
postRes, err := w.WPSPost("mcang/Cycle/updateService", paramMap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(postRes, &res)
|
||||
if err != nil || res == nil {
|
||||
err = fmt.Errorf("转换TestRes结构体失败: %s", string(postRes))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
586
weipinshang_api/wei_pin_shang_client_test.go
Normal file
586
weipinshang_api/wei_pin_shang_client_test.go
Normal file
@ -0,0 +1,586 @@
|
||||
package weipinshang_api
|
||||
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWeiPinShangClient_GetManyPostage(t *testing.T) {
|
||||
type fields struct {
|
||||
Host string
|
||||
ChannelType string
|
||||
Key string
|
||||
}
|
||||
//type args struct {
|
||||
// ip string
|
||||
//}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args GetManyPostageReq
|
||||
wantRes *GetManyPostageRes
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
Host: "https://uat.api.weipinshang.net/",
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
},
|
||||
args: GetManyPostageReq{
|
||||
GoodsInfo: "[{\"goodsId\":\"WPS427_adf0008\",\"goodSpecId\":\"WPS427_0715110641454716\",\"num\":1}]",
|
||||
Province: "广东省",
|
||||
Address: "奥园",
|
||||
City: "广州市",
|
||||
County: "番禺区",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
h := &WeiPinShangClient{
|
||||
Host: test.fields.Host,
|
||||
ChannelType: test.fields.ChannelType,
|
||||
Key: test.fields.Key,
|
||||
}
|
||||
|
||||
gotRes, err := h.GetManyPostage(&test.args)
|
||||
|
||||
log.Println(gotRes, err)
|
||||
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeiPinShangClient_PreOrder(t *testing.T) {
|
||||
type fields struct {
|
||||
Host string
|
||||
ChannelType string
|
||||
Key string
|
||||
}
|
||||
//type args struct {
|
||||
// ip string
|
||||
//}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args PreOrderReq
|
||||
wantRes *PreOrderRes
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
Host: "https://uat.api.weipinshang.net/",
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
},
|
||||
args: PreOrderReq{
|
||||
GoodsInfo: "[{\"goodsId\":\"WPS427_adf0008\",\"goodSpecId\":\"WPS427_0715110641454716\",\"num\":1}]",
|
||||
Province: "广东省",
|
||||
Address: "奥园",
|
||||
City: "广州市",
|
||||
Area: "番禺区",
|
||||
ConsigneePhone: "15375390426",
|
||||
ConsigneeContacts: "张三",
|
||||
LockCode: "L100000005",
|
||||
Source: "AILEHUI",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
h := &WeiPinShangClient{
|
||||
Host: test.fields.Host,
|
||||
ChannelType: test.fields.ChannelType,
|
||||
Key: test.fields.Key,
|
||||
}
|
||||
|
||||
gotRes, err := h.PreOrder(&test.args)
|
||||
|
||||
log.Println(gotRes, err)
|
||||
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeiPinShangClient_CreateOrder(t *testing.T) {
|
||||
type fields struct {
|
||||
Host string
|
||||
ChannelType string
|
||||
Key string
|
||||
}
|
||||
//type args struct {
|
||||
// ip string
|
||||
//}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args CreateOrderReq
|
||||
wantRes *CreateOrderRes
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
Host: "https://uat.api.weipinshang.net/",
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
},
|
||||
args: CreateOrderReq{
|
||||
LockCode: "L100000004",
|
||||
OrderNo: "2000000004",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
h := &WeiPinShangClient{
|
||||
Host: test.fields.Host,
|
||||
ChannelType: test.fields.ChannelType,
|
||||
Key: test.fields.Key,
|
||||
}
|
||||
|
||||
gotRes, err := h.CreateOrder(&test.args)
|
||||
|
||||
log.Println(gotRes, err)
|
||||
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeiPinShangClient_GetOrderInfo(t *testing.T) {
|
||||
type fields struct {
|
||||
Host string
|
||||
ChannelType string
|
||||
Key string
|
||||
}
|
||||
type args struct {
|
||||
orderNo string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantRes *GetOrderInfoRes
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
Host: "https://uat.api.weipinshang.net/",
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
},
|
||||
args: args{
|
||||
//orderNo: "20250527172503439229",
|
||||
//orderNo: "10000000000",
|
||||
orderNo: "20000000000",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
h := &WeiPinShangClient{
|
||||
Host: test.fields.Host,
|
||||
ChannelType: test.fields.ChannelType,
|
||||
Key: test.fields.Key,
|
||||
}
|
||||
|
||||
gotRes, err := h.GetOrderInfo(test.args.orderNo)
|
||||
|
||||
log.Println(gotRes, err)
|
||||
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeiPinShangClient_GetOrderInfoByItemNO(t *testing.T) {
|
||||
type fields struct {
|
||||
Host string
|
||||
ChannelType string
|
||||
Key string
|
||||
}
|
||||
type args struct {
|
||||
mcOrderNo string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantRes *GetOrderInfoByItemNORes
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
Host: "https://uat.api.weipinshang.net/",
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
},
|
||||
args: args{
|
||||
//mcOrderNo: "mc20250527174640537475",
|
||||
mcOrderNo: "mc20250616115732440085",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
h := &WeiPinShangClient{
|
||||
Host: test.fields.Host,
|
||||
ChannelType: test.fields.ChannelType,
|
||||
Key: test.fields.Key,
|
||||
}
|
||||
|
||||
gotRes, err := h.GetOrderInfoByItemNO(test.args.mcOrderNo)
|
||||
|
||||
log.Println(gotRes, err)
|
||||
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeiPinShangClient_GetOrderInfoByThirdNO(t *testing.T) {
|
||||
type fields struct {
|
||||
Host string
|
||||
ChannelType string
|
||||
Key string
|
||||
}
|
||||
type args struct {
|
||||
orderNo string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantRes *GetOrderInfoByThirdNORes
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
Host: "https://uat.api.weipinshang.net/",
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
},
|
||||
args: args{
|
||||
//orderNo: "10000000000",
|
||||
orderNo: "20000000000",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
Host: "https://uat.api.weipinshang.net/",
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
},
|
||||
args: args{
|
||||
orderNo: "570853643339733632",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
h := &WeiPinShangClient{
|
||||
Host: test.fields.Host,
|
||||
ChannelType: test.fields.ChannelType,
|
||||
Key: test.fields.Key,
|
||||
}
|
||||
|
||||
gotRes, err := h.GetOrderInfoByThirdNO(test.args.orderNo)
|
||||
|
||||
log.Println(gotRes, err)
|
||||
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeiPinShangClient_IsRefund(t *testing.T) {
|
||||
type fields struct {
|
||||
Host string
|
||||
ChannelType string
|
||||
Key string
|
||||
}
|
||||
type args struct {
|
||||
mcOrderNo string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantRes *IsRefundRes
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
Host: "https://uat.api.weipinshang.net/",
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
},
|
||||
args: args{
|
||||
mcOrderNo: "mc20250613182629112823",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
h := &WeiPinShangClient{
|
||||
Host: test.fields.Host,
|
||||
ChannelType: test.fields.ChannelType,
|
||||
Key: test.fields.Key,
|
||||
}
|
||||
|
||||
gotRes, err := h.IsRefund(test.args.mcOrderNo)
|
||||
|
||||
log.Println(gotRes, err)
|
||||
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeiPinShangClient_OrderCancel(t *testing.T) {
|
||||
type fields struct {
|
||||
Host string
|
||||
ChannelType string
|
||||
Key string
|
||||
}
|
||||
type args struct {
|
||||
mcOrderNo string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantRes *IsRefundRes
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
Host: "https://uat.api.weipinshang.net/",
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
},
|
||||
args: args{
|
||||
mcOrderNo: "mc20250529102347485667",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
h := &WeiPinShangClient{
|
||||
Host: test.fields.Host,
|
||||
ChannelType: test.fields.ChannelType,
|
||||
Key: test.fields.Key,
|
||||
}
|
||||
|
||||
gotRes, err := h.OrderCancel(test.args.mcOrderNo)
|
||||
|
||||
log.Println(gotRes, err)
|
||||
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeiPinShangClient_CreateAfsApply(t *testing.T) {
|
||||
type fields struct {
|
||||
Host string
|
||||
ChannelType string
|
||||
Key string
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args CreateAfsApplyReq
|
||||
wantRes *IsRefundRes
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
Host: "https://uat.api.weipinshang.net/",
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
},
|
||||
args: CreateAfsApplyReq{
|
||||
CustomerContactName: "钟",
|
||||
CustomerExpect: 10,
|
||||
CustomerMobilePhone: "15375399426",
|
||||
CustomerTel: "15375399426",
|
||||
McOrderNo: "mc20250613182629112823",
|
||||
PickwareAddress: "奥园",
|
||||
PickwareCity: "广州",
|
||||
PickwareCounty: "番禺",
|
||||
PickwareProvince: "广东",
|
||||
QuestionDesc: "商品问题",
|
||||
QuestionPic: "11",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
h := &WeiPinShangClient{
|
||||
Host: test.fields.Host,
|
||||
ChannelType: test.fields.ChannelType,
|
||||
Key: test.fields.Key,
|
||||
}
|
||||
|
||||
gotRes, err := h.CreateAfsApply(&test.args)
|
||||
|
||||
log.Println(gotRes, err)
|
||||
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// test ---------------------------------------------------
|
||||
|
||||
func TestWeiPinShangClient_DeliverGoods(t *testing.T) {
|
||||
type fields struct {
|
||||
Host string
|
||||
ChannelType string
|
||||
Key string
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args DeliverGoodsReq
|
||||
wantRes *TestRes
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
Host: "https://uat.api.weipinshang.net/",
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
},
|
||||
args: DeliverGoodsReq{
|
||||
COrderItemNo: "mc20250613182629112823",
|
||||
CDeliveryName: "顺丰",
|
||||
CDeliveryNo: "1234567890",
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
Host: "https://uat.api.weipinshang.net/",
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
},
|
||||
args: DeliverGoodsReq{
|
||||
COrderItemNo: "mc20250616113428587322",
|
||||
CDeliveryName: "顺丰0",
|
||||
CDeliveryNo: "SF9900000099",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
h := &WeiPinShangClient{
|
||||
Host: test.fields.Host,
|
||||
ChannelType: test.fields.ChannelType,
|
||||
Key: test.fields.Key,
|
||||
}
|
||||
|
||||
gotRes, err := h.DeliverGoods(&test.args)
|
||||
|
||||
log.Println(gotRes, err)
|
||||
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
func TestWeiPinShangClient_UpdateService(t *testing.T) {
|
||||
type fields struct {
|
||||
Host string
|
||||
ChannelType string
|
||||
Key string
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args UpdateServiceReq
|
||||
wantRes *TestRes
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
Host: "https://uat.api.weipinshang.net/",
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
},
|
||||
args: UpdateServiceReq{
|
||||
COrderItemNo: "mc20250612153935670660",
|
||||
CType: "1",
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
Host: "https://uat.api.weipinshang.net/",
|
||||
ChannelType: "AILEHUI",
|
||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||
},
|
||||
args: UpdateServiceReq{
|
||||
COrderItemNo: "mc20250609180246814560",
|
||||
CType: "3",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
h := &WeiPinShangClient{
|
||||
Host: test.fields.Host,
|
||||
ChannelType: test.fields.ChannelType,
|
||||
Key: test.fields.Key,
|
||||
}
|
||||
|
||||
gotRes, err := h.UpdateService(&test.args)
|
||||
|
||||
log.Println(gotRes, err)
|
||||
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user