package context import ( "encoding/json" "errors" "fmt" ) //ErrUnmarshall err when unmarshall var ErrUnmarshall = errors.New("json Unmarshal Error") //WxError 微信返回的错误信息 type WxError struct { Code int64 `json:"errcode"` Msg string `json:"errmsg"` } //NewWxError new NewWxError func NewWxError(code int64, msg string) *WxError { return &WxError{Code: code, Msg: msg} } func (e *WxError) Error() string { return e.Msg } //CheckCommonError check CommonError func CheckCommonError(jsonData []byte) error { var errmsg WxError if err := json.Unmarshal(jsonData, &errmsg); err != nil { return ErrUnmarshall } if errmsg.Code != 0 { return fmt.Errorf("Error , errcode=%d , errmsg=%s", errmsg.Code, errmsg.Msg) } return nil }