xen0n / go-workwx

a sensible WeCom (企业微信, Wechat Work, Work Weixin) SDK for Go
https://godoc.org/github.com/xen0n/go-workwx
MIT License
653 stars 164 forks source link

can not run example #62

Open lucasjinreal opened 3 years ago

lucasjinreal commented 3 years ago
./main.go:15:7: undefined: workwx.RxMessageHandler
./main.go:18:53: undefined: workwx.RxMessage
./main.go:31:13: undefined: workwx.NewHTTPHandler
xen0n commented 3 years ago

Insufficient information, please provide more context (for example whole terminal session recorded with asciinema or similar services) so people could debug.

lucasjinreal commented 3 years ago

@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

lucasjinreal commented 3 years ago

@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")
xen0n commented 3 years ago

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.

lucasjinreal commented 3 years ago

@xen0n Which official step? I can not found such field in Wechatwork's doc.

xen0n commented 3 years ago

@xen0n Which official step? I can not found such field in Wechatwork's doc.

Try this

lucasjinreal commented 3 years ago

@xen0n thanks!

How's the url in the settings? I only need to set token and encodedAESKey ?

xen0n commented 3 years ago

@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.