Open lucasjinreal opened 3 years ago
Insufficient information, please provide more context (for example whole terminal session recorded with asciinema or similar services) so people could debug.
@xen0n Sure. I simply copied the example go code and created a simple project:
package main
import (
"flag"
"fmt"
"net/http"
"github.com/xen0n/go-workwx"
)
type dummyRxMessageHandler struct{}
var _ workwx.RxMessageHandler = dummyRxMessageHandler{}
// OnIncomingMessage 一条消息到来时的回调。
func (dummyRxMessageHandler) OnIncomingMessage(msg *workwx.RxMessage) error {
// You can do much more!
fmt.Printf("incoming message: %s\n", msg)
return nil
}
func main() {
pAddr := flag.String("addr", "[::]:8000", "address and port to listen on")
pToken := flag.String("token", "", "configured Token of your work weixin app")
pEncodingAESKey := flag.String("key", "", "configured EncodingAESKey of your work weixin app")
flag.Parse()
hh, err := workwx.NewHTTPHandler(*pToken, *pEncodingAESKey, dummyRxMessageHandler{})
if err != nil {
panic(err)
}
mux := http.NewServeMux()
mux.Handle("/", hh)
err = http.ListenAndServe(*pAddr, mux)
if err != nil {
panic(err)
}
}
When i run go build -o main *.go
, the error when build:
Oh, I using another machine and not using go.mod, it seems can build
@xen0n How to get this 2 params?
pToken := flag.String("token", "", "configured Token of your work weixin app")
pEncodingAESKey := flag.String("key", "", "configured EncodingAESKey of your work weixin app")
Oh, I using another machine and not using go.mod, it seems can build
Simply ensure your environment is clean then. ;-)
How to get this 2 params?
You just follow the official docs step by step. The Token
and EncodingAESKey
nomenclature is deliberately kept consistent.
@xen0n Which official step? I can not found such field in Wechatwork's doc.
@xen0n Which official step? I can not found such field in Wechatwork's doc.
Try this
@xen0n thanks!
How's the url in the settings? I only need to set token and encodedAESKey ?
@xen0n thanks!
How's the url in the settings? I only need to set token and encodedAESKey ?
You have to mount the application at some domain, of course. Once you have the receiver properly exposed, simply fill in the two parameters and the test for receiving messages should just succeed.