alipay

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2020 License: MIT Imports: 10 Imported by: 0

README

alipay

CircleCI

支付宝付款sdk,目前只实现了普通公钥模式的部分接口

https://docs.open.alipay.com/194/105072

API

  1. TradePreCreate 预下单接口 - 已线上测试通过
  2. TradeQuery 查询订单接口 - 已线上测试通过
  3. CheckSign 签名验证接口 - 已线上测试通过
  4. TradeCancel 交易撤销接口 - 线上未测试
  5. TradeRefund 交易退款 - 未完成
  6. TradePagePay 电脑网站支付下单接口 - 已线上测试
  7. TradeWapPay 手机网站支付下单接口 - 已线上测试

6 7 返回一个奇怪的网址 只要把它嵌入网站的 iframe 标签就会自动跳转到支付宝收银台

Demo

使用案例见 example 文件夹

Test

to do

Documentation

Overview

这里是支付宝常量接口定义

Index

Constants

View Source
const AlipayTradeCancelMethodName = "alipay.trade.cancel"

统一收单线下撤销 接口名称

View Source
const AlipayTradeEndpointURL = "https://openapi.alipay.com/gateway.do"

统一收单线下请求地址

View Source
const AlipayTradePagePay = "alipay.trade.page.pay"

https://opendocs.alipay.com/pre-open/270/105900 2020-03-07 新增电脑网站支付接口 统一收单下单并支付页面接口

View Source
const AlipayTradePrecreateMethodName = "alipay.trade.precreate"

统一收单线下交易预创 接口名称

View Source
const AlipayTradeQueryMethodName = "alipay.trade.query"

统一收单线下交易查询 接口名称

View Source
const AlipayTradeRefundMethodName = "alipay.trade.refund"

统一收单同步退款 接口名称

View Source
const AlipayTradeWapPay = "alipay.trade.wap.pay"

统一收到wap支付接口

View Source
const DefaultCharset = "utf-8"

编码

View Source
const DefaultFormat = "JSON"

格式

View Source
const DefaultTimeFormat = "2006-01-02 15:04:05"

时间戳格式

View Source
const DefaultVersion = "1.0"

版本

Variables

This section is empty.

Functions

func SignRawStrConvert

func SignRawStrConvert(rawStr string) (str, sign string)

原始请求字符转换成签名字符串

Types

type BizContentRequestParams

type BizContentRequestParams struct {
	OutTradeNo   string `json:"out_trade_no,omitempty"`  // 商户订单ID
	TotalAmount  string `json:"total_amount,omitempty"`  // 总金额
	Subject      string `json:"subject,omitempty"`       // 主题
	RefundAmount string `json:"refund_amount,omitempty"` // 退款请求金额
	ProductCode  string `json:"product_code,omitempty"`  // 销售产品码 - 网站支付默认 FAST_INSTANT_TRADE_PAY
	QuitURL      string `json:"quit_url,omitempty"`      // 用户中途退出返回商户网站地址
}

商家请求参数

type Client

type Client struct {
	AppID           string         // 应用id
	NotifyURL       string         // 回调接口
	SignType        string         // 签名类型
	EndpointURL     string         // 创建交易地址 必须要有
	AliPayPublicKey *rsa.PublicKey // 支付宝公钥
	// 普通公钥签名可用
	AppPrivateKey *rsa.PrivateKey // 应用私钥
	// 以下公钥证书可以
	AppPublicKeyCert    string // app公钥证书
	AliPayPublicKeyCert string // 支付宝公钥证书
	AliPayRootCert      string // 支付宝根证书
	ReturnURL           string // wap 支付成功返回地址
}

func NewClient added in v0.0.3

func NewClient(c Client) *Client

NewClient 新实例化

func (*Client) CheckSign

func (c *Client) CheckSign(signReqStr string) bool

检查签名

func (*Client) DoRequest

func (c *Client) DoRequest(method string, p BizContentRequestParams, fromBrowser bool) ([]byte, error)

通用请求接口

func (*Client) SetReturnURL added in v0.0.3

func (c *Client) SetReturnURL(str string)

wap 支付设置成功支付回跳地址

func (*Client) TradeCancel

撤销订单接口

func (*Client) TradePagePay added in v0.0.2

func (c *Client) TradePagePay(p BizContentRequestParams, ReturnUrl string) (string, error)

网站支付下单接口

func (*Client) TradePreCreate

预下单接口

func (*Client) TradeQuery

查询订单接口

func (*Client) TradeRefund

交易退款

func (*Client) TradeWapPay added in v0.0.3

func (c *Client) TradeWapPay(p BizContentRequestParams, ReturnUrl string) (string, error)

wap下单接口

type Params

请求参数

func (*Params) ToMap

func (p *Params) ToMap() map[string]string

转换成 map[string]string

type PublicRequestParams

type PublicRequestParams struct {
	AppID        string `url:"app_id" json:"app_id"`                                     //必填
	Method       string `url:"method" json:"method"`                                     // 必填
	Format       string `url:"format,omitempty" json:"format,omitempty"`                 //格式化
	Charset      string `url:"charset" json:"charset"`                                   // 字符编码
	SignType     string `url:"sign_type" json:"sign_type"`                               // 签名类型
	Sign         string `url:"sign" json:"sign"`                                         // 签名
	Timestamp    string `url:"timestamp" json:"timestamp"`                               // 时间格式
	Version      string `url:"version" json:"version"`                                   //  接口版本
	NotifyURL    string `url:"notify_url,omitempty" json:"notify_url,omitempty"`         // 回调地址
	AppAuthToken string `url:"app_auth_token,omitempty" json:"app_auth_token,omitempty"` // 应用授权
	BizContent   string `url:"biz_content" json:"biz_content"`                           // 特定请求参数
	ReturnURL    string `json:"return_url,omitempty" url:"return_url,omitempty"`         // 移动支付成功返的地址
}

公共请求参数

type PublicResponse

type PublicResponse struct {
	Code    string `json:"code"`     // 网关返回代码
	Msg     string `json:"msg"`      // 网关错误信息
	SubCode string `json:"sub_code"` // 业务返回代码
	SumMsg  string `json:"sum_msg"`  // 业务返回描述
}

------------****响应参数********** ----------------------------------------

type TradeCancelResponse

type TradeCancelResponse struct {
	AlipayTradeCancelResponse struct {
		PublicResponse
		OutTradeNo         string `json:"out_trade_no,omitempty"`         // 商家订单号
		TradeNo            string `json:"trade_no,omitempty"`             // 支付宝订单号
		RetryFlag          string `json:"retry_flag,omitempty"`           // 是否需要重试
		Action             string `json:"action,omitempty"`               // close:交易未支付,触发关闭交易动作,无退款;refund:交易已支付,�触发交易退款动作;未返回:未查询到交易,或接口调用失败;
		GmtRefundPay       string `json:"gmt_refund_pay,omitempty"`       // 当撤销产生了退款时,返回退款时间;
		RefundSettlementID string `json:"refund_settlement_id,omitempty"` // 是否需要重试

	} `json:"alipay_trade_cancel_response"`
}

交易撤销结果

type TradePreCreateResponse

type TradePreCreateResponse struct {
	AlipayTradePrecreateResponse struct {
		PublicResponse
		OutTradeNo string `json:"out_trade_no,omitempty"` // 商家订单号
		QrCode     string `json:"qr_code,omitempty"`      // 商家订单号
	} `json:"alipay_trade_precreate_response"`
}

type TradeQueryResponse

type TradeQueryResponse struct {
	AlipayTradeQueryResponse struct {
		PublicResponse
		TradeStatus string `json:"trade_status"`  // 交易状态
		TotalAmount string `json:"total_amount"`  // 总金额
		BuyerUserID string `json:"buyer_user_id"` // 买家金额
	} `json:"alipay_trade_query_response"`
}

交易结果查询

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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