github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/internal/debug/mch/callback/debug.go (about)

     1  //go:build wechat_debug
     2  // +build wechat_debug
     3  
     4  package callback
     5  
     6  import (
     7  	"bytes"
     8  	"io"
     9  	"log"
    10  	"net/http"
    11  
    12  	"github.com/chanxuehong/util"
    13  )
    14  
    15  func DebugPrintRequest(r *http.Request) {
    16  	log.Println("[WECHAT_DEBUG] [MCH] [CALLBACK]", r.Method, r.RequestURI)
    17  }
    18  
    19  func DebugPrintRequestMessage(msg []byte) {
    20  	log.Printf("[WECHAT_DEBUG] [MCH] [CALLBACK] http request body:\n%s\n", msg)
    21  }
    22  
    23  func EncodeXMLResponseMessage(w io.Writer, msg map[string]string) (err error) {
    24  	var buf bytes.Buffer
    25  	if err = util.EncodeXMLFromMap(&buf, msg, "xml"); err != nil {
    26  		return
    27  	}
    28  	log.Printf("[WECHAT_DEBUG] [MCH] [CALLBACK] http response body:\n%s\n", buf.Bytes())
    29  
    30  	_, err = buf.WriteTo(w)
    31  	return
    32  }