esap / wechat Goto Github PK
View Code? Open in Web Editor NEW微信SDK的golang实现,短小精悍,同时兼容【企业号/服务号/订阅号/小程序】
License: MIT License
微信SDK的golang实现,短小精悍,同时兼容【企业号/服务号/订阅号/小程序】
License: MIT License
你的快递已到,请携带工卡前往邮件中心领取。\n出发前可查看< a href= "http://work.weixin.qq.com\">邮件中心视频实况</ a>,聪明避开排队。
调用一般会有多种格式 xml或json不同的情况, 也要对应不同的解析。
我想建议通过对请求http头 content-type 来进行区分,这种通用性高一些。
另外小程序也是一点比较好的点, 可以多搞搞。
要不wechat.New/Set的参数用一个结构体怎样 ,那样就可以按需显示传参了
比如
WechatConfig struct {
token string
appid string
secret string
ExternalTokenHandler func(string)
......
}
wechat.New(WechatConfig {token:"",appid:"",secret:"",ExternalTokenHandler: func(appId string) *accessToken{} })
是否可以支持微信支付,微信卡券呢
您好,这个版本和silenceper的版本区别在哪里?
有没有模板消息接口呢?谢谢。
// 创建企业微信实例
cfg := &wechat.WxConfig{
Token: "yourToken",
AppId: "yourCorpID",
AgentId: "yourAgentId",
Secret: "yourSecret",
EncodingAESKey: "yourEncodingAesKey",
AppType: 1,
}
请问这几个参数都是神魔意义,从企业号的哪里能看到?
***2ccf[0]本地获取token:&{28_8vZw1BLTdZWLehP6k696CJRZm2reQJp5RqBWEV3C4pJTGgpEt-tkKCYYr9ZoFTRDHIeaeic9F1awTlkrI5CG8kVs3dU7pqwPEH1OtZVAhFDo0T216Ded9AVRuKFXiWTtPVq0naXZW6KuZxCFLIDhAIADAV 1576143635 {0 }}
不知道为什么会把我测试的token打印出来,并没有开启Debug
支持go.mod
辛苦了,API很nice
2021/12/05 18:38:42 POST | /wx/?signature=054e6f1efa0a99050e1baad62f1720511b23dfd5×tamp=1638700720&nonce=1388272663&openid=oNf6L5wGUQaA4O9n2J9GOP5lgfcY
2021/12/05 18:38:42 http: panic serving 127.0.0.1:43256: runtime error: index out of range [-1]
goroutine 369 [running]:
net/http.(*conn).serve.func1()
/opt/hostedtoolcache/go/1.17.3/x64/src/net/http/server.go:1801 +0xb9
panic({0x1007540, 0xc00114ff20})
/opt/hostedtoolcache/go/1.17.3/x64/src/runtime/panic.go:1047 +0x266
github.com/rixingyike/wechat/util.PKCS7UnPad(...)
/home/runner/go/pkg/mod/github.com/rixingyike/[email protected]/util/crypto.go:30
github.com/rixingyike/wechat/util.AesDecrypt({0x1badf10, 0x0, 0x0}, {0xc00045b1d0, 0x0, 0x0})
/home/runner/go/pkg/mod/github.com/rixingyike/[email protected]/util/crypto.go:24 +0x16a
github.com/rixingyike/wechat.(*Server).DecryptMsg(0xc000103ba0, {0x0, 0x3})
/home/runner/go/pkg/mod/github.com/rixingyike/[email protected]/server.go:261 +0x53
github.com/rixingyike/wechat.(*Server).VerifyURL(0xc000103ba0, {0x7f3e95de5660, 0xc000622200}, 0xc0007b6800)
/home/runner/go/pkg/mod/github.com/rixingyike/[email protected]/server.go:230 +0x6c5
github.com/cdle/sillyGirl/im/wxmp.init.0.func1(0xc000622200)
/home/runner/work/sillyGirl/sillyGirl/im/wxmp/init.go:31 +0x70
github.com/gin-gonic/gin.(*Context).Next(...)
/home/runner/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc000344b60, 0xc000622200)
/home/runner/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:489 +0x63e
github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc000344b60, {0x1279568, 0xc000410700}, 0xc0007b6800)
/home/runner/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:445 +0x1c5
net/http.serverHandler.ServeHTTP({0x1277340}, {0x1279568, 0xc000410700}, 0xc0007b6800)
/opt/hostedtoolcache/go/1.17.3/x64/src/net/http/server.go:2878 +0x43b
net/http.(*conn).serve(0xc0002fb360, {0x1283f00, 0xc00078dd70})
/opt/hostedtoolcache/go/1.17.3/x64/src/net/http/server.go:1929 +0xb08
created by net/http.(*Server).Serve
/opt/hostedtoolcache/go/1.17.3/x64/src/net/http/server.go:3033 +0x4e8
当ip不在白名单时,抛出不可恢复的异常
errcode=40164 , errmsg=invalid ip 0.0.0.0, not in whitelist hint:
panic: runtime error: invalid memory address or nil pointer dereference
搞了半天,没弄清楚怎么调用Jscode2Session
Hi @esap , Please tag a new version for go.mod.
Thank you so much.
自动回复的xml消息五花八门 最好是带上CDATA吧
调用方式: wechat.Set(TOKEN, APPID, SECRET)
报错信息如下:
2018/04/11 17:13:13 公众号用户: [] err: errcode=48001 , errmsg=api unauthorized hint:
原因是 server.go 中func (s *Server) Set() 针对accessToken不为空的情况,118行 调用了 b, err := s.BatchGetAll() , 这个else的功能是否可以去掉。
tlpdata:= map[string]struct {
value string
color string
}{"first": {value: "我是渣渣涛", color: "#173177"},
"keyword1": {value: "这是一个你从没有玩过的全新游戏", color: "#173177"},
"keyword2": {value: "只要你跟着我一起试玩一下", color: "#173177"},
"keyword3": {value: "你就会爱上这款游戏", color: "#4B1515"},
"remark": {value: "是兄弟就来砍我", color: "#071D42"},
}
msgid,_ := ctx.SendTemplate(
ctx.Msg.FromUserName,
"tempid",
c.Request.Host,
ctx.AppId,
"",
tlpdata,
)
2021/02/24 15:11:55 GET | /?signature=edb3487a194889b8a434b623c48d1aa6a76f80ad&echostr=6812425678080704511×tamp=1614150715&nonce=139261658
2021/02/24 15:11:55 api echostr: 6812425678080704511
2021/02/24 15:11:55 Wechat <== &{wxResp:{XMLName:{Space: Local:} ToUserName: ToParty: ToTag: FromUserName: CreateTime:1614150715 MsgType:text AgentId:0 Safe:0} content:{Content:查询OK}}
2021/02/24 15:11:55 [*] 发送消息:&{wxResp:{XMLName:{Space: Local:} ToUserName: ToParty: ToTag: FromUserName: CreateTime:1614150715 MsgType:text AgentId:0 Safe:0} content:{Content:客服消息1}}
[*] 回执:{ErrCode:40003 ErrMsg:invalid openid rid: 6035fc3b-4873a3bb-3f1bb871}
2021/02/24 15:11:55 MsgSend err: invalid openid rid: 6035fc3b-4873a3bb-3f1bb871
2021/02/24 15:11:55 [*] 发送消息:&{wxResp:{XMLName:{Space: Local:} ToUserName: ToParty: ToTag: FromUserName: CreateTime:1614150715 MsgType:text AgentId:0 Safe:0} content:{Content:客服消息2}}
[*] 回执:{ErrCode:40003 ErrMsg:invalid openid rid: 6035fc3b-4e6422d5-5c88cae2}
2021/02/24 15:11:55 MsgSend err: invalid openid rid: 6035fc3b-4e6422d5-5c88cae2
cfg := &wechat.WxConfig{
Token: "",
AppId: "",
Secret: "",
EncodingAESKey: "",
ExternalTokenHandler: func(appId string, appName ...string) *wechat.AccessToken {
fmt.Println("运行getAccessToken")
// TODO fetch远程数据,暂时写死
var accessToken *wechat.AccessToken
accessToken.AccessToken = "44_eqMb2oNPeuiwS0LKsA42UXRKpuHVbutgLaENZY1j27Mp4_d1Ao64AbnkmMjD4wKKT-ktN17rUddK_sd10RXk7YmstjboRZ84qHIdUnD30_nUg_FDuWoiwswz7RuRUHqccFap8zNLM_rl987dZBJbAIAHJR"
accessToken.ExpiresIn = 1619153293
return accessToken
},
}
运行getAccessToken
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x12a2a1b]
goroutine 1 [running]:
main.main.func1(0x13344f4, 0x12, 0xc000098db0, 0x1, 0x1, 0x1ed)
/Users/zyk/go/src/waimai-mp/main.go:44 +0x7b
github.com/esap/wechat.(*Server).getAccessToken(0xc00009e9c0, 0xc00009e9c0, 0x14f1760)
/Users/zyk/go/pkg/mod/github.com/esap/[email protected]/accesstoken.go:54 +0x19c
github.com/esap/wechat.New(0xc0000b5f00, 0x1041a0a)
/Users/zyk/go/pkg/mod/github.com/esap/[email protected]/server.go:121 +0x1aa
main.main()
/Users/zyk/go/src/waimai-mp/main.go:50 +0xcf
exit status 2
请问使用New时secret使用的是应用级别的,无法操作通讯录,是不是要再NEW一个有通讯录权限?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.