Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
forked fromobjcoding/wxpay

微信支付(WeChat Pay) SDK for Golang

License

NotificationsYou must be signed in to change notification settings

gogap/wxpay

 
 

Repository files navigation

Powered by zchLanguageLicense

wxpay 提供了以下的方法:

方法名说明
MicroPay刷卡支付
UnifiedOrder统一下单
OrderQuery查询订单
Reverse撤销订单
CloseOrder关闭订单
Refund申请退款
RefundQuery查询退款
DownloadBill下载对账单
Report交易保障
ShortUrl转换短链接
AuthCodeToOpenid授权码查询openid
  • 参数为Params类型,返回类型也是ParamsParams 是一个 map[string]string 类型。
  • 方法内部会将参数会转换成含有appidmch_idnonce_strsign_typesign的XML;
  • 默认使用MD5进行签名;
  • 通过HTTPS请求得到返回数据后会对其做必要的处理(例如验证签名,签名错误则抛出异常)。
  • 对于DownloadBill,无论是否成功都返回Map,且都含有return_codereturn_msg。若成功,其中return_codeSUCCESS,另外data对应对账单数据。

安装

$ go get github.com/objcoding/wxpay

go modules

// go.modrequire github.com/objcoding/wxpay v1.0.5

示例

// 创建支付账户account1 := wxpay.NewAccount("appid", "mchid", "apiKey", false)account2 := wxpay.NewAccount("appid", "mchid", "apiKey", false)// 新建微信支付客户端client := wxpay.NewClient(account1)// 设置证书account.SetCertData("证书地址")// 设置支付账户client.setAccount(account2)// 设置http请求超时时间client.SetHttpConnectTimeoutMs(2000)// 设置http读取信息流超时时间client.SetHttpReadTimeoutMs(1000)// 更改签名类型client.SetSignType(HMACSHA256)
// 统一下单params := make(wxpay.Params)params.SetString("body", "test").SetString("out_trade_no", "436577857").SetInt64("total_fee", 1).SetString("spbill_create_ip", "127.0.0.1").SetString("notify_url", "http://notify.objcoding.com/notify").SetString("trade_type", "APP")p, _ := client.UnifiedOrder(params)// 订单查询params := make(wxpay.Params)params.SetString("out_trade_no", "3568785")p, _ := client.OrderQuery(params)// 退款params := make(wxpay.Params)params.SetString("out_trade_no", "3568785").SetString("out_refund_no", "19374568").SetInt64("total_fee", 1).SetInt64("refund_fee", 1)p, _ := client.Refund(params)// 退款查询params := make(wxpay.Params)params.SetString("out_refund_no", "3568785")p, _ := client.RefundQuery(params)
// 签名signStr := client.Sign(params)// 校验签名b := client.ValidSign(params)
// xml解析params := wxpay.XmlToMap(xmlStr)// map封装xml请求参数b := wxpay.MapToXml(params)
// 支付或退款返回成功信息return wxpay.Notifies{}.OK()// 支付或退款返回失败信息return wxpay.Notifies{}.NotOK("支付失败或退款失败了")

objcoding

License

MIT license

About

微信支付(WeChat Pay) SDK for Golang

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go100.0%

[8]ページ先頭

©2009-2025 Movatter.jp