Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e246123ce2 | ||
![]() |
1e2d00edaf | ||
![]() |
0c7ec61e65 | ||
![]() |
c214b6c94a | ||
![]() |
fc6ddf1fa5 | ||
![]() |
bbe5e26e95 | ||
![]() |
158bb2542d | ||
![]() |
26bc6b3bcc | ||
![]() |
755c39089b | ||
![]() |
ace2872c2d | ||
![]() |
d2a1182c66 | ||
![]() |
0377692779 | ||
![]() |
2f4e52cac5 | ||
![]() |
f26c317144 | ||
![]() |
2835ad200b | ||
![]() |
8b245587bb | ||
![]() |
f5e8a4b990 | ||
![]() |
754a8910f2 | ||
![]() |
587fd91338 | ||
![]() |
0c1bce5d8c |
@@ -1,4 +1,4 @@
|
|||||||
package express_tool
|
package ali_cloud_tool
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -18,10 +18,10 @@ type AliCloudExpressClient struct {
|
|||||||
cache ICacheAdapter
|
cache ICacheAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAliCloudExpressClient(host, appCode string) *AliCloudExpressClient {
|
func NewAliCloudExpressClient(appCode string) *AliCloudExpressClient {
|
||||||
return &AliCloudExpressClient{
|
return &AliCloudExpressClient{
|
||||||
AppCode: appCode,
|
AppCode: appCode,
|
||||||
Host: host,
|
Host: "https://qryexpress.market.alicloudapi.com/lundear/expressTracking",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@@ -1,4 +1,4 @@
|
|||||||
package express_tool
|
package ali_cloud_tool
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
116
ali_cloud_tool/ali_cloud_realname_client.go
Normal file
116
ali_cloud_tool/ali_cloud_realname_client.go
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
package ali_cloud_tool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AliCloudRealNameClient struct {
|
||||||
|
AppCode string
|
||||||
|
Host string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAliCloudRealNameClient(appCode string) *AliCloudRealNameClient {
|
||||||
|
return &AliCloudRealNameClient{
|
||||||
|
AppCode: appCode,
|
||||||
|
Host: "https://zidv2.market.alicloudapi.com/idcheck/Post",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用实名认证API
|
||||||
|
func (s *AliCloudRealNameClient) CallRealNameAuthAPI(ctx context.Context, name, idCard string) (*RealNameAuthData, error) {
|
||||||
|
// 验证输入
|
||||||
|
if strings.TrimSpace(name) == "" || strings.TrimSpace(idCard) == "" {
|
||||||
|
return nil, errors.New("姓名和身份证号不能为空")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置参数
|
||||||
|
params := url.Values{}
|
||||||
|
params.Add("realName", name)
|
||||||
|
params.Add("cardNo", idCard)
|
||||||
|
|
||||||
|
// 构建完整URL
|
||||||
|
fullURL, err := url.JoinPath(s.Host)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("构建实名认证URL失败: %w, 姓名:%s, 身份证号:%s", err, name, idCard)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建HTTP客户端
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: 2 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建POST请求
|
||||||
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, fullURL, strings.NewReader(params.Encode()))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("创建实名认证请求失败: %w, 姓名:%s, 身份证号:%s", err, name, idCard)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置请求头
|
||||||
|
req.Header.Set("Authorization", "APPCODE "+s.AppCode)
|
||||||
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
|
||||||
|
|
||||||
|
// 发送请求
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("发送实名认证请求失败: %w, 姓名:%s, 身份证号:%s", err, name, idCard)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if closeErr := resp.Body.Close(); closeErr != nil {
|
||||||
|
log.Printf("关闭实名认证响应体失败: %v, 姓名:%s, 身份证号:%s", closeErr, name, idCard)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// 读取响应体
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("读取实名认证响应失败: %w, 姓名:%s, 身份证号:%s", err, name, idCard)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析JSON响应
|
||||||
|
var result RealNameAuthData
|
||||||
|
if err = json.Unmarshal(body, &result); err != nil {
|
||||||
|
return nil, fmt.Errorf("解析实名认证响应失败: %w, 响应内容:%s, 姓名:%s, 身份证号:%s", err, string(body), name, idCard)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查API返回的错误码
|
||||||
|
if result.ErrorCode != 0 {
|
||||||
|
return &result, fmt.Errorf("实名认证接口返回错误, 错误码:%d, 原因:%s, 姓名:%s, 身份证号:%s",
|
||||||
|
result.ErrorCode, result.Reason, name, idCard)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查认证结果
|
||||||
|
if !result.Result.Isok {
|
||||||
|
return &result, fmt.Errorf("实名认证不通过, 原因:%s, 姓名:%s, 身份证号:%s",
|
||||||
|
result.Reason, name, idCard)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type RealNameAuthData struct {
|
||||||
|
ErrorCode int `json:"error_code"`
|
||||||
|
Reason string `json:"reason"`
|
||||||
|
Result struct {
|
||||||
|
Realname string `json:"realname"`
|
||||||
|
Idcard string `json:"idcard"`
|
||||||
|
Isok bool `json:"isok"`
|
||||||
|
IdCardInfor struct {
|
||||||
|
Province string `json:"province"`
|
||||||
|
City string `json:"city"`
|
||||||
|
District string `json:"district"`
|
||||||
|
Area string `json:"area"`
|
||||||
|
Sex string `json:"sex"`
|
||||||
|
Birthday string `json:"birthday"`
|
||||||
|
} `json:"IdCardInfor"`
|
||||||
|
} `json:"result"`
|
||||||
|
Sn string `json:"sn"`
|
||||||
|
}
|
20
ali_cloud_tool/ali_cloud_realname_client_test.go
Normal file
20
ali_cloud_tool/ali_cloud_realname_client_test.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package ali_cloud_tool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAliCloudExpressClient_CallRealNameAuthAPI(t *testing.T) {
|
||||||
|
s := &AliCloudRealNameClient{
|
||||||
|
AppCode: "",
|
||||||
|
Host: "",
|
||||||
|
}
|
||||||
|
got, err := s.CallRealNameAuthAPI(context.Background(), "", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("CallRealNameAuthAPI() error = %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println("=====", got)
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package express_tool
|
package ali_cloud_tool
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
35
common_fun/file_func.go
Normal file
35
common_fun/file_func.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package cf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// EnsureDirExists 确保目录存在,如果不存在则创建
|
||||||
|
func EnsureDirExists(dirPath string) error {
|
||||||
|
// 判断路径是否存在
|
||||||
|
_, err := os.Stat(dirPath)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
// 目录不存在,递归创建
|
||||||
|
err = os.MkdirAll(dirPath, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("创建目录失败,目录:%s,err: %w", dirPath, err)
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
// 其他错误(如权限问题)
|
||||||
|
return fmt.Errorf("检查目录失败,目录:%s,err: %w", dirPath, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnsureParentDirExists 确保文件的目录存在,如果不存在则创建
|
||||||
|
func EnsureParentDirExists(filePath string) error {
|
||||||
|
// 提取父级目录路径
|
||||||
|
dir := filepath.Dir(filePath)
|
||||||
|
err := EnsureDirExists(dir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
19
common_fun/file_func_test.go
Normal file
19
common_fun/file_func_test.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package cf
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestEnsureDirExists(t *testing.T) {
|
||||||
|
url := "/test"
|
||||||
|
err := EnsureDirExists(url)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("EnsureDirExists() error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEnsureParentDirExists(t *testing.T) {
|
||||||
|
filePath := "/test/test1/test.txt"
|
||||||
|
err := EnsureParentDirExists(filePath)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("EnsureDirExists() error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
8
go.mod
8
go.mod
@@ -1,12 +1,15 @@
|
|||||||
module git.ssgfgtfy.com/public/ssgf_utils
|
module git.ssgfgtfy.com/public/ssgf_utils
|
||||||
|
|
||||||
go 1.18.0
|
go 1.23.0
|
||||||
|
|
||||||
|
toolchain go1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.1.7
|
github.com/alibabacloud-go/darabonba-openapi/v2 v2.1.7
|
||||||
github.com/alibabacloud-go/dysmsapi-20170525/v5 v5.1.1
|
github.com/alibabacloud-go/dysmsapi-20170525/v5 v5.1.1
|
||||||
github.com/alibabacloud-go/tea v1.3.8
|
github.com/alibabacloud-go/tea v1.3.8
|
||||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.7
|
github.com/alibabacloud-go/tea-utils/v2 v2.0.7
|
||||||
|
github.com/aliyun/alibabacloud-oss-go-sdk-v2 v1.2.3
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/redis/go-redis/v9 v9.10.0
|
github.com/redis/go-redis/v9 v9.10.0
|
||||||
github.com/stretchr/testify v1.10.0
|
github.com/stretchr/testify v1.10.0
|
||||||
@@ -27,7 +30,8 @@ require (
|
|||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/tjfoc/gmsm v1.4.1 // indirect
|
github.com/tjfoc/gmsm v1.4.1 // indirect
|
||||||
golang.org/x/net v0.26.0 // indirect
|
golang.org/x/net v0.41.0 // indirect
|
||||||
|
golang.org/x/time v0.4.0 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
9
go.sum
9
go.sum
@@ -44,13 +44,17 @@ github.com/alibabacloud-go/tea-utils/v2 v2.0.6/go.mod h1:qxn986l+q33J5VkialKMqT/
|
|||||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.7 h1:WDx5qW3Xa5ZgJ1c8NfqJkF6w+AU5wB8835UdhPr6Ax0=
|
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-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/alibabacloud-go/tea-xml v1.1.3/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCEtyBy9+DPF6GgEu8=
|
||||||
|
github.com/aliyun/alibabacloud-oss-go-sdk-v2 v1.2.3 h1:LyeTJauAchnWdre3sAyterGrzaAtZ4dSNoIvDvaWfo4=
|
||||||
|
github.com/aliyun/alibabacloud-oss-go-sdk-v2 v1.2.3/go.mod h1:FTzydeQVmR24FI0D6XWUOMKckjXehM/jgMn1xC+DA9M=
|
||||||
github.com/aliyun/credentials-go v1.1.2/go.mod h1:ozcZaMR5kLM7pwtCMEpVmQ242suV6qTJya2bDq4X1Tw=
|
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.1/go.mod h1:8jKYhQuDawt8x2+fusqa1Y6mPxemTsBEN04dgcAcYz0=
|
||||||
github.com/aliyun/credentials-go v1.3.6/go.mod h1:1LxUuX7L5YrZUWzBrRyk0SwSdH4OmPrib8NVePL3fxM=
|
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 h1:O76WYKgdy1oQYYiJkERjlA2dxGuvLRrzuO2ScrtGWSk=
|
||||||
github.com/aliyun/credentials-go v1.4.5/go.mod h1:Jm6d+xIgwJVLVWT561vy67ZRP4lPTQxMbEYRuT2Ti1U=
|
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/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||||
|
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||||
|
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
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 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
@@ -169,8 +173,9 @@ 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.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||||
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
|
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.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/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
|
||||||
|
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
|
||||||
|
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
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-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-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
@@ -223,6 +228,8 @@ 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.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||||
golang.org/x/text v0.15.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/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||||
|
golang.org/x/time v0.4.0 h1:Z81tqI5ddIoXDPvVQ7/7CC9TnLM7ubaFG2qXYd5BbYY=
|
||||||
|
golang.org/x/time v0.4.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
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-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-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||||
|
@@ -114,7 +114,7 @@ func (h *HuaChenIpClient) GetIpInfoFormCache(ctx context.Context, ip string, opt
|
|||||||
return nil, errors.Wrapf(err, "无法将IP信息转换为JSON,ip:%s", ip)
|
return nil, errors.Wrapf(err, "无法将IP信息转换为JSON,ip:%s", ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(opt) == 0 {
|
if len(opt) != 0 {
|
||||||
err = h.cache.Set(ctx, h.ipKey(ip), string(infoJson), opt[0])
|
err = h.cache.Set(ctx, h.ipKey(ip), string(infoJson), opt[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "缓存ip:%s信息失败,", ip)
|
return nil, errors.Wrapf(err, "缓存ip:%s信息失败,", ip)
|
||||||
|
201
jtt_tool/jtt_client.go
Normal file
201
jtt_tool/jtt_client.go
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
package jtt_tool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto"
|
||||||
|
"crypto/md5"
|
||||||
|
"crypto/rand"
|
||||||
|
"crypto/rsa"
|
||||||
|
"crypto/x509"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"encoding/pem"
|
||||||
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type JttClient struct {
|
||||||
|
AppId string
|
||||||
|
ApiUrl string
|
||||||
|
PublicKey string
|
||||||
|
PrivateKey string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewJttClient(appId, apiUrl, publicKey, privateKey string) *JttClient {
|
||||||
|
return &JttClient{
|
||||||
|
AppId: appId,
|
||||||
|
ApiUrl: apiUrl,
|
||||||
|
PublicKey: publicKey,
|
||||||
|
PrivateKey: privateKey,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *JttClient) FindUserForTokenMessage(address string) (res *FindUserForTokenMessageRes, err error) {
|
||||||
|
if address == "" {
|
||||||
|
return nil, fmt.Errorf("address is empty")
|
||||||
|
}
|
||||||
|
fmt.Println("address", address)
|
||||||
|
|
||||||
|
paramMap := make(map[string]any)
|
||||||
|
|
||||||
|
paramMap["appId"] = j.AppId
|
||||||
|
paramMap["timestamp"] = time.Now().Unix()
|
||||||
|
paramMap["publicKey"] = j.PublicKey
|
||||||
|
paramMap["address"] = address
|
||||||
|
|
||||||
|
postRes, err := j.JttPost("/findUserForTokenMessage", paramMap)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(postRes, &res)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("转换FindUserForTokenMessageRes结构体失败: %s", string(postRes))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if res == nil || res.Code != 200 {
|
||||||
|
err = fmt.Errorf("查询交易所数据失败: %w, res: %+v , 地址:%s", err, res, address)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
type FindUserForTokenMessageRes struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data *Data `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Data struct {
|
||||||
|
UserTokenList []*UserToken `json:"userTokenList"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserToken struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Mes string `json:"mes"`
|
||||||
|
TokenNum float64 `json:"tokenNum"`
|
||||||
|
WalletAddress string `json:"walletAddress"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *JttClient) JttPost(url string, paramMap map[string]any) (res []byte, err error) {
|
||||||
|
|
||||||
|
bodyByte, _ := json.Marshal(paramMap)
|
||||||
|
|
||||||
|
req, err := http.NewRequest(http.MethodPost, j.ApiUrl+url, bytes.NewBuffer(bodyByte))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
sign, err := j.ToSign(paramMap)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
paramMap["sign"] = sign
|
||||||
|
|
||||||
|
// 创建 HTTP 客户端
|
||||||
|
client := &http.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
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *JttClient) ToSign(reqData map[string]interface{}) (sign []byte, errs error) {
|
||||||
|
sortedStr, err := s.GetSortedStr(reqData)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
privateKeyStr := "-----BEGIN PRIVATE KEY-----\r\n" + s.PrivateKey + "\r\n-----END PRIVATE KEY-----"
|
||||||
|
sign, err = s.Sign(sortedStr, privateKeyStr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *JttClient) Sign(signData string, privateKeyStr string) (sign []byte, errs error) {
|
||||||
|
hashedMessage := md5.Sum([]byte(signData))
|
||||||
|
if privateKeyStr == "" {
|
||||||
|
return nil, errors.New("private key is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
block, _ := pem.Decode([]byte(privateKeyStr))
|
||||||
|
privateKey, err := x509.ParsePKCS8PrivateKey(block.Bytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
sign, err = rsa.SignPKCS1v15(rand.Reader, privateKey.(*rsa.PrivateKey), crypto.MD5, hashedMessage[:])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
sign = []byte(base64.StdEncoding.EncodeToString(sign))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *JttClient) GetSortedStr(data any) (str string, err error) {
|
||||||
|
tmp := map[string]interface{}{}
|
||||||
|
if reflect.ValueOf(data).Kind() == reflect.Struct {
|
||||||
|
jsStr, _ := json.Marshal(data)
|
||||||
|
_ = json.Unmarshal(jsStr, &tmp)
|
||||||
|
} else {
|
||||||
|
ok := false
|
||||||
|
tmp, ok = data.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
err = errors.New("data type error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
keys := []string{}
|
||||||
|
for key := range tmp {
|
||||||
|
keys = append(keys, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(keys)
|
||||||
|
sortedParams := []string{}
|
||||||
|
|
||||||
|
for _, key := range keys {
|
||||||
|
value := tmp[key]
|
||||||
|
if key == "sign" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
switch v := value.(type) {
|
||||||
|
case int, uint, int16, int32, int64:
|
||||||
|
sortedParams = append(sortedParams, fmt.Sprintf("%s=%d", key, v))
|
||||||
|
case float64, float32:
|
||||||
|
sortedParams = append(sortedParams, fmt.Sprintf("%s=%f", key, v))
|
||||||
|
default:
|
||||||
|
sortedParams = append(sortedParams, key+"="+value.(string))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
str = strings.Join(sortedParams, "&")
|
||||||
|
return
|
||||||
|
}
|
51
jtt_tool/jtt_client_test.go
Normal file
51
jtt_tool/jtt_client_test.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package jtt_tool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestJttClient_FindUserForTokenMessage(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
AppId string
|
||||||
|
ApiUrl string
|
||||||
|
PublicKey string
|
||||||
|
PrivateKey string
|
||||||
|
}
|
||||||
|
type args struct {
|
||||||
|
address string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
args args
|
||||||
|
wantRes *FindUserForTokenMessageRes
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "test1",
|
||||||
|
fields: fields{},
|
||||||
|
args: args{
|
||||||
|
address: "0x123456",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
h := &JttClient{
|
||||||
|
AppId: test.fields.AppId,
|
||||||
|
ApiUrl: test.fields.ApiUrl,
|
||||||
|
PublicKey: test.fields.PublicKey,
|
||||||
|
PrivateKey: test.fields.PrivateKey,
|
||||||
|
}
|
||||||
|
|
||||||
|
gotRes, err := h.FindUserForTokenMessage(test.args.address)
|
||||||
|
|
||||||
|
log.Println(gotRes, err)
|
||||||
|
|
||||||
|
if (err != nil) != test.wantErr {
|
||||||
|
t.Errorf("FindUserForTokenMessage() error = %v, wantErr %v", err, test.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
174
oss_tool/aliyun_oss.go
Normal file
174
oss_tool/aliyun_oss.go
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
package oss_tool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
cf "git.ssgfgtfy.com/public/ssgf_utils/common_fun"
|
||||||
|
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
|
||||||
|
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
|
||||||
|
"image"
|
||||||
|
"image/jpeg"
|
||||||
|
"image/png"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ALiYunOSSClient struct {
|
||||||
|
AccessKeyID string
|
||||||
|
AccessKeySecret string
|
||||||
|
Region string
|
||||||
|
ossClient *oss.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ALiYunOSSClient) NewAliYunOSS() (err error) {
|
||||||
|
if c.AccessKeyID == "" || c.AccessKeySecret == "" {
|
||||||
|
return errors.New("请配置 oss accessKeyID accessKeySecret")
|
||||||
|
}
|
||||||
|
if c.Region == "" {
|
||||||
|
return errors.New("请配置 oss region")
|
||||||
|
}
|
||||||
|
provider := credentials.NewStaticCredentialsProvider(c.AccessKeyID, c.AccessKeySecret)
|
||||||
|
cfg := oss.LoadDefaultConfig().WithSignatureVersion(oss.SignatureVersionV4).WithCredentialsProvider(provider).WithRegion(c.Region)
|
||||||
|
c.ossClient = oss.NewClient(cfg)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ALiYunOSSClient) GetSignUrl(bucket string, key string, expires time.Duration) (result *oss.PresignResult, err error) {
|
||||||
|
// 生成PutObject的预签名URL
|
||||||
|
result, err = c.ossClient.Presign(
|
||||||
|
context.Background(),
|
||||||
|
&oss.PutObjectRequest{
|
||||||
|
Bucket: oss.Ptr(bucket),
|
||||||
|
Key: oss.Ptr(key),
|
||||||
|
},
|
||||||
|
oss.PresignExpires(expires),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ALiYunOSSClient) GetSignUrlByPutObjectRequest(req *oss.PutObjectRequest, expires time.Duration) (result *oss.PresignResult, err error) {
|
||||||
|
// 生成PutObject的预签名URL
|
||||||
|
result, err = c.ossClient.Presign(
|
||||||
|
context.Background(),
|
||||||
|
req,
|
||||||
|
oss.PresignExpires(expires),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutForLocalFile 上传本地文件
|
||||||
|
func (c *ALiYunOSSClient) PutForLocalFile(bucket, key, path string) (result *oss.PutObjectResult, err error) {
|
||||||
|
// 创建上传对象的请求
|
||||||
|
putRequest := &oss.PutObjectRequest{
|
||||||
|
Bucket: oss.Ptr(bucket), // 存储空间名称
|
||||||
|
Key: oss.Ptr(key), // 对象名称
|
||||||
|
StorageClass: oss.StorageClassStandard, // 指定对象的存储类型为标准存储
|
||||||
|
ContentType: oss.Ptr("application/octet-stream"),
|
||||||
|
}
|
||||||
|
// 执行上传对象的请求
|
||||||
|
result, err = c.ossClient.PutObjectFromFile(context.Background(), putRequest, path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetObject 下载文件,返回的是一个*oss.GetObjectResult (不推荐使用,如果使用的话,需要手动调用object.Body.Close()手动关闭资源)
|
||||||
|
func (c *ALiYunOSSClient) GetObject(bucket string, key string) (object *oss.GetObjectResult, body io.ReadCloser, err error) {
|
||||||
|
getRequest := &oss.GetObjectRequest{
|
||||||
|
Bucket: oss.Ptr(bucket), // 存储空间名称
|
||||||
|
Key: oss.Ptr(key), // 对象名称
|
||||||
|
}
|
||||||
|
// 执行获取对象的操作并处理结果
|
||||||
|
result, err := c.ossClient.GetObject(context.TODO(), getRequest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
//defer func() {
|
||||||
|
// _ = result.Body.Close() // 确保在函数结束时关闭响应体
|
||||||
|
//}()
|
||||||
|
return result, result.Body, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetObjectToFile 获取对象并保存到本地
|
||||||
|
func (c *ALiYunOSSClient) GetObjectToFile(bucket string, key string, path string) (err error) {
|
||||||
|
getRequest := &oss.GetObjectRequest{
|
||||||
|
Bucket: oss.Ptr(bucket), // 存储空间名称
|
||||||
|
Key: oss.Ptr(key), // 对象名称
|
||||||
|
}
|
||||||
|
// 执行获取对象的操作并处理结果
|
||||||
|
result, err := c.ossClient.GetObject(context.TODO(), getRequest)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = result.Body.Close() // 确保在函数结束时关闭响应体
|
||||||
|
}()
|
||||||
|
// 确保文件目录存在
|
||||||
|
err = cf.EnsureParentDirExists(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// 创建目标文件
|
||||||
|
file, err := os.Create(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
// 将 reader 中的内容复制到文件中
|
||||||
|
_, err = io.Copy(file, result.Body)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetObjectToImage 获取对象并保存为图片对象
|
||||||
|
func (c *ALiYunOSSClient) GetObjectToImage(bucket string, key string) (img image.Image, err error) {
|
||||||
|
getRequest := &oss.GetObjectRequest{
|
||||||
|
Bucket: oss.Ptr(bucket), // 存储空间名称
|
||||||
|
Key: oss.Ptr(key), // 对象名称
|
||||||
|
}
|
||||||
|
// 执行获取对象的操作并处理结果
|
||||||
|
result, err := c.ossClient.GetObject(context.TODO(), getRequest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = result.Body.Close() // 确保在函数结束时关闭响应体
|
||||||
|
}()
|
||||||
|
img, _, err = image.Decode(result.Body)
|
||||||
|
if err != nil {
|
||||||
|
// 尝试 JPEG 解码
|
||||||
|
img, err = jpeg.Decode(result.Body)
|
||||||
|
if err != nil {
|
||||||
|
// 尝试 PNG 解码
|
||||||
|
img, err = png.Decode(result.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("图片解码失败(支持的格式:JPEG/PNG): %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return img, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DelObject 删除对象
|
||||||
|
func (c *ALiYunOSSClient) DelObject(bucket string, key string) (err error) {
|
||||||
|
// 创建删除对象的请求
|
||||||
|
request := &oss.DeleteObjectRequest{
|
||||||
|
Bucket: oss.Ptr(bucket), // 存储空间名称
|
||||||
|
Key: oss.Ptr(key), // 对象名称
|
||||||
|
}
|
||||||
|
// 执行删除对象的操作并处理结果
|
||||||
|
_, err = c.ossClient.DeleteObject(context.TODO(), request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
105
oss_tool/aliyun_oss_test.go
Normal file
105
oss_tool/aliyun_oss_test.go
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
package oss_tool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
accessKeyId = os.Getenv("OSS_ACCESS_KEY_ID")
|
||||||
|
accessKeySecret = os.Getenv("OSS_SECRET_ACCESS_KEY")
|
||||||
|
region = os.Getenv("OSS_REGION")
|
||||||
|
client = &ALiYunOSSClient{
|
||||||
|
AccessKeyID: accessKeyId,
|
||||||
|
AccessKeySecret: accessKeySecret,
|
||||||
|
Region: region,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestALiYunOSSClient_NewAliYunOSS(t *testing.T) {
|
||||||
|
err := client.NewAliYunOSS()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
t.Log(client.ossClient)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestALiYunOSSClient_GetSignUrl(t *testing.T) {
|
||||||
|
err := client.NewAliYunOSS()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
sign, err := client.GetSignUrl("", "test/upload/bizhi1.jpg", 0)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
t.Log(sign)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestALiYunOSSClient_GetSignUrlByPutObjectRequest(t *testing.T) {
|
||||||
|
err := client.NewAliYunOSS()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
req := &oss.PutObjectRequest{}
|
||||||
|
req.Bucket = oss.Ptr("")
|
||||||
|
req.Key = oss.Ptr("test/upload/bizhi2.jpg")
|
||||||
|
req.ContentType = oss.Ptr("application/octet-stream")
|
||||||
|
sign, err := client.GetSignUrlByPutObjectRequest(req, 0)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
t.Log(sign)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestALiYunOSSClient_PutForLocalFile(t *testing.T) {
|
||||||
|
err := client.NewAliYunOSS()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
result, err := client.PutForLocalFile("", "test/upload/bizhi2.jpg", "C:\\Users\\Administrator\\Desktop\\壁纸1.jpg")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
t.Log(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestALiYunOSSClient_GetObjectToFile(t *testing.T) {
|
||||||
|
err := client.NewAliYunOSS()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
err = client.GetObjectToFile("", "test/upload/bizhi1.jpg", "D:/bizhi1.jpg")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
} else {
|
||||||
|
t.Log("成功")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestALiYunOSSClient_GetObjectToImage(t *testing.T) {
|
||||||
|
err := client.NewAliYunOSS()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
img, err := client.GetObjectToImage("", "test/upload/bizhi1.jpg")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
} else {
|
||||||
|
t.Log(img)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestALiYunOSSClient_DelObject(t *testing.T) {
|
||||||
|
err := client.NewAliYunOSS()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
err = client.DelObject("", "test/upload/bizhi2.jpg")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
} else {
|
||||||
|
t.Log("成功")
|
||||||
|
}
|
||||||
|
}
|
@@ -38,7 +38,7 @@ func NewSmsClient(smsConfig *SmsConfig) (smsClient SmsClient, err error) {
|
|||||||
config.AccessKeySecret = tea.String(smsConfig.AccessKeySecret)
|
config.AccessKeySecret = tea.String(smsConfig.AccessKeySecret)
|
||||||
// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
|
// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
|
||||||
config.Endpoint = tea.String(smsConfig.Endpoint)
|
config.Endpoint = tea.String(smsConfig.Endpoint)
|
||||||
|
smsClient.SmsConfig = *smsConfig
|
||||||
smsClient.client = &dysmsapi20170525.Client{}
|
smsClient.client = &dysmsapi20170525.Client{}
|
||||||
smsClient.client, err = dysmsapi20170525.NewClient(config)
|
smsClient.client, err = dysmsapi20170525.NewClient(config)
|
||||||
return smsClient, err
|
return smsClient, err
|
||||||
|
@@ -105,3 +105,31 @@ func (c *WeiPinShangClient) GetGoodsStock(req GetGoodsStockReq) (*[]GoodsStock,
|
|||||||
res := out.Data
|
res := out.Data
|
||||||
return &res, err
|
return &res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *WeiPinShangClient) GetSaleVenue(req GetSaleVenueReq) (*SaleVenueList, error) {
|
||||||
|
param := StructToMapString(req)
|
||||||
|
out := GetSaleVenueRes{}
|
||||||
|
err := c.PostAndParse(GetSaleVenueURL, 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) GetSaleVenueGoods(req GetSaleVenueGoodsReq) (*SaleVenueGoodsList, error) {
|
||||||
|
param := StructToMapString(req)
|
||||||
|
out := GetSaleVenueGoodsRes{}
|
||||||
|
err := c.PostAndParse(GetSaleVenueGoodsURL, param, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if out.Code != 0 {
|
||||||
|
return nil, fmt.Errorf(out.Msg)
|
||||||
|
}
|
||||||
|
res := out.Data
|
||||||
|
return &res, err
|
||||||
|
}
|
||||||
|
@@ -113,3 +113,31 @@ func TestGetGoodsStock(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, res)
|
assert.NotNil(t, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetSaleVenue(t *testing.T) {
|
||||||
|
ts := setupMockServer(wps.GetSaleVenueURL, http.MethodPost, `{"code":200,"data":{"stocks":[]}}`, t)
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := newClientWithServer(ts)
|
||||||
|
res, err := client.GetSaleVenue(wps.GetSaleVenueReq{
|
||||||
|
PageNo: "1",
|
||||||
|
PageSize: "100",
|
||||||
|
Sort: 0,
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetSaleVenueGoods(t *testing.T) {
|
||||||
|
ts := setupMockServer(wps.GetSaleVenueGoodsURL, http.MethodPost, `{"code":200,"data":{"stocks":[]}}`, t)
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := newClientWithServer(ts)
|
||||||
|
res, err := client.GetSaleVenueGoods(wps.GetSaleVenueGoodsReq{
|
||||||
|
PageNo: "1",
|
||||||
|
PageSize: "100",
|
||||||
|
ExhibitionID: "1829399501611053057",
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, res)
|
||||||
|
}
|
||||||
|
@@ -160,19 +160,19 @@ type GoodsItem struct {
|
|||||||
|
|
||||||
// 商品SKU信息
|
// 商品SKU信息
|
||||||
type GoodsSkuItem struct {
|
type GoodsSkuItem struct {
|
||||||
CFatherGoodsID string `json:"c_father_goods_id"` // 父级商品ID
|
CFatherGoodsID string `json:"c_father_goods_id"` // 父级商品ID
|
||||||
CGoodsID string `json:"c_goods_id"` // 商品ID
|
CGoodsID string `json:"c_goods_id"` // 商品ID
|
||||||
CGoodsName string `json:"c_goods_name"` // 商品规格名称
|
CGoodsName string `json:"c_goods_name"` // 商品规格名称
|
||||||
COriginalPrice string `json:"c_original_price"` // 商品市场价
|
COriginalPrice string `json:"c_original_price"` // 商品市场价
|
||||||
CInPrice string `json:"c_in_price"` // 商品进价
|
CInPrice string `json:"c_in_price"` // 商品进价
|
||||||
CSalePrice string `json:"c_sale_price"` // 商品建议售价
|
CSalePrice string `json:"c_sale_price"` // 商品建议售价
|
||||||
CGoodsColor string `json:"c_goods_color"` // 商品颜色
|
CGoodsColor string `json:"c_goods_color"` // 商品颜色
|
||||||
CGoodsSize string `json:"c_goods_size"` // 商品尺寸
|
CGoodsSize string `json:"c_goods_size"` // 商品尺寸
|
||||||
CGoodsImage string `json:"c_goods_image"` // 商品列表图片
|
CGoodsImage string `json:"c_goods_image"` // 商品列表图片
|
||||||
CGoodsStockStart int `json:"c_goods_stock_start"` // 初始总库存
|
CGoodsStockStart interface{} `json:"c_goods_stock_start"` // 初始总库存
|
||||||
CGoodsStockValid int `json:"c_goods_stock_valid"` // 有效库存(下单库存参考)
|
CGoodsStockValid interface{} `json:"c_goods_stock_valid"` // 有效库存(下单库存参考)
|
||||||
CBuyMinNum int `json:"c_buy_min_num"` // 最小购买数量
|
CBuyMinNum interface{} `json:"c_buy_min_num"` // 最小购买数量
|
||||||
CBuyMaxNum int `json:"c_buy_max_num"` // 最大购买数量
|
CBuyMaxNum interface{} `json:"c_buy_max_num"` // 最大购买数量
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetGoodsDetailsReq struct {
|
type GetGoodsDetailsReq struct {
|
||||||
@@ -199,3 +199,66 @@ type GoodsStock struct {
|
|||||||
CGoodsId string `json:"c_goods_id"`
|
CGoodsId string `json:"c_goods_id"`
|
||||||
CStock int `json:"c_stock"`
|
CStock int `json:"c_stock"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetSaleVenueReq struct {
|
||||||
|
PageNo string `json:"pageNo"` //页码
|
||||||
|
PageSize string `json:"pageSize"` //条数
|
||||||
|
Sort int `json:"sort"` //传1为c_id desc ,不传或者传0为c_start_datetime asc
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetSaleVenueRes struct {
|
||||||
|
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||||
|
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||||
|
Data SaleVenueList `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SaleVenueList struct {
|
||||||
|
PageIndex string `json:"pageIndex"`
|
||||||
|
PageCount int `json:"pageCount"`
|
||||||
|
DataCount int `json:"dataCount"`
|
||||||
|
List []SaleVenue `json:"list"` // 会场列表
|
||||||
|
}
|
||||||
|
|
||||||
|
type SaleVenue struct {
|
||||||
|
CID int `json:"c_id"` // 序号
|
||||||
|
CExhibitionID string `json:"c_exhibition_id"` // 会场ID
|
||||||
|
CBrandID int `json:"c_brand_id"` // 品牌ID
|
||||||
|
CExhibitionName string `json:"c_exhibition_name"` // 会场名称
|
||||||
|
CIconImageURL string `json:"c_icon_image_url"` // 会场列表图片
|
||||||
|
CBannerImageURL string `json:"c_banner_image_url"` // 会场Banner图
|
||||||
|
CDescription string `json:"c_description"` // 会场描述(可选)
|
||||||
|
CStartDatetime string `json:"c_start_datetime"` // 会场开始时间
|
||||||
|
CEndDatetime string `json:"c_end_datetime"` // 会场结束时间
|
||||||
|
CCompanyCode string `json:"c_company_code"` //供应商编号
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetSaleVenueGoodsReq struct {
|
||||||
|
PageNo string `json:"pageNo"` //页码
|
||||||
|
PageSize string `json:"pageSize"` //条数
|
||||||
|
ExhibitionID string `json:"exhibition_id"` //会场id
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetSaleVenueGoodsRes struct {
|
||||||
|
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||||
|
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||||
|
Data SaleVenueGoodsList `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SaleVenueGoodsList struct {
|
||||||
|
PageIndex string `json:"pageIndex"`
|
||||||
|
PageCount int `json:"pageCount"`
|
||||||
|
DataCount int `json:"dataCount"`
|
||||||
|
List []SaleVenueGoods `json:"list"` // 会场列表
|
||||||
|
}
|
||||||
|
|
||||||
|
type SaleVenueGoods struct {
|
||||||
|
CID int `json:"c_id"` // 序号
|
||||||
|
CExhibitionID string `json:"c_exhibition_id"` // 商品所属会场 ID
|
||||||
|
CFatherGoodsID string `json:"c_father_goods_id"` // 商品编码
|
||||||
|
CGoodsName string `json:"c_goods_name"` // 商品名称
|
||||||
|
CGoodsImage string `json:"c_goods_image"` // 商品主图
|
||||||
|
CGoodsDescription string `json:"c_goods_description"` // 商品描述
|
||||||
|
CGoodsContent string `json:"c_goods_content"` // 商品详情图(可选)
|
||||||
|
CInPrice string `json:"c_in_price"` // 商品进价
|
||||||
|
COriginalPrice string `json:"c_original_price"` // 商品市场价(吊牌价)
|
||||||
|
}
|
||||||
|
@@ -22,13 +22,15 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
GetGoodBrandURL = "mcang/Mcang/goodBrand" //查询商品的品牌
|
GetGoodBrandURL = "mcang/Mcang/goodBrand" //查询商品的品牌
|
||||||
GetGoodsClassifyURL = "mcang/Mcang/getGoodsClassify" //查询商品分类
|
GetGoodsClassifyURL = "mcang/Mcang/getGoodsClassify" //查询商品分类
|
||||||
GetGoodsListURL = "mcang/Mcang/getGoodsList" //获取全部商品列表接口
|
GetGoodsListURL = "mcang/Mcang/getGoodsList" //获取全部商品列表接口
|
||||||
GetGoodsdeptURL = "mcang/Mcang/getGoodsdept" //(推荐使用)获取后台已选商品列表接口
|
GetGoodsdeptURL = "mcang/Mcang/getGoodsdept" //(推荐使用)获取后台已选商品列表接口
|
||||||
GetDetailsGoodsUrl = "mcang/Mcang/getDetailsGoods" //获取批量商品详情接口
|
GetDetailsGoodsUrl = "mcang/Mcang/getDetailsGoods" //获取批量商品详情接口
|
||||||
GetGoodsDetailsURL = "mcang/Mcang/getGoodsDetails" //获取单个商品详情接口
|
GetGoodsDetailsURL = "mcang/Mcang/getGoodsDetails" //获取单个商品详情接口
|
||||||
GetGoodsStockURL = "mcang/Mcang/getGoodsStock" //获取单个商品详情接口
|
GetGoodsStockURL = "mcang/Mcang/getGoodsStock" //获取单个商品详情接口
|
||||||
|
GetSaleVenueURL = "mcang/Mcang/getSaleVenue" //获取会场列表接口
|
||||||
|
GetSaleVenueGoodsURL = "mcang/Mcang/getSaleVenueGoods" //获取会场商品列表接口
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config 客户端配置
|
// Config 客户端配置
|
||||||
|
@@ -25,11 +25,11 @@ type CreateOrderRes struct {
|
|||||||
Data []CreateOrderData `json:"data"` // 返回数据 data array
|
Data []CreateOrderData `json:"data"` // 返回数据 data array
|
||||||
}
|
}
|
||||||
type CreateOrderData struct {
|
type CreateOrderData struct {
|
||||||
ThirdOrderNo string `json:"thirdOrderNo"` // 第三方订单号 本地订单号
|
ThirdOrderNo string `json:"thirdOrderNo"` // 第三方订单号 本地订单号
|
||||||
OrderNo string `json:"orderNo"` // 主订单号
|
OrderNo string `json:"orderNo"` // 主订单号
|
||||||
McOrderNo string `json:"mcOrderNo"` //蜜仓子订单号
|
McOrderNo string `json:"mcOrderNo"` //蜜仓子订单号
|
||||||
OrderAmount float64 `json:"orderAmount"` // 子订单总金额
|
OrderAmount interface{} `json:"orderAmount"` // 子订单总金额
|
||||||
Sku []SkuData `json:"sku"` // 订单商品信息
|
Sku []SkuData `json:"sku"` // 订单商品信息
|
||||||
}
|
}
|
||||||
|
|
||||||
type SkuData struct {
|
type SkuData struct {
|
||||||
@@ -38,7 +38,7 @@ type SkuData struct {
|
|||||||
GoodName string `json:"goodName"` //商品名称
|
GoodName string `json:"goodName"` //商品名称
|
||||||
Num interface{} `json:"num"` //数量
|
Num interface{} `json:"num"` //数量
|
||||||
//Num int `json:"num"` //数量
|
//Num int `json:"num"` //数量
|
||||||
Price string `json:"price"` //单价
|
Price interface{} `json:"price"` //单价
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetOrderInfoRes struct {
|
type GetOrderInfoRes struct {
|
||||||
|
Reference in New Issue
Block a user