Skip to content

Commit

Permalink
Update import statements in Go code
Browse files Browse the repository at this point in the history
  • Loading branch information
shenghui0779 committed Jan 19, 2024
1 parent 886176a commit adc97df
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 188 deletions.
32 changes: 16 additions & 16 deletions alipay/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/tidwall/gjson"

"github.com/shenghui0779/sdk-go/lib"
libCrypto "github.com/shenghui0779/sdk-go/lib/crypto"
libHttp "github.com/shenghui0779/sdk-go/lib/http"
lib_crypto "github.com/shenghui0779/sdk-go/lib/crypto"
lib_http "github.com/shenghui0779/sdk-go/lib/http"
"github.com/shenghui0779/sdk-go/lib/value"
)

Expand All @@ -24,9 +24,9 @@ type Client struct {
gateway string
appid string
aesKey string
prvKey *libCrypto.PrivateKey
pubKey *libCrypto.PublicKey
httpCli libHttp.HTTPClient
prvKey *lib_crypto.PrivateKey
pubKey *lib_crypto.PublicKey
httpCli lib_http.Client
logger func(ctx context.Context, data map[string]string)
}

Expand All @@ -52,8 +52,8 @@ func (c *Client) Do(ctx context.Context, method string, options ...ActionOption)
log.SetReqBody(body)

resp, err := c.httpCli.Do(ctx, http.MethodPost, reqURL, []byte(body),
libHttp.WithHeader(libHttp.HeaderAccept, "application/json"),
libHttp.WithHeader(libHttp.HeaderContentType, libHttp.ContentForm),
lib_http.WithHeader(lib_http.HeaderAccept, "application/json"),
lib_http.WithHeader(lib_http.HeaderContentType, lib_http.ContentForm),
)
if err != nil {
return lib.Fail(err)
Expand Down Expand Up @@ -100,7 +100,7 @@ func (c *Client) Do(ctx context.Context, method string, options ...ActionOption)
}

// Upload 文件上传,参考:https://opendocs.alipay.com/apis/api_4/alipay.merchant.item.file.upload
func (c *Client) Upload(ctx context.Context, method string, form libHttp.UploadForm, options ...ActionOption) (gjson.Result, error) {
func (c *Client) Upload(ctx context.Context, method string, form lib_http.UploadForm, options ...ActionOption) (gjson.Result, error) {
log := lib.NewReqLog(http.MethodPost, c.gateway)
defer log.Do(ctx, c.logger)

Expand All @@ -113,7 +113,7 @@ func (c *Client) Upload(ctx context.Context, method string, form libHttp.UploadF

log.Set("query", query)

resp, err := c.httpCli.Upload(ctx, c.gateway+"?"+query, form, libHttp.WithHeader(libHttp.HeaderAccept, "application/json"))
resp, err := c.httpCli.Upload(ctx, c.gateway+"?"+query, form, lib_http.WithHeader(lib_http.HeaderAccept, "application/json"))
if err != nil {
return lib.Fail(err)
}
Expand Down Expand Up @@ -215,7 +215,7 @@ func (c *Client) Encrypt(data string) (string, error) {
return "", fmt.Errorf("aes_key base64.decode error: %w", err)
}

ct, err := libCrypto.AESEncryptCBC(key, make([]byte, 16), []byte(data))
ct, err := lib_crypto.AESEncryptCBC(key, make([]byte, 16), []byte(data))
if err != nil {
return "", err
}
Expand All @@ -235,7 +235,7 @@ func (c *Client) Decrypt(encryptData string) ([]byte, error) {
return nil, fmt.Errorf("encrypt_data base64.decode error: %w", err)
}

return libCrypto.AESDecryptCBC(key, make([]byte, 16), data)
return lib_crypto.AESDecryptCBC(key, make([]byte, 16), data)
}

// DecodeEncryptData 解析加密数据,如:授权的用户信息和手机号
Expand Down Expand Up @@ -297,19 +297,19 @@ type Option func(c *Client)
// WithHttpCli 设置自定义 HTTP Client
func WithHttpCli(cli *http.Client) Option {
return func(c *Client) {
c.httpCli = libHttp.NewHTTPClient(cli)
c.httpCli = lib_http.NewHTTPClient(cli)
}
}

// WithPrivateKey 设置商户RSA私钥
func WithPrivateKey(key *libCrypto.PrivateKey) Option {
func WithPrivateKey(key *lib_crypto.PrivateKey) Option {
return func(c *Client) {
c.prvKey = key
}
}

// WithPublicKey 设置平台RSA公钥
func WithPublicKey(key *libCrypto.PublicKey) Option {
func WithPublicKey(key *lib_crypto.PublicKey) Option {
return func(c *Client) {
c.pubKey = key
}
Expand All @@ -328,7 +328,7 @@ func NewClient(appid, aesKey string, options ...Option) *Client {
appid: appid,
aesKey: aesKey,
gateway: "https://openapi.alipay.com/gateway.do",
httpCli: libHttp.NewDefaultClient(),
httpCli: lib_http.NewDefaultClient(),
}

for _, f := range options {
Expand All @@ -344,7 +344,7 @@ func NewSandbox(appid, aesKey string, options ...Option) *Client {
appid: appid,
aesKey: aesKey,
gateway: "https://openapi-sandbox.dl.alipaydev.com/gateway.do",
httpCli: libHttp.NewDefaultClient(),
httpCli: lib_http.NewDefaultClient(),
}

for _, f := range options {
Expand Down
38 changes: 19 additions & 19 deletions alipay/client_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ import (
"github.com/tidwall/gjson"

"github.com/shenghui0779/sdk-go/lib"
libCrypto "github.com/shenghui0779/sdk-go/lib/crypto"
libHttp "github.com/shenghui0779/sdk-go/lib/http"
lib_crypto "github.com/shenghui0779/sdk-go/lib/crypto"
lib_http "github.com/shenghui0779/sdk-go/lib/http"
)

// ClientV3 支付宝V3客户端(仅支持v3版本的接口可用)
type ClientV3 struct {
host string
appid string
aesKey string
prvKey *libCrypto.PrivateKey
pubKey *libCrypto.PublicKey
httpCli libHttp.HTTPClient
prvKey *lib_crypto.PrivateKey
pubKey *lib_crypto.PublicKey
httpCli lib_http.Client
logger func(ctx context.Context, data map[string]string)
}

Expand Down Expand Up @@ -89,7 +89,7 @@ func (c *ClientV3) do(ctx context.Context, method, path string, query url.Values
if err != nil {
return nil, err
}
header.Set(libHttp.HeaderAuthorization, authStr)
header.Set(lib_http.HeaderAuthorization, authStr)

log.SetReqHeader(header)

Expand Down Expand Up @@ -137,7 +137,7 @@ func (c *ClientV3) do(ctx context.Context, method, path string, query url.Values
func (c *ClientV3) GetJSON(ctx context.Context, path string, query url.Values, options ...V3HeaderOption) (*APIResult, error) {
header := http.Header{}

header.Set(libHttp.HeaderAccept, "application/json")
header.Set(lib_http.HeaderAccept, "application/json")
header.Set(HeaderRequestID, uuid.NewString())

for _, f := range options {
Expand All @@ -151,9 +151,9 @@ func (c *ClientV3) GetJSON(ctx context.Context, path string, query url.Values, o
func (c *ClientV3) PostJSON(ctx context.Context, path string, params lib.X, options ...V3HeaderOption) (*APIResult, error) {
header := http.Header{}

header.Set(libHttp.HeaderAccept, "application/json")
header.Set(lib_http.HeaderAccept, "application/json")
header.Set(HeaderRequestID, uuid.NewString())
header.Set(libHttp.HeaderContentType, libHttp.ContentJSON)
header.Set(lib_http.HeaderContentType, lib_http.ContentJSON)

for _, f := range options {
f(header)
Expand All @@ -168,7 +168,7 @@ func (c *ClientV3) PostEncrypt(ctx context.Context, path string, params lib.X, o

header.Set(HeaderRequestID, uuid.NewString())
header.Set(HeaderEncryptType, "AES")
header.Set(libHttp.HeaderContentType, libHttp.ContentText)
header.Set(lib_http.HeaderContentType, lib_http.ContentText)

for _, f := range options {
f(header)
Expand All @@ -178,7 +178,7 @@ func (c *ClientV3) PostEncrypt(ctx context.Context, path string, params lib.X, o
}

// Upload 文件上传,参考:https://opendocs.alipay.com/open-v3/054oog?pathHash=7834d743
func (c *ClientV3) Upload(ctx context.Context, path string, form libHttp.UploadForm, options ...V3HeaderOption) (*APIResult, error) {
func (c *ClientV3) Upload(ctx context.Context, path string, form lib_http.UploadForm, options ...V3HeaderOption) (*APIResult, error) {
reqID := uuid.NewString()
reqURL := c.url(path, nil)

Expand All @@ -196,7 +196,7 @@ func (c *ClientV3) Upload(ctx context.Context, path string, form libHttp.UploadF
if err != nil {
return nil, err
}
reqHeader.Set(libHttp.HeaderAuthorization, authStr)
reqHeader.Set(lib_http.HeaderAuthorization, authStr)

log.SetReqHeader(reqHeader)

Expand Down Expand Up @@ -307,7 +307,7 @@ func (c *ClientV3) Encrypt(data string) (string, error) {
return "", err
}

ct, err := libCrypto.AESEncryptCBC(key, make([]byte, 16), []byte(data))
ct, err := lib_crypto.AESEncryptCBC(key, make([]byte, 16), []byte(data))
if err != nil {
return "", err
}
Expand All @@ -327,7 +327,7 @@ func (c *ClientV3) Decrypt(encryptData string) ([]byte, error) {
return nil, err
}

return libCrypto.AESDecryptCBC(key, make([]byte, 16), data)
return lib_crypto.AESDecryptCBC(key, make([]byte, 16), data)
}

// V3Option 自定义设置项
Expand All @@ -336,19 +336,19 @@ type V3Option func(c *ClientV3)
// WithV3Client 设置自定义 HTTP Client
func WithV3Client(cli *http.Client) V3Option {
return func(c *ClientV3) {
c.httpCli = libHttp.NewHTTPClient(cli)
c.httpCli = lib_http.NewHTTPClient(cli)
}
}

// WithV3PrivateKey 设置商户RSA私钥
func WithV3PrivateKey(key *libCrypto.PrivateKey) V3Option {
func WithV3PrivateKey(key *lib_crypto.PrivateKey) V3Option {
return func(c *ClientV3) {
c.prvKey = key
}
}

// WithV3PublicKey 设置平台RSA公钥
func WithV3PublicKey(key *libCrypto.PublicKey) V3Option {
func WithV3PublicKey(key *lib_crypto.PublicKey) V3Option {
return func(c *ClientV3) {
c.pubKey = key
}
Expand All @@ -367,7 +367,7 @@ func NewClientV3(appid, aesKey string, options ...V3Option) *ClientV3 {
host: "https://openapi.alipay.com",
appid: appid,
aesKey: aesKey,
httpCli: libHttp.NewDefaultClient(),
httpCli: lib_http.NewDefaultClient(),
}

for _, f := range options {
Expand All @@ -383,7 +383,7 @@ func NewSandboxV3(appid, aesKey string, options ...V3Option) *ClientV3 {
host: "http://openapi.sandbox.dl.alipaydev.com",
appid: appid,
aesKey: aesKey,
httpCli: libHttp.NewDefaultClient(),
httpCli: lib_http.NewDefaultClient(),
}

for _, f := range options {
Expand Down
24 changes: 12 additions & 12 deletions antchain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ import (
"github.com/tidwall/gjson"

"github.com/shenghui0779/sdk-go/lib"
libCrypto "github.com/shenghui0779/sdk-go/lib/crypto"
libHttp "github.com/shenghui0779/sdk-go/lib/http"
lib_crypto "github.com/shenghui0779/sdk-go/lib/crypto"
lib_http "github.com/shenghui0779/sdk-go/lib/http"
)

// Config 客户端配置
type Config struct {
BizID string `json:"biz_id"` // 链ID (a00e36c5)
TenantID string `json:"tenant_id"` // 租户ID
AccessID string `json:"access_id"` // AccessID
AccessKey *libCrypto.PrivateKey `json:"access_key"` // AccessKey
Account string `json:"account"` // 链账户
MyKmsKeyID string `json:"mykmskey_id"` // 托管标识
BizID string `json:"biz_id"` // 链ID (a00e36c5)
TenantID string `json:"tenant_id"` // 租户ID
AccessID string `json:"access_id"` // AccessID
AccessKey *lib_crypto.PrivateKey `json:"access_key"` // AccessKey
Account string `json:"account"` // 链账户
MyKmsKeyID string `json:"mykmskey_id"` // 托管标识
}

// Client 发送请求使用的客户端
Expand Down Expand Up @@ -74,7 +74,7 @@ func WithParam(key string, value any) ChainCallOption {
type client struct {
endpoint string
config *Config
httpCli libHttp.HTTPClient
httpCli lib_http.Client
logger func(ctx context.Context, data map[string]string)
}

Expand Down Expand Up @@ -150,7 +150,7 @@ func (c *client) do(ctx context.Context, reqURL string, params lib.X) (string, e

log.SetReqBody(string(body))

resp, err := c.httpCli.Do(ctx, http.MethodPost, reqURL, body, libHttp.WithHeader(libHttp.HeaderContentType, libHttp.ContentJSON))
resp, err := c.httpCli.Do(ctx, http.MethodPost, reqURL, body, lib_http.WithHeader(lib_http.HeaderContentType, lib_http.ContentJSON))
if err != nil {
return "", err
}
Expand Down Expand Up @@ -184,7 +184,7 @@ type Option func(c *client)
// WithHttpCli 设置自定义 HTTP Client
func WithHttpCli(httpCli *http.Client) Option {
return func(c *client) {
c.httpCli = libHttp.NewHTTPClient(httpCli)
c.httpCli = lib_http.NewHTTPClient(httpCli)
}
}

Expand All @@ -200,7 +200,7 @@ func NewClient(cfg *Config, options ...Option) Client {
c := &client{
endpoint: "https://rest.baas.alipay.com",
config: cfg,
httpCli: libHttp.NewDefaultClient(),
httpCli: lib_http.NewDefaultClient(),
}

for _, f := range options {
Expand Down
16 changes: 8 additions & 8 deletions esign/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (
"github.com/tidwall/gjson"

"github.com/shenghui0779/sdk-go/lib"
libHttp "github.com/shenghui0779/sdk-go/lib/http"
lib_http "github.com/shenghui0779/sdk-go/lib/http"
)

// Client E签宝客户端
type Client struct {
host string
appid string
secret string
httpCli libHttp.HTTPClient
httpCli lib_http.Client
logger func(ctx context.Context, data map[string]string)
}

Expand Down Expand Up @@ -58,7 +58,7 @@ func (c *Client) do(ctx context.Context, method, path string, query url.Values,

header := http.Header{}

header.Set(libHttp.HeaderAccept, AcceptAll)
header.Set(lib_http.HeaderAccept, AcceptAll)
header.Set(HeaderTSignOpenAppID, c.appid)
header.Set(HeaderTSignOpenAuthMode, AuthModeSign)
header.Set(HeaderTSignOpenCaTimestamp, strconv.FormatInt(time.Now().UnixMilli(), 10))
Expand All @@ -83,7 +83,7 @@ func (c *Client) do(ctx context.Context, method, path string, query url.Values,

contentMD5 := ContentMD5(body)

header.Set(libHttp.HeaderContentType, "application/json; charset=UTF-8")
header.Set(lib_http.HeaderContentType, "application/json; charset=UTF-8")
header.Set(HeaderContentMD5, contentMD5)

options = append(options, WithSignContMD5(contentMD5), WithSignContType("application/json; charset=UTF-8"))
Expand Down Expand Up @@ -132,7 +132,7 @@ func (c *Client) doStream(ctx context.Context, uploadURL string, reader io.ReadS

header := http.Header{}

header.Set(libHttp.HeaderContentType, libHttp.ContentStream)
header.Set(lib_http.HeaderContentType, lib_http.ContentStream)
header.Set(HeaderContentMD5, base64.StdEncoding.EncodeToString(h.Sum(nil)))

log.SetReqHeader(header)
Expand Down Expand Up @@ -227,7 +227,7 @@ type Option func(c *Client)
// WithHttpCli 设置自定义 HTTP Client
func WithHttpCli(cli *http.Client) Option {
return func(c *Client) {
c.httpCli = libHttp.NewHTTPClient(cli)
c.httpCli = lib_http.NewHTTPClient(cli)
}
}

Expand All @@ -244,7 +244,7 @@ func NewClient(appid, secret string, options ...Option) *Client {
host: "https://openapi.esign.cn",
appid: appid,
secret: secret,
httpCli: libHttp.NewDefaultClient(),
httpCli: lib_http.NewDefaultClient(),
}

for _, f := range options {
Expand All @@ -260,7 +260,7 @@ func NewSandbox(appid, secret string, options ...Option) *Client {
host: "https://smlopenapi.esign.cn",
appid: appid,
secret: secret,
httpCli: libHttp.NewDefaultClient(),
httpCli: lib_http.NewDefaultClient(),
}

for _, f := range options {
Expand Down
Loading

0 comments on commit adc97df

Please sign in to comment.