示例#1
0
// Response returns the response body data for the request from wechat mp platform.
func (h *recvHandler) Response(msg []byte, encryptType string) ([]byte, error) {
	if encryptType == "aes" {
		msgEncrypt, err := EncryptMsg(msg, h.appID, h.encodingAESKey)
		if err != nil {
			return nil, err
		}

		nonce := pb.GenNonce()
		timestamp := pb.GenTimestamp()
		signature := pb.GenSignature(h.token, fmt.Sprintf("%d", timestamp), nonce, msgEncrypt)

		resp := &RecvHTTPEncryptRespBody{
			Encrypt:      pb.String2CDATA(msgEncrypt),
			MsgSignature: pb.String2CDATA(signature),
			TimeStamp:    timestamp,
			Nonce:        pb.String2CDATA(nonce),
		}
		return xml.MarshalIndent(resp, " ", "  ")
	}
	return msg, nil
}
示例#2
0
// dev_msg_signature=sha1(sort(token、timestamp、nonce、msg_encrypt))
func genSignature(token, timestamp, nonce, msgEncrypt string) string {
	return pb.GenSignature(token, timestamp, nonce, msgEncrypt)
}
示例#3
0
func genSignature(token, timestamp, nonce string) string {
	return pb.GenSignature(token, timestamp, nonce)
}