Skip to content

taydy/pay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

微信、支付宝支付 GoLand 版

支付方式 是否支持
支付宝 web
支付宝 wap
支付宝 app
微信 web
微信 h5
微信 app
微信 小程序
转账方式 是否支持
支付宝
微信

示例

微信 App 支付

// 微信支付均可参考以下格式来调用
var WXPayClient = &client.WeChatAppClient{
	WeChatClient: &client.WeChatClient{
		AppID:     "",
		MchID:     "",
		SecretKey: "",
	},
}

// 注意 H5 支付需要传客户端的 ip 地址,微信会做校验
func WXAppPay(orderId string, amount int, description string, notifyUrl string, returnUrl string, ip string) (map[string]interface{}, error) {
	now := time.Now()

	charge := &_struct.Charge{}
	charge.OutTradeNo = orderId
	charge.TotalFee = amount
	charge.Body = description
	charge.NotifyUrl = notifyUrl
	charge.ReturnUrl = returnUrl
	charge.SpbillCreateIp = ip

	charge.TimeStart = util.FormatTime(now)
	charge.TimeExpire = util.FormatTime(now.Add(constant.TIMEOUT_PAY))

	result, err := WXPayClient.Pay(charge)
	if err != nil {
		return nil, err
	}
	return result, nil
}

支付宝 App 支付

var ALIPayClient = &client.AliAppPayClient{
	AliPayClient: &client.AliPayClient{
		AppID:      "",
		PrivateKey: nil,
		PublicKey:  nil,
	},
}

func AliAppPay(orderId string, amount int, description string, notifyUrl string, returnUrl string) (map[string]interface{}, error) {
	charge := &_struct.Charge{}
	charge.Body = description
	charge.OutTradeNo = orderId
	charge.TotalFee = amount
	charge.NotifyUrl = notifyUrl
	charge.ReturnUrl = returnUrl

	result, err := ALIPayClient.Pay(charge)
	if err != nil {
		return nil, err
	}
	return result, nil
}

工具类

// 微信证书加载
func LoadWxTlsConfig(certKeyPath string, KeyPath string, caPath string) *tls.Config {}

// 支付宝证书加载
func LoadAliPrivateKey(path string) *rsa.PrivateKey {}
func LoadAliPublicKey(path string) *rsa.PublicKey {}

About

AliPay & WeChat SDK for Golang

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages