Alipay - 支付宝 SDK for Golang

alipay

CI Go Reference License

支付宝 SDK for Go

使用指南

安装支付宝 SDK

go get -u github.com/go-wheels/alipay

初始化支付宝 SDK

alipayOptions := alipay.Options{
    Gateway:         alipay.GatewayProduction, // 支付宝网关
    AppID:           "", // 应用ID
    AppPrivateKey:   "", // 应用私钥
    AlipayPublicKey: "", // 支付宝公钥
}
alipayClient, _ := alipay.NewClient(alipayOptions)

支付 API

交易查询

tradeQueryRequest := alipay.TradeQueryRequest{
    OutTradeNo: "1586150366616",
}
var tradeQueryResponse alipay.TradeQueryResponse
alipayClient.Execute(tradeQueryRequest, &tradeQueryResponse)
log.Printf("%#v", tradeQueryResponse)

条码支付

tradePayRequest := alipay.TradePayRequest{
    NotifyURL:   "http://example.com/notify_url",
    OutTradeNo:  "1586150366616",
    Scene:       "bar_code",
    AuthCode:    "283189274716618278",
    Subject:     "fresh meat",
    TotalAmount: "0.01",
}
var tradePayResponse alipay.TradePayResponse
alipayClient.Execute(tradePayRequest, &tradePayResponse)
log.Printf("%#v", tradePayResponse)

扫码支付

tradePrecreateRequest := alipay.TradePrecreateRequest{
    NotifyURL:   "http://example.com/notify_url",
    OutTradeNo:  "1586150366616",
    TotalAmount: "0.01",
    Subject:     "fresh meat",
}
var tradePrecreateResponse alipay.TradePrecreateResponse
alipayClient.Execute(tradePrecreateRequest, &tradePrecreateResponse)
log.Printf("%#v", tradePrecreateResponse)

App 支付

tradeAppPayRequest := alipay.TradeAppPayRequest{
    ReturnURL:   "http://example.com/return_url",
    NotifyURL:   "http://example.com/notify_url",
    OutTradeNo:  "1586150366616",
    TotalAmount: "0.01",
    Subject:     "fresh meat",
}
query, _ := alipayClient.SDKExecute(tradeAppPayRequest)
log.Print(query)

手机网站支付

tradeWapPayRequest := alipay.TradeWapPayRequest{
    ReturnURL:   "http://example.com/return_url",
    NotifyURL:   "http://example.com/notify_url",
    Subject:     "fresh meat",
    OutTradeNo:  "1586150366616",
    TotalAmount: "0.01",
    QuitURL:     "http://example.com/quit_url",
    ProductCode: "QUICK_WAP_WAY",
}
url, _ := alipayClient.PageExecute(tradeWapPayRequest)
log.Print(url)

电脑网站支付

tradePagePayRequest := alipay.TradePagePayRequest{
    ReturnURL:   "http://example.com/return_url",
    NotifyURL:   "http://example.com/notify_url",
    OutTradeNo:  "1586150366616",
    ProductCode: "FAST_INSTANT_TRADE_PAY",
    TotalAmount: "0.01",
    Subject:     "fresh meat",
}
url, _ := alipayClient.PageExecute(tradePagePayRequest)
log.Print(url)

通知验签

http.HandleFunc("/notify_url", func(w http.ResponseWriter, r *http.Request) {
    err := alipayClient.VerifyNotification(r)
    if err != nil {
        // 验签失败
        return
    }
    // 验签成功
    w.Write([]byte("success"))
})
Similar Resources

Easy SSH servers in Golang

gliderlabs/ssh The Glider Labs SSH server package is dope. —@bradfitz, Go team member This Go package wraps the crypto/ssh package with a higher-level

Dec 28, 2022

Golang Super Simple Load Balance

SSLB (Super Simple Load Balancer) ver 0.1.0 It's a Super Simple Load Balancer, just a little project to achieve some kind of performance. Features Hig

Dec 18, 2022

golang tcp server

TCPServer Package tcp_server created to help build TCP servers faster. Install package go get -u github.com/firstrow/tcp_server Usage: NOTICE: OnNewMe

Dec 28, 2022

A LWM2M Client and Server implementation (For Go/Golang)

Betwixt - A LWM2M Client and Server in Go Betwixt is a Lightweight M2M implementation written in Go OMA Lightweight M2M is a protocol from the Open Mo

Dec 23, 2022

Simple hosts file management in Golang (deprecated).

Simple hosts file management in Golang (deprecated).

Goodhosts (deprecated) This library is now deprecated. See the goodhosts organisation for the current maintained version. Simple hosts file (/etc/host

Mar 17, 2022

Golang library for Radius

goradius Description goradius package implements basic Radius client capabilities, allowing Go code to authenticate against a Radius server. It is bas

May 16, 2022

Simple, fast and scalable golang rpc library for high load

gorpc Simple, fast and scalable golang RPC library for high load and microservices. Gorpc provides the following features useful for highly loaded pro

Dec 19, 2022

Decentralized VPN in golang

Decentralized VPN in golang

LCVPN - Light decentralized VPN in golang Originally this repo was just an answer on a question "how much time it'll take to write my own simple VPN i

Dec 28, 2022

Package for writing Nagios/Icinga/et cetera plugins in Go (golang)

nagiosplugin Package for writing Nagios/Icinga/et cetera plugins in Go (golang). Documentation See http://godoc.org/github.com/olorin/nagiosplugin. Us

Aug 30, 2022
Related tags
language server protocol sdk implement for go

LSP(language server protocol) defines for golang lsp types is from vscode-languageserver-node. Project is working in progress. Example func main() {

Dec 17, 2022
Build - The axelar-core app based on the Cosmos SDK is the main application of the axelar network

⚠️ ⚠️ ⚠️ THIS IS A WORK IN PROGRESS ⚠️ ⚠️ ⚠️ axelar-core The axelar-core app bas

Feb 15, 2022
Hprose 1.0 for Golang (Deprecated). Hprose 2.0 for Golang is here:

Hprose for Golang Introduction Installation Usage Http Server Http Client Synchronous Invoking Synchronous Exception Handling Asynchronous Invoking As

Dec 15, 2022
A Minecraft scanner written in Golang (first Golang project)

__ __/ \__ Gothyc A Minecraft port scanner written in Go. ?? / \__/ \__ \__/ \__/ \ Version 0.3.0 \__/ \__/ Author @toas

Nov 6, 2022
Fast IP to CIDR lookup in Golang
Fast IP to CIDR lookup in Golang

cidranger Fast IP to CIDR block(s) lookup using trie in Golang, inspired by IPv4 route lookup linux. Possible use cases include detecting if a IP addr

Dec 30, 2022
High performance async-io(proactor) networking for Golang。golangのための高性能非同期io(proactor)ネットワーキング
High performance async-io(proactor) networking for Golang。golangのための高性能非同期io(proactor)ネットワーキング

gaio Introduction 中文介绍 For a typical golang network program, you would first conn := lis.Accept() to get a connection and go func(net.Conn) to start a

Dec 29, 2022
Gmqtt is a flexible, high-performance MQTT broker library that fully implements the MQTT protocol V3.1.1 and V5 in golang

中文文档 Gmqtt News: MQTT V5 is now supported. But due to those new features in v5, there area lots of breaking changes. If you have any migration problem

Jan 5, 2023
An SNMP library written in GoLang.

gosnmp GoSNMP is an SNMP client library fully written in Go. It provides Get, GetNext, GetBulk, Walk, BulkWalk, Set and Traps. It supports IPv4 and IP

Jan 7, 2023
A Crypto-Secure, Production-Grade Reliable-UDP Library for golang with FEC
 A Crypto-Secure, Production-Grade Reliable-UDP Library for golang with FEC

Introduction kcp-go is a Production-Grade Reliable-UDP library for golang. This library intents to provide a smooth, resilient, ordered, error-checked

Dec 28, 2022
Simple mDNS client/server library in Golang

mdns Simple mDNS client/server library in Golang. mDNS or Multicast DNS can be used to discover services on the local network without the use of an au

Jan 4, 2023