@@ -0,0 +1,130 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"91porn-server/app/appg"
|
||||
"91porn-server/common/httputil"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/web/webg"
|
||||
"crypto/md5"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
GainGameCodeUrl = "/api/jt/product/getscode"
|
||||
QueryGameCodeUrl = "/api/jt/product/getsclist"
|
||||
)
|
||||
|
||||
type GameCodeReq struct {
|
||||
Level int `json:"level" bson:"level"` // 商品等级
|
||||
Sign string `json:"sign" bson:"sign"` // md5加密
|
||||
}
|
||||
|
||||
type GameCodeResp struct {
|
||||
Code int `json:"code" bson:"code"` // code编码
|
||||
Data Data `json:"data" bson:"data"` // 游戏码响应内容
|
||||
Msg string `json:"msg" bson:"msg"` // 返回内容
|
||||
Hash bool `json:"hash" bson:"hash"` // hash
|
||||
Time string `json:"time" bson:"time"` // 时间
|
||||
Tip string `json:"tip" bson:"tip"` // 提示内容
|
||||
}
|
||||
|
||||
type Data struct {
|
||||
Code int `json:"code" bson:"code"` // code编码
|
||||
Msg string `json:"msg" bson:"msg"` // 返回内容
|
||||
SubscriptionCode string `json:"subscriptionCode" bson:"subscriptionCode"` // 订单订阅码(无用)
|
||||
SerialCode string `json:"serialCode" bson:"serialCode"` // 序列号 (玩家游戏使用)
|
||||
}
|
||||
|
||||
type QueryGameCodeReq struct {
|
||||
PageNum int `json:"pageNum" bson:"pageNum"` // 当前页
|
||||
PageSize int `json:"pageSize" bson:"pageSize"` // 页码
|
||||
}
|
||||
|
||||
type QueryGameCodeResp struct {
|
||||
Code int `json:"code" bson:"code"` // code编码
|
||||
Data QueryData `json:"data" bson:"data"` // 游戏码响应内容
|
||||
Msg string `json:"msg" bson:"msg"` // 返回内容
|
||||
Hash bool `json:"hash" bson:"hash"` // hash
|
||||
Time string `json:"time" bson:"time"` // 时间
|
||||
Tip string `json:"tip" bson:"tip"` // 提示内容
|
||||
}
|
||||
|
||||
type QueryData struct {
|
||||
Total int `json:"total" bson:"total"` // 总数
|
||||
List []Detail `json:"list" bson:"list"` // 返回内容
|
||||
}
|
||||
|
||||
type Detail struct {
|
||||
SubscriptionCode string `json:"subscriptionCode" bson:"subscriptionCode"` // 订单订阅码(无用)
|
||||
SerialCode string `json:"serialCode" bson:"serialCode"` // 序列号 (玩家游戏使用)
|
||||
UserId string `json:"userId" bson:"userId"` // 用户ID
|
||||
MerchantId int `json:"merchantId" bson:"merchantId"` // 商户号
|
||||
ProductPrice int `json:"productPrice" bson:"productPrice"` // 商品价格
|
||||
ProductLevel int `json:"productLevel" bson:"productLevel"` // 商品等级
|
||||
CreatedAt string `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
}
|
||||
|
||||
func GainTripartiteGameCode(uid uint64) (string, error) {
|
||||
var gameCode string
|
||||
userId := fmt.Sprintf("LLD_%v", uid)
|
||||
sprintf := fmt.Sprintf("userid=%v&merchantid=%v", userId, appg.Conf.Game.MercId)
|
||||
reqHeader := base64.StdEncoding.EncodeToString([]byte(sprintf))
|
||||
|
||||
md5Str := fmt.Sprintf("level=%d&userid=%v&merchantid=%d", 1, userId, appg.Conf.Game.MercId)
|
||||
hash := md5.Sum([]byte(md5Str))
|
||||
// 将 MD5 转换为十六进制字符串
|
||||
md5String := hex.EncodeToString(hash[:])
|
||||
|
||||
var (
|
||||
url = appg.Conf.Game.URL + GainGameCodeUrl
|
||||
params = GameCodeReq{Level: 1, Sign: md5String}
|
||||
out GameCodeResp
|
||||
)
|
||||
h := map[string]string{"m-api-key": reqHeader}
|
||||
|
||||
code, err := httputil.DefaultClientPostJsonWithResp(&out, url, h, params)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("GainTripartiteGameCode http request err:[%v],uid:[%v],url:[%v],params:[%v]", err, uid, url, params))
|
||||
return gameCode, err
|
||||
}
|
||||
if code != http.StatusOK {
|
||||
return gameCode, errors.New("status code is err")
|
||||
}
|
||||
|
||||
if out.Data.Code == http.StatusOK {
|
||||
gameCode = out.Data.SerialCode
|
||||
}
|
||||
return gameCode, nil
|
||||
}
|
||||
|
||||
func QueryTripartiteGameCode(uid uint64) (*QueryData, error) {
|
||||
userId := fmt.Sprintf("LLD_%v", uid)
|
||||
sprintf := fmt.Sprintf("userid=%v&merchantid=%v", userId, webg.Conf.Game.MercId)
|
||||
reqHeader := base64.StdEncoding.EncodeToString([]byte(sprintf))
|
||||
|
||||
var (
|
||||
url = webg.Conf.Game.URL + QueryGameCodeUrl
|
||||
params = QueryGameCodeReq{PageNum: 1, PageSize: 10}
|
||||
out QueryGameCodeResp
|
||||
)
|
||||
h := map[string]string{"m-api-key": reqHeader}
|
||||
|
||||
code, err := httputil.DefaultClientPostJsonWithResp(&out, url, h, params)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("QueryTripartiteGameCode http request err:[%v],uid:[%v],url:[%v],params:[%v]", err, uid, url, params))
|
||||
return nil, err
|
||||
}
|
||||
if code != http.StatusOK {
|
||||
return nil, errors.New("status code is err")
|
||||
}
|
||||
|
||||
if out.Code == http.StatusOK {
|
||||
return &out.Data, nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
Reference in New Issue
Block a user