chanxuehong / wechat Goto Github PK
View Code? Open in Web Editor NEWweixin/wechat/微信公众平台/微信企业号/微信商户平台/微信支付 go/golang sdk
License: Other
weixin/wechat/微信公众平台/微信企业号/微信商户平台/微信支付 go/golang sdk
License: Other
参考:http://mp.weixin.qq.com/wiki/4/b3546879f07623cb30df9ca0e420a5d0.html
如果对于material中的DownloadMaterial(),如果类型是video,会返回的是一个json,其中包含一个下载的url,而不是多媒体文件;
需要增加一个struct来定义,另外如果能在把视频的下载也写到DownloadMaterial就最好了
感觉现在的log设计的不够合理,你们都提提意见,说说怎么处理的比较好
微信更新了两个内容:
详见:http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html
There are two readme files.README.md and readme.md .....
Is there any reason to create two files?
Git have a mistake here, because of the same files, it always says there is a readme.md was deleted.
Can you delete one of them?
微信把poi中的图片列表更新了,最新的格式:
"photo_list":[{"photo_url":"https:// XXX.com"},{"photo_url":"https://
XXX.com"}],
参加【微信卡券】中的文档:https://mp.weixin.qq.com/zh_CN/htmledition/comm_htmledition/res/cardticket/wx_card_document.zip
在 chrome 中访问 https://api.weixin.qq.com/sns/oauth2/access_token?appid=xxx&secret=xxx&code=xxx&grant_type=authorization_code
正常。
但在代码里面调用 token, xerr := oauth2Client.ExchangeToken(code)
得到 xerr:
Get https://api.weixin.qq.com/sns/oauth2/access_token?appid=xxx&secret=xxx&code=xxx&grant_type=authorization_code: dial tcp: i/o timeout
以下命令也超时
curl -sL https://api.weixin.qq.com/sns/oauth2/access_token?appid=xxx&secret=xxx&code=xxx&grant_type=authorization_code
OS: macOS Sierra 10.12.3 (16D30)
还是集思广益
因为微信推送过来的消息如果你5秒内没有处理完毕,会尝试再推送过来一个,总的三次
那么现实中,很有可能因为某些原因(逻辑处理不对在5秒内没有处理完成,或者异常)造成重发消息,
那么有什么好的算法能快速排重呢
集思广益,tks
建议添加log信息或者记录log文件。
在Request中,struct默认所有的属性都会加上,能否加入,omitempty,删除空节点
偶尔会出现这个消息 signature is empty, 然后微信提示 "该公众号暂无法提供服务, 请稍后重试" 我再发一遍, 服务器就收到正常消息了, AES加密的, 就好了, 没机会重现,这个是什么原因??
github.com/chanxuehong/wechat.v2/mp/core/server.go:20:2: cannot find package "github.com/chanxuehong/util/security"
分布式部署下面,有什么推荐的部署方案吗?
我脑袋第一反应的是通过appid了做hash路由。
R.T,打算搜集一下写SDK中微信接口的问题,一块儿写邮件发给他们,求产线生吐槽
https://github.com/chanxuehong/wechat/blob/master/mp/card/card.go#L164
这段代码中,最后total是用户所有卡券的数量,而不是请求中应该包含的卡券数量,所以返回参数中应该加入一个count的值,所以下面的代码是错误的:
if result.TotalNum != len(result.CardIdList) {
err = errors.New("the total_num and length of card_id_list does not match")
return
}
/Web/go/src/github.com/chanxuehong/wechat/mp/serve_http.go:21:2: cannot find package "github.com/chanxuehong/util/security" in any of:
/usr/local/Cellar/go/1.5.1/libexec/src/github.com/chanxuehong/util/security (from $GOROOT)
/Web/go/src/github.com/chanxuehong/util/security (from $GOPATH)
项目中有多处使用该包
现在的DefaultAccessTokenServer只支持单进程吧?
支付微信通知处理的代码有示例吗?最好结合beego的用法
go get -u -v github.com/chanxuehong/wechat.v2
github.com/chanxuehong/wechat.v2 (download)
package github.com/chanxuehong/wechat.v2: no buildable Go source files in /home/defned/.gvm/pkgsets/go1.8.3/global/src/github.com/chanxuehong/wechat.v2
我已经获取了access_token并保存在数据库中,但是当我想建立新的Client实例的时候,只能通过:
NewClient 和 NewClientEx 来创建,但是我别的程序不知道这个appid和secret是多少,而使用Ex有需要构建一个tokenCache的类,能不能暴露一个新的函数:
NewClientFromToken(accessToken string)的方式,传入accessToken就直接创建?
func MicroPay(clt *core.Client, req map[string]string) (resp map[string]string, err error) {
return clt.PostXML("https://api.core.weixin.qq.com/pay/micropay", req)
}
正确的不是https://api.mch.weixin.qq.com/pay/micropay吗?
好象所有的mch被批量替换成了core了。
如果我想定义一个类型,然后所有的到腾讯接口的访问都经过这个类型,就是
https://github.com/chanxuehong/wechat/blob/master/mp/shakearound/account/account.go#L45
这里的 mp.Client
那么你认为这个类型的名称叫什么好?
APIProxy
ApiProxy
ApiAdapter
Proxy
Delegate
Requester
Client
还是有其他的,请留下你的答案
比较奇怪的是这个没有msgtype的属性?然后文档样式也不对,估计是文档写漏了这个字段;
util.WXVersion()
不是有效的微信浏览器 user-agent, Mozilla/5.0 (Linux; Android 4.4.4; Che1-CL10 Build/Che1-CL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043128 Safari/537.36 MicroMessenger/6.5.7.1041 NetType/WIFI Language/zh_CN
看不到?v1支持的消息类型不完整
就是 https://github.com/chanxuehong/wechat.v2/blob/master/mch/pay/orderquery.go 里面的 OrderQuery2() ,没有校验微信接口返回值的sign字段,但感觉这是有必要的
wechat/mp/message/custom/msg.go
第30行
KfAccount string json:"kfaccount"
根据微信开发文档此处应为
KfAccount string json:"kf_account"
修改后微信客户端可正常显示客服头像及昵称
这个包不支持沙箱测试么,怎么修改api地址
我更新了 Client 的 access token 维护机制,现在有机会可以把 Client 的各个方法移到对应的包里去了,
比如菜单操作可以把方法移动到 menu 包里
最后整个 client 包可以去掉,大家觉得这样是不是更好???
llog:
2018-03-23 16:12:17 handler/weixin.go:67 /service/weixin/mp?code=071AdBVI1ZHOd509MKUI1jwjVI1AdBVV&state=385a5e02f501f8190cb5de69fe0d4d0c
2018-03-23 16:12:17 handler/weixin.go:67 /service/weixin/mp?code=001tbrPg2GWJYH07NrNg2oxqPg2tbrPQ&state=385a5e02f501f8190cb5de69fe0d4d0c
两次回调的code不同,但state相同.
解决方法
生成url时添加connect_redirect=1
:
func AuthCodeURL(appId, redirectURI, scope, state string) string {
return "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + url.QueryEscape(appId) +
"&redirect_uri=" + url.QueryEscape(redirectURI) +
"&response_type=code&scope=" + url.QueryEscape(scope) +
"&state=" + url.QueryEscape(state) +
"&connect_redirect=1#wechat_redirect"
}
package main
import (
"log"
"net/http"
"github.com/chanxuehong/wechat.v2/mp/core"
"github.com/chanxuehong/wechat.v2/mp/menu"
"github.com/chanxuehong/wechat.v2/mp/message/callback/request"
"github.com/chanxuehong/wechat.v2/mp/message/callback/response"
"fmt"
)
const (
//看看的内容
wxAppId = " "
wxAppSecret = " "
wxOriId = " "
wxToken = " "
wxEncodedAESKey = " "
)
var (
// 下面两个变量不一定非要作为全局变量, 根据自己的场景来选择.
msgHandler core.Handler
msgServer *core.Server
accessTokenServer core.AccessTokenServer = core.NewDefaultAccessTokenServer(wxAppId, wxAppSecret, nil)
wechatClient *core.Client = core.NewClient(accessTokenServer, nil)
)
func init() {
//不知道为什么必须放到初始化当中,在 main 上不行
//创建菜单
var subButtons = make([]menu.Button, 2)
subButtons[0].SetAsViewButton("搜索", "http://www.soso.com/")
subButtons[1].SetAsClickButton("赞一下我们", "V1001_GOOD")
var mn menu.Menu
mn.Buttons = make([]menu.Button, 3)
mn.Buttons[0].SetAsScanCodePushButton("测试汤中", "rselfmenu_0_0")
mn.Buttons[1].SetAsViewButton("视频", "http://v.qq.com/")
mn.Buttons[2].SetAsSubMenuButton("子菜单", subButtons)
if err := menu.Create(wechatClient, &mn); err != nil {
fmt.Println(err)
return
}
fmt.Println("ok")
mux := core.NewServeMux()
mux.DefaultMsgHandleFunc(defaultMsgHandler)
mux.DefaultEventHandleFunc(defaultEventHandler)
mux.MsgHandleFunc(request.MsgTypeText, textMsgHandler)
mux.EventHandleFunc(menu.EventTypeClick, menuClickEventHandler)
msgHandler = mux
msgServer = core.NewServer(wxOriId, wxAppId, wxToken, wxEncodedAESKey, msgHandler, nil)
http.HandleFunc("/weixin", wxCallbackHandler)
}
func textMsgHandler(ctx *core.Context) {
fmt.Println("收到文本消息:\n%s\n", string(ctx.MsgPlaintext))
msg := request.GetText(ctx.MixedMsg)
resp := response.NewText(msg.FromUserName, msg.ToUserName, msg.CreateTime, msg.Content)
ctx.RawResponse(resp) // 明文回复
//ctx.AESResponse(resp, 0, "", nil) // aes密文回复
fmt.Println("老子拿到了你的消息",msg.Content)
}
func defaultMsgHandler(ctx *core.Context) {
fmt.Println("收到消息:\n%s\n", string(ctx.MsgPlaintext))
ctx.NoneResponse()
}
func menuClickEventHandler(ctx *core.Context) {
fmt.Println("收到菜单 click 事件:\n%s\n", string(ctx.MsgPlaintext))
event := menu.GetClickEvent(ctx.MixedMsg)
resp := response.NewText(event.FromUserName, event.ToUserName, event.CreateTime, "收到 click 类型的事件")
ctx.RawResponse(resp) // 明文回复
//ctx.AESResponse(resp, 0, "", nil) // aes密文回复
}
func defaultEventHandler(ctx *core.Context) {
fmt.Println("收到事件:\n%s\n", string(ctx.MsgPlaintext))
ctx.NoneResponse()
}
// wxCallbackHandler 是处理回调请求的 http handler.
// 1. 不同的 web 框架有不同的实现
// 2. 一般一个 handler 处理一个公众号的回调请求(当然也可以处理多个, 这里我只处理一个)
func wxCallbackHandler(w http.ResponseWriter, r *http.Request) {
fmt.Printf("老子信了你的邪")
msgServer.ServeHTTP(w, r, nil)
fmt.Printf("老子信了你的邪2")
}
func main() {
log.Println(http.ListenAndServe(":3080", nil))
}
产先生,目前 v2 是最新的版本?但是当我们在go get 的时候,发现会出现依赖的错误,是否可以支持gopkg.in 的版本控制方法?
额,我正在折腾,做一个第三方登录的demo出来。
i have checked with wechat's tool , same as my sign info , but it still return "签名错误" when i use your lib to queryOrder , is there any solutions?
群发接口的返回结果,由于msg_id并不是群发统计的事件ID,所以微信新增了一个msg_data_id的字段:
貌似少了一个user_source
{list:[
{
"ref_date": "2015-01-13",
"user_source": 4,
"int_page_read_user": 88,
"int_page_read_count": 294,
"ori_page_read_user": 0,
"ori_page_read_count": 0,
"share_user": 0,
"share_count": 0,
"add_to_fav_user": 0,
"add_to_fav_count": 0
},...
]}
Documentation says there is support for 企业微信 but it doesnt seem to be present in wechat.v2. My ability to read chinese is pretty limited however, so perhaps I am missing something.
现在在搞支付,要用到pay相关部份,现在的代码不太方便测试,发请求都用了具体类型core.Client,而且url也写死在代码里, 没办法mock一个,如果是接口就好,总不能测试就去请求微信那边吧
serve_http.go中引用了一个非wechat项目中的包:
"github.com/chanxuehong/util/security"
请教一个问题,大神关于access_token是如何管理的,每次向微信发出请求还是本地缓存还是其他分布式的做法?
每个AccessTokenServer都只能适用于一个Corp,实际场景是一个微信应用需要服务很多企业,不太明白为什么作者在注释中反复强调整个系统只能存在一个 DefaultAccessTokenServer 实例?
type DefaultAccessTokenServer struct {
corpId string
corpSecret string
httpClient *http.Client
resetTickerChan chan time.Duration // 用于重置 tokenDaemon 里的 ticker
tokenGet struct {
sync.Mutex
LastTokenInfo accessTokenInfo // 最后一次成功从微信服务器获取的 access_token 信息
LastTimestamp int64 // 最后一次成功从微信服务器获取 access_token 的时间戳
}
tokenCache struct {
sync.RWMutex
Token string
}
}
参考微信素材管理功能的文档:http://mp.weixin.qq.com/wiki/5/963fc70b80dc75483a271298a76a8d59.html
当前代码中这一部分在文档中已经被移除,还没有测试老的接口是否可以使用,如果不可以使用了,老的上传news的代码需要移除了:https://github.com/chanxuehong/wechat/blob/master/mp/media/media.go#L26
新的逻辑中只有多媒体素材作为临时素材上传的描述;
可以保留老的代码,但是需要说明一下使用的时候需要注意;
好几个项目使用了持续构建
用go get -v -x
命令安装依赖,现在报错如下
git clone https://github.com/chanxuehong/wechat /go/src/github.com/chanxuehong/wechat
cd /go/src/github.com/chanxuehong/wechat
git show-ref
cd /go/src/github.com/chanxuehong/wechat
git checkout master
# cd /go/src/github.com/chanxuehong/wechat; git checkout master
error: pathspec 'master' did not match any file(s) known to git.
package github.com/chanxuehong/wechat/mp: exit status 1
github.com/gorilla/websocket (download)
security.SecureCompareString这个函数不见了
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.