- refactor.

This commit is contained in:
gazebo
2018-06-13 11:41:48 +08:00
parent 0fc65c457a
commit 892c814b0e
4 changed files with 27 additions and 19 deletions

View File

@@ -11,11 +11,9 @@ import (
"net/url" "net/url"
"sort" "sort"
"strconv" "strconv"
"strings"
"time" "time"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"github.com/satori/go.uuid"
"go.uber.org/zap" "go.uber.org/zap"
) )
@@ -97,19 +95,7 @@ var (
type PageResultParser func(map[string]interface{}, int) ([]interface{}, int) type PageResultParser func(map[string]interface{}, int) ([]interface{}, int)
func getUUID() string { func signParams(jdParams map[string]string) string {
return strings.ToUpper(strings.Replace(uuid.Must(uuid.NewV1()).String(), "-", "", -1))
}
func getJDOperator() string {
return time.Now().Format("2006-01-02_15:04:05")
}
func getCurTimeStr() string {
return time.Now().Format("2006-01-02 15:04:05")
}
func SignParams(jdParams map[string]string) string {
var keys []string var keys []string
for k := range jdParams { for k := range jdParams {
if k != "app_secret" { if k != "app_secret" {
@@ -166,8 +152,8 @@ func (j JDAPI) AccessJDQuery(apiStr string, jdParams map[string]string) (map[str
return nil, ErrJdParam return nil, ErrJdParam
} }
params["timestamp"] = getCurTimeStr() params["timestamp"] = utils.GetCurTimeStr()
sign := SignParams(params) sign := signParams(params)
params["sign"] = sign params["sign"] = sign
exceedLimitRetryCount := 0 exceedLimitRetryCount := 0

View File

@@ -4,6 +4,7 @@ import (
"net/http" "net/http"
"testing" "testing"
"git.rosy.net.cn/baseapi/utils"
"go.uber.org/zap" "go.uber.org/zap"
) )
@@ -19,7 +20,7 @@ func init() {
} }
func TestTest(t *testing.T) { func TestTest(t *testing.T) {
sugarLogger.Debug(getCurTimeStr()) sugarLogger.Debug(utils.GetCurTimeStr())
} }
func TestAccessJDQuery(t *testing.T) { func TestAccessJDQuery(t *testing.T) {

View File

@@ -76,7 +76,7 @@ func (j JDAPI) OrderAcceptOperate(orderId string, isAgreed bool) (interface{}, e
jdParams := map[string]string{ jdParams := map[string]string{
"orderId": orderId, "orderId": orderId,
"isAgreed": utils.Bool2String(isAgreed), "isAgreed": utils.Bool2String(isAgreed),
"operator": getJDOperator(), "operator": utils.GetAPIOperator(),
} }
return j.AccessJDQueryNoPage("ocs/orderAcceptOperate", jdParams, nil, nil) return j.AccessJDQueryNoPage("ocs/orderAcceptOperate", jdParams, nil, nil)
} }

View File

@@ -6,6 +6,10 @@ import (
"fmt" "fmt"
"reflect" "reflect"
"strconv" "strconv"
"strings"
"time"
"github.com/satori/go.uuid"
) )
func GetConcretValue(value reflect.Value) reflect.Value { func GetConcretValue(value reflect.Value) reflect.Value {
@@ -120,3 +124,20 @@ func Int64ToStr(value int64) string {
func Int2Str(value int) string { func Int2Str(value int) string {
return strconv.Itoa(value) return strconv.Itoa(value)
} }
// 去除-号全部大写比如929ADB626EB911E893E452540009DAB3
func GetUUID() string {
return strings.ToUpper(strings.Replace(uuid.Must(uuid.NewV1()).String(), "-", "", -1))
}
func GetCurTimeStr() string {
return time.Now().Format("2006-01-02 15:04:05")
}
func GetCurTimestamp() int64 {
return time.Now().Unix()
}
func GetAPIOperator() string {
return time.Now().Format("2006-01-02_15:04:05")
}