74 Star 423 Fork 138

ShirDon-廖显东 / go支付合集

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pay.go 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
ShirDon-廖显东 提交于 2019-08-21 21:54 . 修正文档
package pays_with_go
import (
"errors"
"gitee.com/shirdonl/pays_with_go/client"
"gitee.com/shirdonl/pays_with_go/common"
"gitee.com/shirdonl/pays_with_go/constant"
"strconv"
)
//执行请求
func Pay(charge *common.Charge) (string, error) {
err := checkCharge(charge)
if err != nil {
//log.Error(err, charge)
return "", err
}
ct := getPayClient(charge.PayMethod)
re, err := ct.Pay(charge)
if err != nil {
//log.Error("支付失败:", err, charge)
return "", err
}
return re, err
}
//检验
func checkCharge(charge *common.Charge) error {
var id uint64
var err error
if charge.UserID == "" {
id = 0
} else {
id, err = strconv.ParseUint(charge.UserID, 10, -1)
if err != nil {
return err
}
}
if id < 0 {
return errors.New("userID less than 0")
}
if charge.PayMethod < 0 {
return errors.New("payMethod less than 0")
}
if charge.MoneyFee < 0 {
return errors.New("totalFee less than 0")
}
if charge.CallbackURL == "" {
return errors.New("callbackURL is NULL")
}
return nil
}
// getPayClient 得到需要支付的客户端
func getPayClient(payMethod int64) common.PayClient {
//如果使用余额支付
switch payMethod {
case constant.ALI_WEB:
return client.DefaultAliWebClient()
case constant.ALI_APP:
return client.DefaultAliAppClient()
case constant.WECHAT:
return client.DefaultWechatAppClient()
}
return nil
}
Go
1
https://gitee.com/shirdonl/pays_with_go.git
git@gitee.com:shirdonl/pays_with_go.git
shirdonl
pays_with_go
go支付合集
master

搜索帮助