|
@@ -6,9 +6,11 @@ import (
|
|
|
"encoding/xml"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "math/rand"
|
|
|
"sort"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
+ "time"
|
|
|
|
|
|
"git.chuangxin1.com/cx/util"
|
|
|
)
|
|
@@ -120,6 +122,20 @@ func Sign(req map[string]interface{}, key string) (sign string) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+func Random(n int) string {
|
|
|
+ str := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
|
+ bytes := []byte(str)
|
|
|
+ result := []byte{}
|
|
|
+
|
|
|
+ r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
+ n1 := len(bytes)
|
|
|
+ for i := 0; i < n; i++ {
|
|
|
+ result = append(result, bytes[r.Intn(n1)])
|
|
|
+ }
|
|
|
+ return string(result)
|
|
|
+}
|
|
|
+
|
|
|
func makeSignature(token, signature, timestamp, nonce string) bool {
|
|
|
sl := []string{token, timestamp, nonce}
|
|
|
sort.Strings(sl)
|