请输入
菜单

通过Go使用kookeey线路实例及api签名

  • 通过Go配置kookeey代理

打开 kookeey IP 代理平台,假如端口是 http://gate.kookeey.io:15959,账号: kookeey,密码: 12345678 )。

package main

    import (
      "fmt"
      "io/ioutil"
      "log"
      "net/http"
      "os"
    )
    func main() {
      os.Setenv("HTTP_PROXY", "http://kookeey:12345678@gate.kookeey.io:15959")
      resp, err := http.Get("https://lumtest.com/myip.json")
      fmt.Println(resp)
      
      if err != nil {
        panic(err)
      }
      defer resp.Body.Close()

      if resp.StatusCode == http.StatusOK {
        bodyBytes, err := ioutil.ReadAll(resp.Body)
        if err != nil {
          log.Fatal(err)
        }
        bodyString := string(bodyBytes)
        fmt.Println(bodyString)
      }
    }


  • 通过Go调用API签名加密
package main

import (
    "crypto/hmac"
    "crypto/sha1"
    "encoding/hex"
    "encoding/base64"
    "time"
    "fmt"
)

func main() {

    ts := time.Now().Unix()
    fmt.Println((ts))
    secret := "1234567ABCDEFG="
    paramstr := "t=2&g=0&p=1&ts="
    data := fmt.Sprintf("%s%d", paramstr, ts)
    fmt.Printf("Secret: %s Data: %s\n", secret, data)

    // Create a new HMAC by defining the hash type and the key (as byte array)
    h := hmac.New(sha1.New, []byte(secret))

    // Write Data to it
    h.Write([]byte(data))

    // Get result and encode as hexadecimal string
    sha := hex.EncodeToString(h.Sum(nil))
    fmt.Println("before base64: "+sha);
    strbytes := []byte(sha)
    encoded := base64.StdEncoding.EncodeToString(strbytes)

    fmt.Println("Result: " + encoded)
}


上一个
通过Python使用kookeey线路实例及api签名
下一个
通过Java使用kookeey线路实例及api签名
最近修改: 2025-05-27