wxpayGo 的微信支付商戶平臺 SDK
wxpay 是一個使用Go語言編寫的微信支付商戶平臺SDK。
舉個栗子
以查詢企業(yè)付款A(yù)PI為栗:
package main
import (
"log"
"github.com/go-with/wxpay"
)
const (
appId = "" // 微信公眾平臺應(yīng)用ID
mchId = "" // 微信支付商戶平臺商戶號
apiKey = "" // 微信支付商戶平臺API密鑰
// 微信支付商戶平臺證書路徑
certFile = "cert/apiclient_cert.pem"
keyFile = "cert/apiclient_key.pem"
rootcaFile = "cert/rootca.pem"
)
func main() {
c := wxpay.NewClient(appId, mchId, apiKey)
// 附著商戶證書
err := c.WithCert(certFile, keyFile, rootcaFile)
if err != nil {
log.Fatal(err)
}
params := make(wxpay.Params)
// 查詢企業(yè)付款接口請求參數(shù)
params.SetString("appid", c.AppId)
params.SetString("mch_id", c.MchId)
params.SetString("nonce_str", "5K8264ILTKCH16CQ2502SI8ZNMTM67VS") // 隨機字符串
params.SetString("partner_trade_no", "10000098201411111234567890") // 商戶訂單號
params.SetString("sign", c.Sign(params)) // 簽名
// 查詢企業(yè)付款接口請求URL
url := "https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo"
// 發(fā)送查詢企業(yè)付款請求
ret, err := c.Post(url, params, true)
if err != nil {
log.Fatal(err)
}
log.Print(ret)
}評論
圖片
表情
