You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
杨赟
b0ec11f072
|
3 years ago | |
---|---|---|
.gitignore | 3 years ago | |
README.md | 3 years ago | |
go.mod | 3 years ago | |
go.sum | 3 years ago | |
wxpay.go | 3 years ago |
README.md
支付
微信支付
package main
import (
"context"
"git.oa00.com/go/wxpay"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/app"
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi"
"log"
"time"
)
func main() {
// 初始化配置
if err := pay.InitWxpay(pay.Config{
MchID: "mchID", // 支付商户号
MchAPIv3Key: "mchAPIv3Key", // apiV3密钥
PrivateKey: "privateKey", // 私钥证书密钥
PrivateCert: "privateCert", // 私钥证书
}); err != nil {
log.Panicln("微信支付错误:", err)
}
// app支付
apiService := app.AppApiService{Client: pay.Wxpay.Client}
result, _, err := apiService.PrepayWithRequestPayment(context.Background(), app.PrepayRequest{
Appid: core.String("appid"),
Mchid: core.String("mchID"),
Description: core.String("subject"),
OutTradeNo: core.String("payNo"),
TimeExpire: core.Time(time.Now().Add(time.Minute * time.Duration(15))),
NotifyUrl: core.String("notifyURL"),
Amount: &app.Amount{
Total: core.Int64(int64(0.01 * 100)),
Currency: core.String("CNY"),
},
})
log.Println(result, err)
// 小程序/微信公众号支付
apiService := jsapi.JsapiApiService{Client: pay.Wxpay.Client}
result, _, err = apiService.PrepayWithRequestPayment(context.Background(), jsapi.PrepayRequest{
Appid: core.String("appid"),
Mchid: core.String("mchID"),
Description: core.String("subject"),
OutTradeNo: core.String("payNo"),
TimeExpire: core.Time(time.Now().Add(time.Minute * time.Duration(15))),
NotifyUrl: core.String("notifyURL"),
Amount: &jsapi.Amount{
Total: core.Int64(int64(0.01 * 100)),
Currency: core.String("CNY"),
},
Payer: &jsapi.Payer{
Openid: core.String("openId"),
},
})
log.Println(result, err)
// 详细使用文档见 https://github.com/wechatpay-apiv3/wechatpay-go
}