-
Notifications
You must be signed in to change notification settings - Fork 1
/
http.go
66 lines (56 loc) · 1.55 KB
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"github.com/SunRich/wechat/cache"
"github.com/SunRich/wechat"
"github.com/SunRich/wechat/material"
"net/http"
"github.com/SunRich/wechat/message"
)
func hello(rw http.ResponseWriter, req *http.Request) {
//配置微信参数
config := &wechat.Config{
AppID: "your app id",
AppSecret: "your app secret",
Token: "your token",
EncodingAESKey: "your encoding aes key",
}
wc := wechat.NewWechat(config)
// 传入request和responseWriter
server := wc.GetServer(req, rw)
//设置接收消息的处理方法
server.SetMessageHandler(func(msg message.MixMessage) *message.Reply {
//回复消息:演示回复用户发送的消息
text := message.NewText(msg.Content)
return &message.Reply{message.MsgTypeText, text}
})
//处理消息接收以及回复
err := server.Serve()
if err != nil {
fmt.Println(err)
return
}
//发送回复的消息
server.Send()
}
func main() {
//配置微信参数
redis := cache.NewRedis("192.168.118.174:6379","")
config := &wechat.Config{
AppID: "wx235a8df325c1f364",
AppSecret: "your app secret",
Token: "your token",
EncodingAESKey: "your encoding aes key",
Cache: redis,
}
wc := wechat.NewWechat(config)
m := material.NewMaterial(wc.Context)
url,err:=m.GetMediaURL("UOPeYV3zne3VdhFO1hG8l8-FBAxyDPtCM7iHNBN0_KqJrfcgMhvruxsu8ybNCGnN")
fmt.Println(url)
fmt.Println(err)
http.HandleFunc("/", hello)
err := http.ListenAndServe(":8001", nil)
if err != nil {
fmt.Printf("start server error , err=%v", err)
}
}