Poker Fox - API
Poker Fox - API
Poker Fox - API
  • 🦊Poker Fox - Transfer Wallet API
  • 产品介绍
    • 市场概况
    • 产品特徵
    • 产品说明
    • 核心功能
  • 对接流程
  • 对接环境
  • 接口列表
    • 设置Header
    • 公共参数
    • 登入游戏
    • 上分
    • 下分
    • 用戶信息
    • 上下分状态
    • 投注记录
    • 玩家在线状态
    • 玩家投注明细
  • 相关对照表
    • 游戏列表
    • 語言参数对照表
    • 币種参数对照表
    • 国家地区参数对照列表
    • 非游戏消费类型
    • 代码状态說明
  • 程序范例
    • PHP
    • GO
Powered by GitBook
  1. 程序范例

GO

Last updated 1 year ago


GO范例程序下载

package main
 
import (
    "bytes"
    "crypto/aes"
    "crypto/cipher"
    "fmt"
    b64 "encoding/base64"
    "encoding/json"
    "net/http"
    "io/ioutil"
)

type B struct {
    Account string `json:"Account"`
}

type BMT struct {
    BB interface{} `json:"b"`
    M string `json:"m"`
    T int `json:"t"`
}

func main() {
	key := "3b4db1e4202bde5a1b75dbd941defc38"
	iv := "20454ee618d4fb86"
  	bb := B{
        Account: "egg_test_ip_004",
    }
    bmt := BMT{
        BB: bb,
        M: "1021202311031",
        T: 1648111171,
    }

    fmt.Println("================= DES Example =================")
    json_string, _ := json.Marshal(bmt)
    fmt.Println("Original Data")
    fmt.Println(string(json_string))
	data, _ := json.Marshal(bb)
	encode := EncryptAES_CBC(string(data), key, iv)
    fmt.Println("After encrypted")
    bmt.BB = encode
    json_string, _ = json.Marshal(bmt)
    fmt.Println(string(json_string))

    // decode := DecryptAES_CBC(encode, key, iv)
    // var sB B
    // _ = json.Unmarshal([]byte(decode), &sB)
    // bmt.BB = sB
    // json_string, _ = json.Marshal(bmt)
    // fmt.Println("After decrypted")
    // fmt.Println(string(json_string))
    fmt.Println("================= End DES Example =================")

    fmt.Println("================= Send Request =================")
    req, err := http.NewRequest("POST", "http://qa1.h5_open_api.nqsf9emow.com:27799/v1/epoker/account/info", bytes.NewBuffer(json_string))
    // req.Header.Set("X-Custom-Header", "myvalue")
    req.Header.Set("Content-Type", "application/json")
    // must to set the User-Agent
    req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36")
    req.Header.Set("lang", "en-US")
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))
    fmt.Println("================= End Send Request =================")
}

func EncryptAES_CBC(src, key, iv string) string {
    data := []byte(src)
    keyByte := []byte(key)
    block, err := aes.NewCipher(keyByte)
    if err != nil {
        panic(err)
    }
    data = PKCS5Padding(data, block.BlockSize())
    ivByte := []byte(iv)
    mode := cipher.NewCBCEncrypter(block, ivByte)
    out := make([]byte, len(data))
    mode.CryptBlocks(out, data)
	encode := b64.StdEncoding.EncodeToString(out)
    return encode
}
 
func DecryptAES_CBC(src, key, iv string) string {
    data, _ := b64.StdEncoding.DecodeString(src)
    keyByte := []byte(key)
    block, err := aes.NewCipher(keyByte)
    if err != nil {
        panic(err)
    }
    ivByte := []byte(iv)
    mode := cipher.NewCBCDecrypter(block, ivByte)
    decode := make([]byte, len(data))
    mode.CryptBlocks(decode, data)
    decode = PKCS5UnPadding(decode)
    return string(decode)
}
 
func PKCS5Padding(ciphertext []byte, blockSize int) []byte {
    padding := blockSize - len(ciphertext)%blockSize
    padtext := bytes.Repeat([]byte{byte(padding)}, padding)
    return append(ciphertext, padtext...)
}
 
func PKCS5UnPadding(origData []byte) []byte {
    length := len(origData)
    unpadding := int(origData[length-1])
    return origData[:(length - unpadding)]
}