mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-13 00:11:28 +08:00
@@ -3,6 +3,8 @@ package builtin
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/hmac"
|
||||||
|
"crypto/sha256"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
builtinJSON "encoding/json"
|
builtinJSON "encoding/json"
|
||||||
@@ -15,6 +17,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
@@ -565,3 +568,18 @@ func SplitInteger(m, n int) (ints []int) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sha256HMAC(key []byte, data []byte) []byte {
|
||||||
|
mac := hmac.New(sha256.New, key)
|
||||||
|
mac.Write(data)
|
||||||
|
return []byte(fmt.Sprintf("%x", mac.Sum(nil)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ver: auth-v1or auth-v2
|
||||||
|
func Sign(ver string, ak string, sk string, body []byte) string {
|
||||||
|
expiration := 1800
|
||||||
|
signKeyInfo := fmt.Sprintf("%s/%s/%d/%d", ver, ak, time.Now().Unix(), expiration)
|
||||||
|
signKey := sha256HMAC([]byte(sk), []byte(signKeyInfo))
|
||||||
|
signResult := sha256HMAC(signKey, body)
|
||||||
|
return fmt.Sprintf("%v/%v", signKeyInfo, string(signResult))
|
||||||
|
}
|
||||||
|
|||||||
2
hrp/internal/env/env.go
vendored
2
hrp/internal/env/env.go
vendored
@@ -5,6 +5,8 @@ import "os"
|
|||||||
var (
|
var (
|
||||||
WDA_USB_DRIVER = os.Getenv("WDA_USB_DRIVER")
|
WDA_USB_DRIVER = os.Getenv("WDA_USB_DRIVER")
|
||||||
VEDEM_OCR_URL = os.Getenv("VEDEM_OCR_URL")
|
VEDEM_OCR_URL = os.Getenv("VEDEM_OCR_URL")
|
||||||
|
VEDEM_OCR_AK = os.Getenv("VEDEM_OCR_AK")
|
||||||
|
VEDEM_OCR_SK = os.Getenv("VEDEM_OCR_SK")
|
||||||
DISABLE_GA = os.Getenv("DISABLE_GA")
|
DISABLE_GA = os.Getenv("DISABLE_GA")
|
||||||
DISABLE_SENTRY = os.Getenv("DISABLE_SENTRY")
|
DISABLE_SENTRY = os.Getenv("DISABLE_SENTRY")
|
||||||
PYPI_INDEX_URL = os.Getenv("PYPI_INDEX_URL")
|
PYPI_INDEX_URL = os.Getenv("PYPI_INDEX_URL")
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/json"
|
"github.com/httprunner/httprunner/v4/hrp/internal/json"
|
||||||
)
|
)
|
||||||
@@ -64,6 +65,9 @@ func (s *veDEMOCRService) getOCRResult(imageBuf []byte) ([]OCRResult, error) {
|
|||||||
return nil, fmt.Errorf("construct request error: %v", err)
|
return nil, fmt.Errorf("construct request error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
token := builtin.Sign("auth-v2", env.VEDEM_OCR_AK, env.VEDEM_OCR_SK, bodyBuf.Bytes())
|
||||||
|
|
||||||
|
req.Header.Add("Agw-Auth", token)
|
||||||
req.Header.Add("Content-Type", bodyWriter.FormDataContentType())
|
req.Header.Add("Content-Type", bodyWriter.FormDataContentType())
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user