epay

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 7 Imported by: 0

README

go-epay

Documentation

Index

Constants

View Source
const DefaultUrl = "https://payment.moe/"
View Source
const (
	PurchaseUrl = "/submit.php"
)
View Source
const StatusTradeSuccess = "TRADE_SUCCESS"

Variables

This section is empty.

Functions

func CreateUrlString

func CreateUrlString(keys []string, values []string) string

CreateUrlString 生成待签名字符串, ["a", "b", "c"], ["d", "e", "f"] => "a=d&b=e&c=f"

func GenerateParams

func GenerateParams(params map[string]string, key string) map[string]string

GenerateParams 生成加签参数

func MD5String

func MD5String(urlString string, key string) string

MD5String 生成 加盐(商户 key) MD5 字符串

func ParamsFilter

func ParamsFilter(params map[string]string) map[string]string

ParamsFilter 过滤参数,生成签名时需删除 “sign” 和 “sign_type” 参数

func ParamsSort

func ParamsSort(params map[string]string) ([]string, []string)

ParamsSort 对参数进行排序,返回排序后的 keys 和 values (go 中 map 为乱序)

Types

type Client

type Client struct {
	Config  *Config
	BaseUrl *url.URL
}

func NewClient

func NewClient(config *Config) *Client

NewClient 创建一个新的易支付客户端

func NewClientWithUrl

func NewClientWithUrl(config *Config, baseUrl string) (*Client, error)

NewClientWithUrl 创建一个新的易支付客户端

func (*Client) Purchase

func (c *Client) Purchase(args *PurchaseArgs) (string, map[string]string, error)

Purchase 生成支付链接和参数

func (*Client) Verify

func (c *Client) Verify(params map[string]string) (*VerifyRes, error)

type Config

type Config struct {
	PartnerID string
	Key       string
}

type DeviceType

type DeviceType string
var (
	PC     DeviceType = "pc"     // PC PC端
	MOBILE DeviceType = "mobile" // MOBILE 移动端
)

type PurchaseArgs

type PurchaseArgs struct {
	// 支付类型
	Type PurchaseType
	// 商家订单号
	ServiceTradeNo string
	// 商品名称
	Name string
	// 金额
	Money string
	// 设备类型
	Device    DeviceType
	NotifyUrl *url.URL
	ReturnUrl *url.URL
}

type PurchaseType

type PurchaseType string
var (
	Alipay    PurchaseType = "alipay" // Alipay 支付宝
	WechatPay PurchaseType = "wxpay"  // WechatPay 微信
)

type Service

type Service interface {
	// Purchase 生成支付链接和参数
	Purchase(args *PurchaseArgs) (string, map[string]string, error)
	// Verify 验证回调参数是否符合签名
	Verify(params map[string]string) (*VerifyRes, error)
}

Service 易支付API

type VerifyRes

type VerifyRes struct {
	// 支付类型
	Type PurchaseType
	// 易支付订单号
	TradeNo string `mapstructure:"trade_no"`
	// 商家订单号
	ServiceTradeNo string `mapstructure:"out_trade_no"`
	// 商品名称
	Name string
	// 金额
	Money string
	// 订单支付状态
	TradeStatus string `mapstructure:"trade_status"`
	// 签名检验
	VerifyStatus bool `mapstructure:"-"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL