支付工具
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.
Go to file
杨赟 ff1764098b
修改位置支付配置
3 years ago
.gitignore init 3 years ago
README.md init 3 years ago
alipay.go init 3 years ago
go.mod init 3 years ago
go.sum init 3 years ago
wxpay.go 修改位置支付配置 3 years ago

README.md

支付

微信支付

package main

import (
	"context"
	"git.oa00.com/go/pay"
	"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.WxpayConfig{
		MchID:                      "mchID",                      // 支付商户号
		MchCertificateSerialNumber: "mchCertificateSerialNumber", // 证书序列号
		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
}

支付宝支付

package main

import (
    "git.oa00.com/go/pay"
	"github.com/smartwalle/alipay/v3"
	"log"
	"time"
)

func main() {
    // 初始化配置
	if err := pay.InitAlipay(pay.AlipayConfig{
		AppId:        "appId",// appId
		PrivateKey:   "privateKey",// 商户私钥
		AliPublicKey: "aliPublicKey",// 支付宝公钥
		IsProduction: isProduction,// 是否线上环境
	}); err != nil {
		log.Panicln("支付宝支付错误:", err)
	}

	// app支付 
	param := alipay.TradeAppPay{}
	param.OutTradeNo = "payNo"
	param.TotalAmount = "0.01"
	param.Subject = "subject"
	param.TimeExpire = time.Now().Add(time.Minute * time.Duration(15)).Format("2006-01-02 15:04:05")
	param.NotifyURL = "notifyURL"
	result, err := pay.Alipay.TradeAppPay(param)
	log.Println(result, err)
	
	// 详细使用文档见 https://github.com/smartwalle/alipay
}