Skip to content

qbhy/goal-alipay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goal-aliyun

这是一个 goal 的支付宝 sdk,基于 smartwalle/alipay 封装,支持多应用

安装 - install

$ go get github.com/qbhy/goal-alipay

配置 - configuration

// config/alipay.go
package config

import (
	"github.com/goal-web/contracts"
	alipay "github.com/qbhy/goal-alipay"
)

func init() {
	configs["alipay"] = func(env contracts.Env) interface{} {
		return &alipay.Config{
			Default: env.StringOption("alipay.default", "default"),
			Apps: map[string]*alipay.AppConfig{
				"default": {
					AppId:        env.GetString("alipay.appid"),
					PrivateKey:   env.GetString("alipay.private_key"),
					IsProduction: !env.GetBool("alipay.debug"),
					//OptionFunctions: []alipay.OptionFunc{
					//	func(c *alipay2.Client) {
					//		// do something
					//	},
					//},
				},
			},
		}
	}
}

使用 - usage

注册服务

// main.go
import (
    "github.com/goal-web/application"
alipay "github.com/qbhy/goal-alipay"
)

func main()  {
    var app = application.Singleton()
    
    app.RegisterServices(
        // other service
        alipay.ServiceProvider{},
    )
	// ...
}

使用

// app/controllers/order/pay.go

import (
	"fmt"
    "github.com/goal-web/contracts"
    alipay "github.com/qbhy/goal-alipay"
    alipayWalle "github.com/smartwalle/alipay/v3"
)

// ... 

// 通过注入支付宝工厂,你可以通过工厂获取定义好的应用
func AppTrade(alipay alipay.Factory, request contracts.HttpRequest) {
    var client = alipay.Client("default")
}

// 你也可以直接注入 支付宝kehuduan  的实例,这种情况下会获取默认实例
func InjectInstanceExample(client *alipayWalle.Client) {
	// do something ...
}

// ...

相关链接

goal-web
qbhy/goal-alipay
smartwalle/alipay
qbhy0715@qq.com

About

支付宝sdk for goal

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages