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.
247 lines
8.6 KiB
247 lines
8.6 KiB
package moneydealer |
|
|
|
import ( |
|
"fmt" |
|
"github.com/google/uuid" |
|
"server/config" |
|
"server/util" |
|
"sort" |
|
"strings" |
|
"time" |
|
|
|
"github.com/liangdas/mqant/log" |
|
) |
|
|
|
var ( |
|
baseUrl = "https://testorder.octopus-pay.com" |
|
payURL = "/api/order/create" // 创建订单 |
|
queryPayURL = "/api/order/status" // 订单查询 |
|
withdrawURL = "/api/order/create" |
|
queryWithdrawURL = "/api/order/status" |
|
projectCode = "p9lrvB5TaojgQxZTXeSnCoQ6IxBMp0z4RGFA0UulDebpwuXb" |
|
apiKey = "ahsxHdAk6oK2577QYkmB9kfjWrTrlplIRev3CfCnHFaXAbgmvNZk738VDD9MoH" |
|
apiSecret = "ESzyeg48ml0CSKKJt7qQhinlnZSYspY3O2sGlJsv4bofTv1YBm91tNPvqvIAw5" |
|
signType = "HMAC-SHA256" // 或者是"MD5" 回调是HMAC-SHA256 |
|
) |
|
|
|
func init() { |
|
if strings.ToUpper(config.GetBase().ServerFlag) == "B" { |
|
projectCode = "I872cvaUFYkDfVioaFWsrvDJL8FqqqZNvzHD1GwDABTvZ5O1" |
|
apiKey = "IosJgyQur0nvZtb0BKLDrz8VeTEnXEg4alFQ70y5IFnUm77YF9cuPGqdBSQHkZ" |
|
apiSecret = "gXwq6aza5gPvci3nvpgtPOkIDcQQaweQzm5LpcUNXa4YWklHNI3sUifWC4iYmK" |
|
} |
|
} |
|
|
|
type PayInfo struct { |
|
ProjectCode string |
|
ApiKey string |
|
ApiSecret string |
|
} |
|
|
|
func getPayInfo() PayInfo { |
|
if strings.ToUpper(config.GetBase().ServerFlag) == "B" { |
|
return PayInfo{ |
|
ProjectCode: "I872cvaUFYkDfVioaFWsrvDJL8FqqqZNvzHD1GwDABTvZ5O1", |
|
ApiKey: "IosJgyQur0nvZtb0BKLDrz8VeTEnXEg4alFQ70y5IFnUm77YF9cuPGqdBSQHkZ", |
|
ApiSecret: "gXwq6aza5gPvci3nvpgtPOkIDcQQaweQzm5LpcUNXa4YWklHNI3sUifWC4iYmK", |
|
} |
|
//projectCode = "I872cvaUFYkDfVioaFWsrvDJL8FqqqZNvzHD1GwDABTvZ5O1" |
|
//apiKey = "IosJgyQur0nvZtb0BKLDrz8VeTEnXEg4alFQ70y5IFnUm77YF9cuPGqdBSQHkZ" |
|
//apiSecret = "gXwq6aza5gPvci3nvpgtPOkIDcQQaweQzm5LpcUNXa4YWklHNI3sUifWC4iYmK" |
|
} else { |
|
return PayInfo{ |
|
ProjectCode: projectCode, |
|
ApiKey: apiKey, |
|
ApiSecret: apiSecret, |
|
} |
|
} |
|
} |
|
|
|
func getUrl() string { |
|
if config.GetConfig().Release { |
|
return "https://order.octopus-pay.com" |
|
} else { |
|
return baseUrl |
|
} |
|
} |
|
|
|
type PayReq struct { |
|
ProjectCode string `json:"project_code"` |
|
MerchantOrderNo string `json:"merchant_order_no"` |
|
UserUid string `json:"user_uid"` |
|
Amount string `json:"amount"` |
|
Currency string `json:"currency"` |
|
NotifyUrl string `json:"notify_url"` |
|
ReturnUrl string `json:"return_url"` |
|
ExtraData string `json:"extra_data"` |
|
} |
|
|
|
type UserData struct { |
|
UserName string `json:"userName"` |
|
UserEmail string `json:"userEmail"` |
|
UserPhone string `json:"userPhone"` |
|
} |
|
|
|
type PayRespData struct { |
|
OrderNo string `json:"order_no"` |
|
PayUrl string `json:"pay_url"` |
|
MerchantId string `json:"merchant_id"` |
|
ProjectCode string `json:"project_code"` |
|
UserUid string `json:"user_uid"` |
|
Amount string `json:"amount"` |
|
Currency string `json:"currency"` |
|
PaymentMode int `json:"payment_mode"` |
|
Signature string `json:"signature"` |
|
ExtraData string `json:"extra_data"` |
|
ExpiredAt string `json:"expired_at"` |
|
CreatedAt string `json:"created_at"` |
|
} |
|
|
|
type PayResp struct { |
|
Code int `json:"code"` // 200表示成功 |
|
Msg string `json:"msg"` // 状态描述 |
|
Data PayRespData `json:"data"` // 响应数据 |
|
} |
|
|
|
type PayCallbackReq struct { |
|
OrderNo string `json:"order_no"` |
|
MerchantOrderNo string `json:"merchant_order_no"` // 商户订单号 |
|
ProjectCode string `json:"project_code"` |
|
UserUid string `json:"user_uid"` |
|
Amount string `json:"amount"` |
|
Currency string `json:"currency"` |
|
Status int `json:"status"` // 0-待接单,1-已接单,2-已完成,3-已取消,4-已超时 |
|
PaymentMode int `json:"payment_mode"` |
|
CreatedAt int `json:"created_at"` |
|
ExtraData string `json:"extra_data"` |
|
Signature string `json:"signature"` |
|
} |
|
|
|
type QueryPayReq struct { |
|
OrderNo string `json:"order_no"` |
|
} |
|
|
|
type QueryPayResp struct { |
|
Code int `json:"code"` |
|
Message string `json:"message"` |
|
Data struct { |
|
OrderNo string `json:"order_no"` // 系统订单号 |
|
MerchantOrderNo string `json:"merchant_order_no"` // 商户订单号 |
|
Status int `json:"status"` // 0-待接单,1-已接单,2-已完成,3-已取消,4-已超时 |
|
PaymentMode int `json:"payment_mode"` // 支付模式:1-代收,2-代付 |
|
Amount string `json:"amount"` // 订单金额 |
|
Signature string `json:"signature"` // 签名 |
|
Currency string `json:"currency"` // 币种 |
|
CreatedAt int64 `json:"created_at"` |
|
} `json:"data"` |
|
} |
|
|
|
type WithdrawPayInfo struct { |
|
AccountType string `json:"account_type"` // 账户类型:UPI/Bank/USDT/Epay |
|
AccountNumber string `json:"account_number"` // 统一账户标识:银行账号/UPI ID/钱包地址/Epay账号 |
|
BeneficiaryName string `json:"beneficiary_name"` // 收款人姓名 |
|
BeneficiaryPhone string `json:"beneficiary_phone"` // 收款人手机号(10位数字,6-9开头) |
|
BankName string `json:"bank_name"` // 银行名称(account_type=Bank时必填) |
|
BankBranch string `json:"bank_branch"` // 银行分支 |
|
Ifsc string `json:"ifsc"` // IFSC代码(account_type=Bank时必填,11位格式) |
|
Remark string `json:"remark"` // 转账备注 |
|
} |
|
|
|
type WithdrawReq struct { |
|
ProjectCode string `json:"project_code"` |
|
MerchantOrderNo string `json:"merchant_order_no"` |
|
UserUid string `json:"user_uid"` |
|
Amount string `json:"amount"` |
|
Currency string `json:"currency"` |
|
PaymentMode int `json:"payment_mode"` // 支付模式:1-代收,2-代付(默认为1) |
|
NotifyUrl string `json:"notify_url"` |
|
PayoutInfo WithdrawPayInfo `json:"payout_info"` |
|
} |
|
|
|
type WithdrawResp struct { |
|
Code int `json:"code"` |
|
Message string `json:"message"` |
|
Data struct { |
|
OrderNo string `json:"order_no"` // 系统订单号 |
|
MerchantOrderNo string `json:"merchant_order_no"` // 商户订单号 |
|
Status int `json:"status"` // 0-待处理,1-处理中,2-已完成,3-已失败,4-已取消 |
|
PaymentMode int `json:"paymentMode"` // 支付模式:1-代收,2-代付 |
|
Amount string `json:"amount"` // 订单金额 |
|
Signature string `json:"signature"` // 签名 |
|
Currency string `json:"currency"` // 币种 |
|
CreatedAt string `json:"created_at"` // 创建时间 |
|
} `json:"data"` |
|
} |
|
|
|
type WithdrawCallbackReq struct { |
|
OrderNo string `json:"order_no"` |
|
MerchantOrderNo string `json:"merchant_order_no"` |
|
ProjectCode string `json:"project_code"` |
|
UserUid string `json:"user_uid"` |
|
Amount string `json:"amount"` |
|
Currency string `json:"currency"` |
|
Status int `json:"status"` // 0-待处理,1-处理中,2-已完成,3-已失败,4-已取消 |
|
PaymentMode int `json:"payment_mode"` |
|
CreatedAt int `json:"created_at"` |
|
ExtraData string `json:"extra_data"` |
|
Signature string `json:"signature"` |
|
} |
|
|
|
func Sign(m map[string]interface{}, t int) string { |
|
str := []string{} |
|
if _, ok := m["x-merchant-id"]; !ok { |
|
m["x-merchant-id"] = getPayInfo().ProjectCode |
|
} |
|
if _, ok := m["x-api-key"]; !ok { |
|
m["x-api-key"] = getPayInfo().ApiKey |
|
} |
|
if _, ok := m["x-timestamp"]; !ok { |
|
m["x-timestamp"] = fmt.Sprintf("%d", time.Now().Unix()) |
|
} |
|
if _, ok := m["x-nonce"]; !ok { |
|
m["x-nonce"] = uuid.New().String() |
|
} |
|
if _, ok := m["x-sign-type"]; !ok { |
|
m["x-sign-type"] = "MD5" |
|
} |
|
|
|
for i := range m { |
|
if i == "x-signature" { |
|
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=" + getPayInfo().ApiSecret |
|
} else { |
|
signStr += "key=" + getPayInfo().ApiSecret |
|
} |
|
log.Debug("signStr:%v", signStr) |
|
return strings.ToUpper(util.CalculateMD5(signStr)) |
|
} |
|
|
|
type QueryWithdrawReq struct { |
|
OrderNo string `json:"order_no"` |
|
} |
|
|
|
type QueryWithdrawResp struct { |
|
Code int `json:"code"` |
|
Message string `json:"message"` |
|
Data struct { |
|
OrderNo string `json:"order_no"` // 系统订单号 |
|
MerchantOrderNo string `json:"merchant_order_no"` // 商户订单号 |
|
Status int `json:"status"` // 0-待处理,1-处理中,2-已完成,3-已失败,4-已取消 |
|
PaymentMode int `json:"payment_mode"` // 支付模式:1-代收,2-代付 |
|
Amount string `json:"amount"` // 订单金额 |
|
Signature string `json:"signature"` // 签名 |
|
Currency string `json:"currency"` // 币种 |
|
CreatedAt int64 `json:"created_at"` |
|
} `json:"data"` |
|
}
|
|
|