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.
222 lines
9.8 KiB
222 lines
9.8 KiB
|
1 year ago
|
package pgsoft
|
||
|
|
|
||
|
|
import (
|
||
|
|
"io"
|
||
|
|
"net/http"
|
||
|
|
"net/url"
|
||
|
|
"strings"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/liangdas/mqant/log"
|
||
|
|
)
|
||
|
|
|
||
|
|
const (
|
||
|
|
APIURL = "https://api.pg-bo.co"
|
||
|
|
APITest = "https://api.pg-bo.me"
|
||
|
|
// APIURL = "https://m.pgr-nmga.com"
|
||
|
|
// APITest = "https://m.pg-redirect.net"
|
||
|
|
OperatorTokenTest = "164a855bf5129a8448dffc31ff9ec86c"
|
||
|
|
SecretKeyTest = "c441ef6f2297b8390e2d2dad353599fa"
|
||
|
|
SaltTest = "d6b791314cd04dc6d82e372a11bfd7bd"
|
||
|
|
OperatorTokenRelease = "4735860F-03A6-5C31-EDD3-3484B0B8E8A0"
|
||
|
|
SecretKeyRelease = "687CCAFA0D12C0081F48E7D307FD18E4"
|
||
|
|
SaltRelease = "85238F6B2158D393F447D5F03CA047FB"
|
||
|
|
)
|
||
|
|
|
||
|
|
var (
|
||
|
|
OperatorToken = ""
|
||
|
|
SecretKey = ""
|
||
|
|
Salt = ""
|
||
|
|
)
|
||
|
|
|
||
|
|
var (
|
||
|
|
API = ""
|
||
|
|
)
|
||
|
|
|
||
|
|
type Error struct {
|
||
|
|
Code string
|
||
|
|
Message string
|
||
|
|
}
|
||
|
|
|
||
|
|
type CommonResp struct {
|
||
|
|
Data interface{} `json:"data"`
|
||
|
|
Error *Error `json:"error"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type verifySessionReq struct {
|
||
|
|
OperatorToken string `json:"operator_token"`
|
||
|
|
SecretKey string `json:"secret_key"`
|
||
|
|
OperatorPlayerSession string `json:"operator_player_session"`
|
||
|
|
GameID int `json:"game_id"`
|
||
|
|
IP string `json:"ip"`
|
||
|
|
CustomParameter string `json:"custom_parameter"`
|
||
|
|
BetType int `json:"bet_type"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type verifySessionResp struct {
|
||
|
|
PlayerName string `json:"player_name"`
|
||
|
|
Nickname string `json:"nickname"`
|
||
|
|
Currency string `json:"currency"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type CashGetReq struct {
|
||
|
|
OperatorToken string `json:"operator_token"`
|
||
|
|
SecretKey string `json:"secret_key"`
|
||
|
|
PlayerName string `json:"player_name"`
|
||
|
|
OperatorPlayerSession string `json:"operator_player_session"`
|
||
|
|
GameID int `json:"game_id"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type CashGetResp struct {
|
||
|
|
CurrencyCode string `json:"currency_code"`
|
||
|
|
BalanceAmount float64 `json:"balance_amount"`
|
||
|
|
UpdatedTime int64 `json:"updated_time"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type TransInOutReq struct {
|
||
|
|
OperatorToken string `json:"operator_token"`
|
||
|
|
SecretKey string `json:"secret_key"`
|
||
|
|
OperatorPlayerSession string `json:"operator_player_session"`
|
||
|
|
PlayerName string `json:"player_name"`
|
||
|
|
GameID int `json:"game_id"`
|
||
|
|
ParentBetID string `json:"parent_bet_id"`
|
||
|
|
BetID string `json:"bet_id"`
|
||
|
|
CurrencyCode string `json:"currency_code"`
|
||
|
|
BetAmount float64 `json:"bet_amount"`
|
||
|
|
WinAmount float64 `json:"win_amount"`
|
||
|
|
TransferAmount float64 `json:"transfer_amount"`
|
||
|
|
TansactionID string `json:"transaction_id"`
|
||
|
|
WalletType string `json:"wallet_type"`
|
||
|
|
BetType int `json:"bet_type"`
|
||
|
|
Platform string `json:"platform"`
|
||
|
|
CreateTime int64 `json:"create_time"`
|
||
|
|
UpdatedTime int64 `json:"updated_time"`
|
||
|
|
IsValidateBet bool `json:"is_validate_bet"` // 表示该请求是否是为进行验证而重新发送的交易 True: 重新发送的交易 False: 正常交易
|
||
|
|
IsAdjustment bool `json:"is_adjustment"` // 表示该请求是否是待处理投注的调整或正常交易 True: 调整 False: 正常交易
|
||
|
|
IsParentZeroStake bool `json:"is_parent_zero_stake"` // 表示该请求在第一轮投注中的投注金 额是否为0 True: 在第一轮投注中的投注金额为0(针对至尊百家乐的飞牌操作)False: 在第一轮投注中的投注金额大于 0
|
||
|
|
IsFeature bool `json:"is_feature"` // 表示旋转类型 True: 特色旋转 False: 普通旋转
|
||
|
|
IsFeatureBuy bool `json:"is_feature_buy"` // 表示购买奖金游戏 注:仅适用于具有购买奖金游戏功能的游戏
|
||
|
|
IsWager bool `json:"is_wager"` // 表示该交易是否为投注
|
||
|
|
IsEndRound bool `json:"is_end_round"` // 表示当前游戏投注是否已结束
|
||
|
|
FreeGameTransactionID string `json:"free_game_transaction_id"` // 免费游戏的唯一标识符 只有在免费游戏分配给玩家时才会出现。注:仅适用于以外部应用编程接口API创建的免费游戏
|
||
|
|
FreeGameName string `json:"free_game_name"` // 免费游戏名称只有在免费游戏分配给玩家时才会出现。
|
||
|
|
FreeGameID int `json:"free_game_id"` // 免费游戏的唯一标识符 只有在免费游戏分配给玩家时才会出现。
|
||
|
|
IsMinusCount bool `json:"is_minus_count"` // 免费游戏中的旋转类型 True: 普通旋转(扣除免费游戏次数) False: 免费旋转
|
||
|
|
BonusTransactionID string `json:"bonus_transaction_id"` // 红利游戏的唯一标识符 只有在红利分配给玩家时才会出现。注:仅适用于以外部应用编程接口API创建的红利游戏
|
||
|
|
BonusName string `json:"bonus_name"` // 红利游戏名称 只有在红利分配给玩家时才会出现。
|
||
|
|
BonusID int `json:"bonus_id"` // 红利游戏的唯一标识符 只有在红利分配给玩家时才会出现。
|
||
|
|
BonusBalanceAmount float64 `json:"bonus_balance_amount"` // 红利钱包的红利总金额 只有在玩家选择用现金完成红利时才会出现。
|
||
|
|
BonusRatioAmount float64 `json:"bonus_ratio_amount"` // 红利游戏中玩家需要达到的流水金额 只有在玩家选择用现金完成红利时才会出现。
|
||
|
|
}
|
||
|
|
|
||
|
|
type TransInOutResp struct {
|
||
|
|
CurrencyCode string `json:"currency_code"`
|
||
|
|
BalanceAmount float64 `json:"balance_amount"`
|
||
|
|
UpdatedTime int64 `json:"updated_time"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type AdjustmentReq struct {
|
||
|
|
OperatorToken string `json:"operator_token"`
|
||
|
|
SecretKey string `json:"secret_key"`
|
||
|
|
PlayerName string `json:"player_name"`
|
||
|
|
CurrencyCode string `json:"currency_code"`
|
||
|
|
BetType int `json:"bet_type"`
|
||
|
|
TransferAmount float64 `json:"transfer_amount"`
|
||
|
|
AdjustmentTime int64 `json:"adjustment_time"`
|
||
|
|
AdjustmentID string `json:"adjustment_id"`
|
||
|
|
AdjustmentTransaction string `json:"adjustment_transaction_id"`
|
||
|
|
TransactionType string
|
||
|
|
}
|
||
|
|
|
||
|
|
type AdjustmentResp struct {
|
||
|
|
AdjustAmount float64 `json:"adjust_amount"`
|
||
|
|
BalanceBefore float64 `json:"balance_before"`
|
||
|
|
BalanceAfter float64 `json:"balance_after"`
|
||
|
|
UpdatedTime int64 `json:"updated_time"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// BetReq 请求下注
|
||
|
|
type BetReq struct {
|
||
|
|
ReqID string `json:"reqId"` // 请求识别码
|
||
|
|
Token string `json:"token"` // token
|
||
|
|
Currency string `json:"Currency"`
|
||
|
|
Game int `json:"game"` // 游戏代码
|
||
|
|
Round int64 `json:"round"` // 注单唯一识别值
|
||
|
|
WagersTime int64 `json:"wagersTime"` // 注单结账时间戳
|
||
|
|
BetAmount float64 `json:"betAmount"` // 押注金额
|
||
|
|
WinLoseAmount float64 `json:"winloseAmount"` // 发奖金额
|
||
|
|
IsFreeRound bool `json:"isFreeRound"` // 为true时表示离线开奖
|
||
|
|
UserId string `json:"userId"` // 玩家账号唯一值
|
||
|
|
TransactionID int64 `json:"transactionId"` // 离线开奖触发局局号
|
||
|
|
Platform string `json:"platform"` // 玩家装置信息
|
||
|
|
}
|
||
|
|
|
||
|
|
type BetResp struct {
|
||
|
|
ErrorCode int `json:"errorCode"` // 0成功
|
||
|
|
Message string `json:"message"` // 信息
|
||
|
|
UserName string `json:"username"` // 账号唯一识别名称
|
||
|
|
Currency string `json:"currency"` // 身上持有币种
|
||
|
|
Balance float64 `json:"balance"` // 余额
|
||
|
|
TxID int64 `json:"txId"` // 营运商注单号
|
||
|
|
Token string `json:"token"` // token
|
||
|
|
}
|
||
|
|
|
||
|
|
// SessionBetReq 请求下注
|
||
|
|
type SessionBetReq struct {
|
||
|
|
ReqID string `json:"reqId"` // 请求识别码
|
||
|
|
Token string `json:"token"` // token
|
||
|
|
Currency string `json:"Currency"`
|
||
|
|
Game int `json:"game"` // 游戏代码
|
||
|
|
Round int64 `json:"round"` // 注单唯一识别值
|
||
|
|
WagersTime int64 `json:"wagersTime"` // 注单结账时间戳
|
||
|
|
BetAmount float64 `json:"betAmount"` // 押注金额
|
||
|
|
WinLoseAmount float64 `json:"winloseAmount"` // 发奖金额
|
||
|
|
SessionID int64 `json:"sessionId"` // 牌局唯一值
|
||
|
|
Type int `json:"type"` // 注单类型 1下注 2结算
|
||
|
|
UserId string `json:"userId"` // 玩家账号唯一值
|
||
|
|
TurnOver float64 `json:"turnover"` // 有效投注
|
||
|
|
Preserve float64 `json:"preserve"` // 有效投注
|
||
|
|
Platform string `json:"platform"` // 玩家装置信息
|
||
|
|
SessionTotalBet float64 `json:"sessionTotalBet"` // 整一局总投注
|
||
|
|
}
|
||
|
|
|
||
|
|
// HttpPostForm post请求
|
||
|
|
func HttpPostForm(target string, send url.Values) (string, error) {
|
||
|
|
log.Debug("send:%+v", send.Encode())
|
||
|
|
// ul += fmt.Sprintf("%v=%v", "sign", util.CalculateMD5(oid+strconv.Itoa(apiReq.AdvChannel)+apiReq.ClientDate+apiReq.Money+values.ZYAppKey))
|
||
|
|
|
||
|
|
req, err := http.NewRequest("POST", target, strings.NewReader(send.Encode()))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
return "", err
|
||
|
|
}
|
||
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||
|
|
req.Header.Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||
|
|
// req.Header.Set("Accept", "application/problem+json")
|
||
|
|
// req.Header.Set("Authorization", "api-key "+config.GetConfig().Web.OrangePay.APISecret)
|
||
|
|
// req.Header.Set("Authorization", "api-key "+OrangeAPISecret)
|
||
|
|
|
||
|
|
client := &http.Client{
|
||
|
|
Timeout: 5 * time.Second,
|
||
|
|
}
|
||
|
|
log.Debug("req:%+v", req)
|
||
|
|
resp, err := client.Do(req)
|
||
|
|
if err != nil {
|
||
|
|
log.Error("http post call err:%v", err)
|
||
|
|
return "", err
|
||
|
|
}
|
||
|
|
// if resp.StatusCode != http.StatusOK {
|
||
|
|
// log.Error("req fail err code:%v", resp.StatusCode)
|
||
|
|
// return errors.New("http req fail")
|
||
|
|
// }
|
||
|
|
defer resp.Body.Close()
|
||
|
|
body, _ := io.ReadAll(resp.Body)
|
||
|
|
res := string(body)
|
||
|
|
log.Debug("response Body%v:", res)
|
||
|
|
// if err := json.Unmarshal(body, ret); err != nil {
|
||
|
|
// log.Error("unmarshal fail err:%v", err)
|
||
|
|
// return err
|
||
|
|
// }
|
||
|
|
return res, nil
|
||
|
|
}
|