mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
30c8e77246651e64cdda4940ae661c197f0f62d0
* fix: improve type safety in httpWithTLS for custom RoundTripper Add type assertion check to handle cases where DefaultHTTPClient.Transport is a custom http.RoundTripper implementation (not *http.Transport). This improves upon the fix in PR #844 which only handled nil Transport. The previous code would still panic if users set a custom RoundTripper: trans := baseTransport.(*http.Transport).Clone() // panic if not *http.Transport Now safely handles three scenarios: 1. Transport is nil -> use http.DefaultTransport 2. Transport is *http.Transport -> clone it 3. Transport is custom RoundTripper -> use http.DefaultTransport Added comprehensive test cases: - TestHttpWithTLS_NilTransport - TestHttpWithTLS_CustomTransport - TestHttpWithTLS_CustomRoundTripper Related to #803 * refactor: reduce code duplication and complexity in httpWithTLS - Eliminate duplicate http.DefaultTransport.Clone() calls - Reduce cyclomatic complexity by simplifying conditional logic - Use nil check pattern instead of nested else branches - Maintain same functionality with cleaner code structure This addresses golangci-lint warnings for dupl and gocyclo. * fix: add newline at end of http_test.go Fix gofmt -s compliance issue: - File must end with newline character - Addresses golangci-lint gofmt error on line 81 This fixes CI check failure.
WeChat SDK for Go
使用Golang开发的微信SDK,简单、易用。
文档 && 例子
快速开始
import "github.com/silenceper/wechat/v2"
以下是一个微信公众号处理消息接收以及回复的例子:
// 使用memcache保存access_token,也可选择redis或自定义cache
wc := wechat.NewWechat()
memory := cache.NewMemory()
cfg := &offConfig.Config{
AppID: "xxx",
AppSecret: "xxx",
Token: "xxx",
// EncodingAESKey: "xxxx",
Cache: memory,
}
officialAccount := wc.GetOfficialAccount(cfg)
// 传入request和responseWriter
server := officialAccount.GetServer(req, rw)
// 设置接收消息的处理方法
server.SetMessageHandler(func(msg *message.MixMessage) *message.Reply {
// 回复消息:演示回复用户发送的消息
text := message.NewText(msg.Content)
return &message.Reply{MsgType: message.MsgTypeText, MsgData: text}
})
// 处理消息接收以及回复
err := server.Serve()
if err != nil {
fmt.Println(err)
return
}
// 发送回复的消息
server.Send()
目录说明
- officialaccount: 微信公众号API
- miniprogram: 小程序API
- minigame:小游戏API
- pay:微信支付API
- openplatform:开放平台API
- work:企业微信
- aispeech:智能对话
- doc: api文档
贡献
- 在API列表中查看哪些API未实现
- 提交issue,描述需要贡献的内容
- 完成更改后,提交PR
感谢以下贡献者
作者公众号
License
Apache License, Version 2.0
Description
Languages
Go
98.7%
C++
0.8%
C
0.5%
