# Go

# 代码示例

package main

import (
   "crypto/aes"
   "crypto/cipher"
   "encoding/base64"
   "encoding/json"
   "fmt"
   "io/ioutil"
   "net/http"
   "strings"
)

const (
   c_url    = "https://api.yazx.com/phone/check/v3/callback"
   c_snuser = "xxx"
   c_snkey  = "xxx"
)

func AESDecrypt(ciphertxt string, keystr string) string {
   // prepare cipher text
   cipherbyte, _ := base64.StdEncoding.DecodeString(ciphertxt)
   // prepare the key
   block, _ := aes.NewCipher([]byte(keystr))

   if len(cipherbyte) < aes.BlockSize {
      return ""
   }

   // split iv and ciphertext
   iv := cipherbyte[:aes.BlockSize]
   cipherbyte = cipherbyte[aes.BlockSize:]
   stream := cipher.NewCFBDecrypter(block, iv)

   // XORKeyStream can work in-place if the two arguments are the same.
   stream.XORKeyStream(cipherbyte, cipherbyte)
   return string(cipherbyte)
}

func Check() {
   payload := strings.NewReader("{\"snuser\": \"" + c_snuser + "\"}")
   req, _ := http.NewRequest("POST", c_url, payload)
   req.Header.Add("content-type", "application/json")
   res, _ := http.DefaultClient.Do(req)

   defer res.Body.Close()
   body, _ := ioutil.ReadAll(res.Body)

   fmt.Println(string(body))
   var response map[string]interface{}
   if err := json.Unmarshal(body, &response); err != nil {
      panic(err)
   }

   if response["status"].(float64) != 200 {
      fmt.Println("get status failed")
   } else {
      fmt.Println("get status success =>>>")
      fmt.Println(AESDecrypt(response["data"].(string), c_snkey))
   }
}


func main() {
   Check()
}
Last Updated: 1/6/2023, 3:12:40 PM