安装
go get github.com/yaotian/gowechat
配置
参数
var config = wxcontext.Config{
//微信公众平台,商户平台,需要填写的信息
AppID: "your app id",
AppSecret: "your app secret",
Token: "your token",
EncodingAESKey: "your encoding aes key",
//以下是 mch商户平台需要的变量
SslCertFilePath string //证书公钥文件的路径
SslKeyFilePath string //证书私钥文件的路径
SslCertContent string //公钥证书的内容
SslKeyContent string //私钥证书的内容
MchID string //商户ID
MchAPIKey string //商户平台设置的api key
}
微信平台的操作接口
微信公众平台
wc := gowechat.NewWechat(config)
//微信公众平台
mp, err := wc.MpMgr()
if err != nil {
return
}
微信商户平台
wc := gowechat.NewWechat(config)
//微信商户平台
mch , err := wc.MchMgr()
if err != nil {
return
}
在框架中使用
beego中使用的例子
./examples/beego
gin中使用的例子
./examples/gin
net/http中使用的例子
./examples/http
微信公众平台
初始化
消息
模板消息
用户
网页授权
JSSDK
二维码
菜单
微信支付(商户平台)
初始化
var config = wxcontext.Config{
//微信公众平台,商户平台,需要填写的信息
AppID: "your app id",
AppSecret: "your app secret",
Token: "your token",
EncodingAESKey: "your encoding aes key",
//------以下是 mch商户平台需要的变量
//
//证书公钥,路径,内容要保证只要有一项设置
SslCertFilePath string //证书公钥文件的路径
SslCertContent string //公钥证书的内容
//私钥,路径,内容要保证只要有一项设置
SslKeyFilePath string //证书私钥文件的路径
SslKeyContent string //私钥证书的内容
MchID string //商户ID
MchAPIKey string //商户平台设置的api key
//------ End 商户平台设置
}
wc := gowechat.NewWechat(config)
//微信商户平台
mch , err := wc.MchMgr()
if err != nil {
return
}
订单
统一下单
查询订单
该接口提供所有微信支付订单的查询,商户可以通过该接口主动查询订单状态,完成下一步的业务逻辑。
需要调用查询接口的情况:
-
当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知;
-
调用支付接口后,返回系统错误或未知交易状态情况;
-
调用被扫支付API,返回USERPAYING的状态;
-
调用关单或撤销接口API之前,需确认支付状态;