|
|
@@ -3,7 +3,7 @@ package gopay
|
|
|
import (
|
|
|
"crypto/md5"
|
|
|
"encoding/hex"
|
|
|
- "encoding/xml"
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
"strings"
|
|
|
"testing"
|
|
|
@@ -18,17 +18,65 @@ func TestMd5(t *testing.T) {
|
|
|
fmt.Println(" ssad ", upper)
|
|
|
}
|
|
|
|
|
|
+type Student struct {
|
|
|
+ Name string `json:"name,omitempty"`
|
|
|
+ Age int `json:"age,omitempty"`
|
|
|
+ Sign string `json:"sign,omitempty"`
|
|
|
+ Phone string `json:"phone,omitempty"`
|
|
|
+}
|
|
|
+
|
|
|
func TestBodyMap_MarshalXML(t *testing.T) {
|
|
|
|
|
|
- maps := make(BodyMap)
|
|
|
- maps.Set("name", "jerry")
|
|
|
- maps.Set("age", 28)
|
|
|
- maps.Set("phone", "13212345678")
|
|
|
+ student := new(Student)
|
|
|
+ student.Name = "Jerry"
|
|
|
+ student.Age = 28
|
|
|
+ student.Phone = "18017448610"
|
|
|
|
|
|
- bytes, err := xml.Marshal(&maps)
|
|
|
+ marshal, err := json.Marshal(student)
|
|
|
if err != nil {
|
|
|
fmt.Println("err:", err)
|
|
|
}
|
|
|
- fmt.Println("ssss:", string(bytes))
|
|
|
|
|
|
+ fmt.Println("marshal:", string(marshal))
|
|
|
+
|
|
|
+ maps := make(map[string]interface{})
|
|
|
+
|
|
|
+ err = json.Unmarshal(marshal, &maps)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("err2:", err)
|
|
|
+ }
|
|
|
+ fmt.Println("maps:", maps)
|
|
|
+
|
|
|
+ //maps := make(BodyMap)
|
|
|
+ //maps.Set("name", "jerry")
|
|
|
+ //maps.Set("age", 28)
|
|
|
+ //maps.Set("phone", "13212345678")
|
|
|
+ //
|
|
|
+ //bytes, err := xml.Marshal(&maps)
|
|
|
+ //if err != nil {
|
|
|
+ // fmt.Println("err:", err)
|
|
|
+ //}
|
|
|
+ //fmt.Println("ssss:", string(bytes))
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func TestVerifyWeChatResponseSign(t *testing.T) {
|
|
|
+ student := new(Student)
|
|
|
+ student.Name = "Jerry"
|
|
|
+ student.Age = 1
|
|
|
+ student.Sign = "544E55ED43B787B945FF0BF8344A4D69"
|
|
|
+ student.Phone = "18017448610"
|
|
|
+
|
|
|
+ maps := make(BodyMap)
|
|
|
+ maps["name"] = "Jerry"
|
|
|
+ maps["age"] = 1
|
|
|
+ maps["sign"] = "544E55ED43B787B945FF0BF8344A4D69"
|
|
|
+ maps["phone"] = "18017448610"
|
|
|
+
|
|
|
+ ok, err := VerifyWeChatSign("ABCDEFG", "MD5", student)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("errrrr:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Println("ok:", ok)
|
|
|
}
|