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.
203 lines
8.5 KiB
203 lines
8.5 KiB
|
2 months ago
|
package mlpay2
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"server/modules/pay/values"
|
||
|
|
"server/util"
|
||
|
|
"sort"
|
||
|
|
"strings"
|
||
|
|
|
||
|
|
"github.com/liangdas/mqant/log"
|
||
|
|
)
|
||
|
|
|
||
|
|
const (
|
||
|
|
baseUrl = "https://api.mlpayvip.top"
|
||
|
|
payURL = "/pay/order"
|
||
|
|
payCallbackURL = "/mlpay/pay/callback"
|
||
|
|
queryPayURL = "/pay/queryOrder"
|
||
|
|
withdrawURL = "/pay/withdraw"
|
||
|
|
withdrawCallbackURL = "/mlpay/withdraw/callback"
|
||
|
|
queryWithdrawURL = "/pay/queryWithdraw"
|
||
|
|
PartnerId = 23144
|
||
|
|
ApplicationId = 568
|
||
|
|
key = "A328070444024823966A962DB0E6CCDF"
|
||
|
|
withdrawKey = "72E83B56EFB9460F8146E2B69FDAED5E"
|
||
|
|
)
|
||
|
|
|
||
|
|
type PayReq struct {
|
||
|
|
PartnerID int64 `json:"partnerId"` // 支付中心分配的商户号
|
||
|
|
ApplicationID int64 `json:"applicationId"` // 商户应用ID
|
||
|
|
PayWay int `json:"payWay"` // 支付方式ID,固定值2
|
||
|
|
PartnerOrderNo string `json:"partnerOrderNo"` // 商户生成的代收号
|
||
|
|
Amount int64 `json:"amount"` // 支付金额,单位分
|
||
|
|
Currency string `json:"currency"` // 货币代码(如 INR、BRL 等)
|
||
|
|
Name string `json:"name"` // 用户姓名
|
||
|
|
GameID string `json:"gameId"` // 用户游戏ID
|
||
|
|
ClientIP string `json:"clientIp"` // 客户端IP地址,支持IPv6
|
||
|
|
NotifyURL string `json:"notifyUrl"` // 支付结果异步回调URL
|
||
|
|
Subject string `json:"subject"` // 商品主题
|
||
|
|
Body string `json:"body"` // 商品描述信息
|
||
|
|
CallbackURL string `json:"callbackUrl"` // 支付完成后跳转的URL,可选
|
||
|
|
Extra string `json:"extra"` // 特殊参数(JSON格式)
|
||
|
|
Version string `json:"version"` // 接口版本号,固定:1.0
|
||
|
|
IdentityNo string `json:"identityNo"` // 巴西代收必须填写收款人税号,可选
|
||
|
|
BankCode string `json:"bankCode"` // 韩国、日本必传,可选
|
||
|
|
Sign string `json:"sign"` // 签名值
|
||
|
|
}
|
||
|
|
|
||
|
|
type UserData struct {
|
||
|
|
UserName string `json:"userName"`
|
||
|
|
UserEmail string `json:"userEmail"`
|
||
|
|
UserPhone string `json:"userPhone"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type PayResp struct {
|
||
|
|
Code string `json:"code"`
|
||
|
|
Msg string `json:"message"`
|
||
|
|
Data string `json:"data"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type PayData struct {
|
||
|
|
OrderNo string `json:"orderNo"` // 系统订单号
|
||
|
|
PayURL string `json:"payUrl"` // 支付链接
|
||
|
|
QRCode string `json:"qrCode"` // 巴西支付二维码数据
|
||
|
|
}
|
||
|
|
|
||
|
|
type PayCallbackReq struct {
|
||
|
|
Status int `json:"status"` // 状态(0:失败;1:成功)
|
||
|
|
ApplicationID int64 `json:"applicationId"` // 商户应用ID
|
||
|
|
PayWay int `json:"payWay"` // 支付方式ID(1:PAYPAL; 2:PAYTM)
|
||
|
|
PartnerOrderNo string `json:"partnerOrderNo"` // 商户生成的代收号
|
||
|
|
OrderNo string `json:"orderNo"` // 平台生成的代收号
|
||
|
|
ChannelOrderNo string `json:"channelOrderNo"` // 上游生成的代收号(可选)
|
||
|
|
Amount int64 `json:"amount"` // 实际支付金额,单位分
|
||
|
|
Sign string `json:"sign"` // 签名值,转为大写
|
||
|
|
}
|
||
|
|
|
||
|
|
type QueryPayReq struct {
|
||
|
|
PartnerID int64 `json:"partnerId"` // 支付中心分配的商户号
|
||
|
|
ApplicationID string `json:"applicationId"` // 商户应用ID
|
||
|
|
PartnerOrderNo string `json:"partnerOrderNo"` // 商户生成的代收号
|
||
|
|
Sign string `json:"sign"` // 签名值,详见签名算法
|
||
|
|
Version string `json:"version"` // 接口版本号,固定:1.0
|
||
|
|
}
|
||
|
|
|
||
|
|
type QueryPayResp struct {
|
||
|
|
Code string `json:"code"` // 响应状态码:0000-处理成功,其他-处理有误
|
||
|
|
Message string `json:"message"` // 具体错误原因,例如:签名失败、参数格式校验错误
|
||
|
|
Data interface{} `json:"data"` // 返回参数为代付结果,返回同步代付结果
|
||
|
|
}
|
||
|
|
|
||
|
|
type QueryPayData struct {
|
||
|
|
PayPartnerID int64 `json:"payPartnerId"` // 支付中心分配的商户号
|
||
|
|
PayApplicationID int64 `json:"payApplicationId"` // 商户应用ID
|
||
|
|
OrderNo string `json:"orderNo"` // 平台生成的代收号
|
||
|
|
PartnerOrderNo string `json:"partnerOrderNo"` // 商户生成的代收号
|
||
|
|
Amount int64 `json:"amount"` // 支付金额,单位分
|
||
|
|
Status int `json:"status"` // 状态(0:创建订单;1:代收中;2:代收成功;3:代收失败)
|
||
|
|
SuccessTime string `json:"successTime"` // 成功时间
|
||
|
|
CreateTime string `json:"createTime"` // 创建时间
|
||
|
|
}
|
||
|
|
|
||
|
|
type WithdrawReq struct {
|
||
|
|
PartnerID string `json:"partnerId"` // 支付中心分配的商户号
|
||
|
|
PartnerWithdrawNo string `json:"partnerWithdrawNo"` // 商户生成的代付号,订单号唯一
|
||
|
|
Amount int64 `json:"amount"` // 支付金额,单位分,例如100,传值10000
|
||
|
|
Currency string `json:"currency"` // 货币代码
|
||
|
|
GameID string `json:"gameId"` // 用户游戏ID
|
||
|
|
NotifyURL string `json:"notifyUrl"` // 支付结果异步回调URL
|
||
|
|
ReceiptMode int `json:"receiptMode"` // 收款方式
|
||
|
|
AccountNumber string `json:"accountNumber"` // 收款账户
|
||
|
|
AccountName string `json:"accountName"` // 收款姓名
|
||
|
|
AccountPhone string `json:"accountPhone"` // 收款电话
|
||
|
|
AccountEmail string `json:"accountEmail"` // 收款邮箱
|
||
|
|
AccountExtra1 string `json:"accountExtra1"` // 收款特殊参数1 (可选)
|
||
|
|
AccountExtra2 string `json:"accountExtra2"` // 收款特殊参数2 (可选)
|
||
|
|
IdentityNo string `json:"identityNo"` // 收款人税号 (可选,巴西代付需填)
|
||
|
|
CardID string `json:"cardId"` // 身份证号 (可选)
|
||
|
|
Version string `json:"version"` // 接口版本号,固定:1.0
|
||
|
|
Sign string `json:"sign"` // 签名值
|
||
|
|
}
|
||
|
|
|
||
|
|
type WithdrawResp struct {
|
||
|
|
Code string `json:"code"`
|
||
|
|
Msg string `json:"message"`
|
||
|
|
Data string `json:"data"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// type WithdrawData struct {
|
||
|
|
// Amount string `json:"amount"`
|
||
|
|
// MchOrder string `json:"mch_order"`
|
||
|
|
// OrderNo string `json:"order_no"` // 平台订单号
|
||
|
|
// Timestamp int64 `json:"timestamp"` // 时间戳
|
||
|
|
// }
|
||
|
|
|
||
|
|
type WithdrawCallbackReq struct {
|
||
|
|
Status int `json:"status"` // 状态(0:失败;1:成功)
|
||
|
|
ErrorMsg string `json:"errorMsg"` // 上游错误信息,URLENCODE编码后验签,非必填
|
||
|
|
PartnerWithdrawNo string `json:"partnerWithdrawNo"` // 商户生成的代付号
|
||
|
|
WithdrawNo string `json:"withdrawNo"` // 平台生成的代付号
|
||
|
|
ChannelWithdrawNo string `json:"channelWithdrawNo"` // 上游生成的代付号,非必填
|
||
|
|
Amount string `json:"amount"` // 支付金额,单位分
|
||
|
|
UTR string `json:"utr"` // 代付UTR,非必填
|
||
|
|
Sign string `json:"sign"` // 签名值,详见签名算法,需转为大写
|
||
|
|
}
|
||
|
|
|
||
|
|
func Sign(m map[string]interface{}, t int) string {
|
||
|
|
str := []string{}
|
||
|
|
for i := range m {
|
||
|
|
if i == "sign" {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
str = append(str, i)
|
||
|
|
}
|
||
|
|
sort.Strings(str)
|
||
|
|
signStr := ""
|
||
|
|
for _, v := range str {
|
||
|
|
mv := m[v]
|
||
|
|
signStr += fmt.Sprintf("%v=%v", v, mv)
|
||
|
|
signStr += "&"
|
||
|
|
}
|
||
|
|
if t == 0 {
|
||
|
|
signStr += "key=" + key
|
||
|
|
} else {
|
||
|
|
signStr += "key=" + withdrawKey
|
||
|
|
}
|
||
|
|
log.Debug("signStr:%v", signStr)
|
||
|
|
return strings.ToUpper(util.CalculateMD5(signStr))
|
||
|
|
}
|
||
|
|
|
||
|
|
type QueryWithdrawReq struct {
|
||
|
|
PartnerId int64 `json:"partnerId"` // 支付中心分配的商户号
|
||
|
|
PartnerWithdrawNo string `json:"partnerWithdrawNo"` // 商户生成的代付号
|
||
|
|
Sign string `json:"sign"` // 签名值,详见签名算法
|
||
|
|
Version string `json:"version"` // 接口版本号,固定:1.0
|
||
|
|
}
|
||
|
|
|
||
|
|
type QueryWithdrawResp struct {
|
||
|
|
Code string `json:"code"`
|
||
|
|
Msg string `json:"message"`
|
||
|
|
Data interface{} `json:"data"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type QueryWithdrawData struct {
|
||
|
|
PayPartnerId int64 `json:"payPartnerId"`
|
||
|
|
WithdrawNo string `json:"withdrawNo"`
|
||
|
|
PartnerWithdrawNo string `json:"partnerWithdrawNo"`
|
||
|
|
Amount int `json:"amount"`
|
||
|
|
Status int `json:"status"` // 状态(0:创建订单;1:代付中;2:代付成功;3:代付失败)
|
||
|
|
SuccessTime string `json:"successTime"`
|
||
|
|
CreateTime string `json:"createTime"`
|
||
|
|
ErrorMsg string `json:"errorMsg"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func checkSign(str, sign string, t int) (pass bool) {
|
||
|
|
str = values.GetSignStrURLEncode(str, "sign")
|
||
|
|
if t == 0 {
|
||
|
|
str += "&key=" + key
|
||
|
|
} else {
|
||
|
|
str += "&key=" + withdrawKey
|
||
|
|
}
|
||
|
|
return strings.ToUpper(util.CalculateMD5(str)) == sign
|
||
|
|
}
|