github.com/872409/go-netease-im@v1.0.2-0.20201109080841-fdb3e13691c5/tests/notify_test.go (about)

     1  package tests
     2  
     3  import (
     4  	"bytes"
     5  	"net/http"
     6  	"os"
     7  	"strconv"
     8  	"testing"
     9  	"time"
    10  
    11  	"github.com/872409/go-netease-im"
    12  )
    13  
    14  func TestCheckSum(t *testing.T) {
    15  	os.Setenv("GOCACHE", "off")
    16  	cli := netease.CreateImClient("b2c60dbed0ae2d3c48e6c85664836dc9", "1ed04f7d7085", "")
    17  
    18  	body := []byte(`{}`)
    19  	req, _ := http.NewRequest("POST", "http://yunxinservice.com.cn/receiveMsg.action", bytes.NewReader(body))
    20  	curTime := strconv.FormatInt(time.Now().UnixNano(), 10)
    21  	md5 := netease.Md5HashToHexString(body)
    22  	req.Header.Set("CurTime", curTime)
    23  	req.Header.Set("MD5", md5)
    24  	req.Header.Set("CheckSum", netease.ShaHashToHexStringFromString(cli.AppSecret+md5+curTime))
    25  	t.Log("checksum:", cli.AppSecret+md5+curTime, "checksum-encoded:", netease.ShaHashToHexStringFromString(cli.AppSecret+md5+curTime))
    26  
    27  	bd, err := cli.GetEventNotification(req)
    28  	t.Log(string(bd), err)
    29  }