package cryptx import ( "fmt" "testing" ) func TestWXBizMsgCrypt(t *testing.T) { // 1.第三方回复加密消息给公众平台; // 2.第三方收到公众平台发送的消息,验证消息的安全性,并对消息进行解密。 encodingAESKey := "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG" token := "spamtest" appid := "wx2c2769f8efd9abc2" timestamp := int64(1409735669) to_xml := ` 1407743423 ` nonce := "1320562132" // 测试加密接口 cryp_test, err := NewWXBizMsgCrypt(token, encodingAESKey, appid) if err != nil { return } ret, encrypt_xml := cryp_test.EncryptMsg(to_xml, nonce, timestamp) fmt.Println(ret) fmt.Println(encrypt_xml) msg_sign := "ea7a2ac5580e3c67d663b42c63b976b7e2bf26b9" from_xml := `1409735669` // 测试解密接口 //msg_sign := "5d197aaffba7e9b25a30732f161a50dee96bd5fa" //from_xml := `14097356686054768590064713728` ret, decryp_xml := cryp_test.DecryptMsg(from_xml, msg_sign, timestamp, nonce) fmt.Println(ret) fmt.Println(decryp_xml) } func TestWXBizMsgCrypt2(t *testing.T) { // 1.第三方回复加密消息给公众平台; // 2.第三方收到公众平台发送的消息,验证消息的安全性,并对消息进行解密。 encodingAESKey := "E7MKT2IwQzLCxtzc1sjeqjPrftqGFLxomFSv2py0UNx" token := "weixin" appid := "wx4e7d601bea5a8093" timestamp := int64(1680706178) // to_xml := ` 1407743423 ` nonce := "1536850936" // // 测试加密接口 cryp_test, err := NewWXBizMsgCrypt(token, encodingAESKey, appid) if err != nil { return } // ret, encrypt_xml := cryp_test.EncryptMsg(to_xml, nonce, timestamp) // fmt.Println(ret) // fmt.Println(encrypt_xml) msg_sign := "34d5a40b6e17013f0e0aa2e48de98355c15ba6c6" from_xml := ` ` // 测试解密接口 //msg_sign := "5d197aaffba7e9b25a30732f161a50dee96bd5fa" //from_xml := `14097356686054768590064713728` ret, decryp_xml := cryp_test.DecryptMsg(from_xml, msg_sign, timestamp, nonce) fmt.Println(ret) fmt.Println(decryp_xml) }