You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
197 lines
6.4 KiB
197 lines
6.4 KiB
|
1 year ago
|
package eanipay
|
||
|
|
|
||
|
|
import "strings"
|
||
|
|
|
||
|
|
const (
|
||
|
|
baseURL = "https://gateway.eanishop.com"
|
||
|
|
// baseURL = "https://gateway.eanishop.com"
|
||
|
|
payURL = "/pg/v2/payment/create"
|
||
|
|
queryPayURL = "/pg/v2/payment/query"
|
||
|
|
withdrawURL = "/pg/v2/payout/create"
|
||
|
|
queryWithdrawURL = "/pg/v2/payout/query"
|
||
|
|
appID = "c553240e3e3842ad98eb8ae23c3745b5"
|
||
|
|
appSecret = "8e77714f16d2487f9846cc6c3432ead5"
|
||
|
|
)
|
||
|
|
|
||
|
|
type PayReq struct {
|
||
|
|
MerchantTradeNo string `json:"merchantTradeNo"`
|
||
|
|
Amount string `json:"amount"`
|
||
|
|
Currency string `json:"currency"`
|
||
|
|
Description string `json:"description"`
|
||
|
|
Payer Payer `json:"payer"`
|
||
|
|
PayMethod struct {
|
||
|
|
Type string `json:"type"` // UPI
|
||
|
|
} `json:"payMethod"`
|
||
|
|
TradeEnv struct {
|
||
|
|
IP string `json:"ip"`
|
||
|
|
} `json:"tradeEnv"` // 如果具体环境信息比较复杂,可以直接使用json.RawMessage
|
||
|
|
MerchantAttach string `json:"merchantAttach,omitempty"` // omitempty表示如果字段为空,则在JSON中不显示
|
||
|
|
NotifyUrl string `json:"notifyUrl"`
|
||
|
|
ReturnUrl string `json:"returnUrl"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type Payer struct {
|
||
|
|
UserID string `json:"userId" validate:"required,max=64"`
|
||
|
|
Name string `json:"name" validate:"required,max=80"`
|
||
|
|
Email string `json:"email" validate:"required,email,max=80"`
|
||
|
|
Phone string `json:"phone" validate:"required,max=20"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type PayResp struct {
|
||
|
|
Code string `json:"code"`
|
||
|
|
ErrorMessage string `json:"errorMessage"`
|
||
|
|
Data PaymentData `json:"data"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type PaymentData struct {
|
||
|
|
PaymentNo string `json:"paymentNo"`
|
||
|
|
MerchantTradeNo string `json:"merchantTradeNo"`
|
||
|
|
Amount string `json:"amount"`
|
||
|
|
Currency string `json:"currency"`
|
||
|
|
Action Action `json:"action"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type Action struct {
|
||
|
|
PayMethodType string `json:"payMethodType"`
|
||
|
|
Type string `json:"type"`
|
||
|
|
URL string `json:"url"`
|
||
|
|
Method string `json:"method"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type PayCallbackReq struct {
|
||
|
|
Event string `json:"event"`
|
||
|
|
Code string `json:"code"`
|
||
|
|
ErrorMessage string `json:"errorMessage"`
|
||
|
|
Data struct {
|
||
|
|
PaymentNo string `json:"paymentNo"`
|
||
|
|
MerchantTradeNo string `json:"merchantTradeNo"`
|
||
|
|
Amount string `json:"amount"`
|
||
|
|
Currency string `json:"currency"`
|
||
|
|
RefundStatus string `json:"refundStatus"`
|
||
|
|
Status string `json:"status"` // PENDING 待⽀付 PROCESSING ⽀付中 PAID ⽀付成功 FAILURE ⽀付失败 CANCELLED 已取消
|
||
|
|
MerchantAttach string `json:"merchantAttach"`
|
||
|
|
CreatedTime string `json:"createdTime"`
|
||
|
|
PaidTime string `json:"paidTime"`
|
||
|
|
} `json:"data"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type QueryPayReq struct {
|
||
|
|
MerchantTradeNo string `json:"merchantTradeNo"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type QueryPayResp struct {
|
||
|
|
Code string `json:"code"`
|
||
|
|
ErrorMessage string `json:"errorMessage"`
|
||
|
|
Data struct {
|
||
|
|
PaymentNo string `json:"paymentNo"`
|
||
|
|
MerchantTradeNo string `json:"merchantTradeNo"`
|
||
|
|
Amount string `json:"amount"`
|
||
|
|
Currency string `json:"currency"`
|
||
|
|
RefundStatus string `json:"refundStatus"`
|
||
|
|
Status string `json:"status"` // PENDING 待⽀付 PROCESSING ⽀付中 PAID ⽀付成功 FAILURE ⽀付失败 CANCELLED 已取消
|
||
|
|
MerchantAttach string `json:"merchantAttach"`
|
||
|
|
CreatedTime string `json:"createdTime"`
|
||
|
|
PaidTime string `json:"paidTime"`
|
||
|
|
} `json:"data"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type WithdrawReq struct {
|
||
|
|
MerchantTradeNo string `json:"merchantTradeNo"`
|
||
|
|
Amount string `json:"amount"`
|
||
|
|
Currency string `json:"currency"`
|
||
|
|
Description string `json:"description"`
|
||
|
|
PayoutMethod struct {
|
||
|
|
Type string `json:"type"` // BANK_ACCOUNT
|
||
|
|
Mode string `json:"mode"` // IMPS
|
||
|
|
BankCode string `json:"bankCode"`
|
||
|
|
BankName string `json:"bankName"`
|
||
|
|
AccountNumber string `json:"accountNumber"`
|
||
|
|
PayeeName string `json:"payeeName"`
|
||
|
|
PayeePhone string `json:"payeePhone"`
|
||
|
|
PayeeEmail string `json:"payeeEmail"`
|
||
|
|
PayeeAddress string `json:"payeeAddress"`
|
||
|
|
// VPA string `json:"vpa"`
|
||
|
|
} `json:"payoutMethod"`
|
||
|
|
MerchantAttach string `json:"merchantAttach,omitempty"`
|
||
|
|
NotifyUrl string `json:"notifyUrl"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type WithdrawResp struct {
|
||
|
|
Code string `json:"code"` // OK
|
||
|
|
ErrorMessage string `json:"errorMessage"`
|
||
|
|
Data struct {
|
||
|
|
PayoutNo string `json:"payoutNo"`
|
||
|
|
MerchantTradeNo string `json:"merchantTradeNo"`
|
||
|
|
Amount string `json:"amount"`
|
||
|
|
Currency string `json:"currency"`
|
||
|
|
} `json:"data"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type WithdrawCallbackReq struct {
|
||
|
|
Event string `json:"event"`
|
||
|
|
Code string `json:"code"`
|
||
|
|
ErrorMessage string `json:"errorMessage"`
|
||
|
|
Data struct {
|
||
|
|
PayoutNo string `json:"payoutNo"`
|
||
|
|
MerchantTradeNo string `json:"merchantTradeNo"`
|
||
|
|
Amount string `json:"amount"`
|
||
|
|
Currency string `json:"currency"`
|
||
|
|
TotalFee string `json:"totalFee"`
|
||
|
|
Status string `json:"status"` // PENDING 待处理 PROCESSING 处理中 PAID 代付成功 FAILURE 代付失败 REVERSED 代付退票 CANCELLED 代付取消
|
||
|
|
MerchantAttach string `json:"merchantAttach"`
|
||
|
|
CreatedTime string `json:"createdTime"`
|
||
|
|
PaidTime string `json:"paidTime"`
|
||
|
|
} `json:"data"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type QueryWithdrawReq struct {
|
||
|
|
MerchantTradeNo string `json:"merchantTradeNo"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type QueryWithdrawResp struct {
|
||
|
|
Code string `json:"code"`
|
||
|
|
ErrorMessage string `json:"errorMessage"`
|
||
|
|
Data struct {
|
||
|
|
PayoutNo string `json:"payoutNo"`
|
||
|
|
MerchantTradeNo string `json:"merchantTradeNo"`
|
||
|
|
Amount string `json:"amount"`
|
||
|
|
Currency string `json:"currency"`
|
||
|
|
TotalFee string `json:"totalFee"`
|
||
|
|
Status string `json:"status"` // PENDING 待处理 PROCESSING 处理中 PAID 代付成功 FAILURE 代付失败 REVERSED 代付退票 CANCELLED 代付取消
|
||
|
|
MerchantAttach string `json:"merchantAttach"`
|
||
|
|
CreatedTime string `json:"createdTime"`
|
||
|
|
PaidTime string `json:"paidTime"`
|
||
|
|
} `json:"data"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type SignData struct {
|
||
|
|
AppId string
|
||
|
|
Sign string
|
||
|
|
Timestamp string
|
||
|
|
Nonce string
|
||
|
|
}
|
||
|
|
|
||
|
|
func parseData(input string) SignData {
|
||
|
|
input = strings.TrimPrefix(input, "V2_SHA256 ")
|
||
|
|
pairs := strings.Split(input, ",")
|
||
|
|
data := SignData{}
|
||
|
|
for _, pair := range pairs {
|
||
|
|
keyValue := strings.Split(pair, "=")
|
||
|
|
if len(keyValue) == 2 {
|
||
|
|
key := keyValue[0]
|
||
|
|
value := keyValue[1]
|
||
|
|
switch key {
|
||
|
|
case "appId":
|
||
|
|
data.AppId = value
|
||
|
|
case "sign":
|
||
|
|
data.Sign = value
|
||
|
|
case "timestamp":
|
||
|
|
data.Timestamp = value
|
||
|
|
case "nonce":
|
||
|
|
data.Nonce = value
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return data
|
||
|
|
}
|