Пример #1
0
func TestString2CDATA(t *testing.T) {
	want := `<![CDATA[toUser]]>`
	field := pb.String2CDATA("toUser")

	if field.Text != want {
		t.Errorf("Want [%s], but actual[%s]", want, field.Text)
	}
}
Пример #2
0
// Response returns the response body data for the request from wechat qy platform.
func (h *recvHandler) Response(msg []byte, encryptType string /* not used */) ([]byte, error) {
	msgEncrypt, err := EncryptMsg(msg, h.corpID, h.encodingAESKey)
	if err != nil {
		return nil, err
	}

	nonce := pb.GenNonce()
	timestamp := pb.GenTimestamp()

	signature := genSignature(h.token, fmt.Sprintf("%d", timestamp), nonce, msgEncrypt)
	resp := &RecvHTTPRespBody{
		Encrypt:      pb.String2CDATA(msgEncrypt),
		MsgSignature: pb.String2CDATA(signature),
		TimeStamp:    timestamp,
		Nonce:        pb.String2CDATA(nonce),
	}

	return xml.MarshalIndent(resp, " ", "  ")
}
Пример #3
0
func TestGenRecvRespBaseDataPkg(t *testing.T) {
	var data = &pb.RecvRespBaseDataPkg{
		ToUserName:   pb.String2CDATA("toUser"),
		FromUserName: pb.String2CDATA("fromUser"),
		CreateTime:   1348831860,
		MsgType:      pb.String2CDATA("text"),
	}

	var want = `<xml>
  <ToUserName><![CDATA[toUser]]></ToUserName>
  <FromUserName><![CDATA[fromUser]]></FromUserName>
  <CreateTime>1348831860</CreateTime>
  <MsgType><![CDATA[text]]></MsgType>
</xml>`
	pkg, err := xml.MarshalIndent(data, "", "  ")
	if err != nil {
		t.Error("Xml marshalling error:", err)
	}

	if string(pkg) != want {
		t.Errorf("Want [%s], but actual[%s]", want, string(pkg))
	}
}