| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- package main
- import (
- "bytes"
- "crypto/sha256"
- "encoding/hex"
- "encoding/json"
- "io"
- "net/http"
- "regexp"
- "testing"
- "time"
- )
- func Test_send(t *testing.T) {
- var classReq []ClassReq
- classReq = append(classReq, ClassReq{
- SeriesName: "故宫博物院11",
- SeriesIssuer: "海南边界智能科技有限公司",
- ExternalUrl: "http://github.com",
- SeriesDes: "",
- SeriesId: []string{"0xF3C2fFA43d20599b1a4163CB3cCB61B57D0624CB"},
- TotalDNA: 100,
- AssetContracts: "did:bid:ef28nLJWiyEX8x61qXohtZhSadwEuZD28",
- })
- objJson, err := json.Marshal(&Req{
- Data: classReq,
- })
- if err != nil {
- t.Log(err)
- return
- }
- // payload := bytes.NewReader(objJson)
- // req, err := http.Post("https://test-dna.bitfactory.cn/auth/api/v1/series", "application/json", bytes.NewBuffer(objJson))
- req, err := http.NewRequest("POST", "https://test-dna.bitfactory.cn/auth/api/v1/series", bytes.NewBuffer(objJson))
- if err != nil {
- t.Log(err)
- return
- }
- req.Header.Add("Content-Type", "application/json")
- req.Header.Add("accessToken", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBcHBJZCI6IjFiNTQyNWExLTBlYjAtNDM3Yy1iZjU2LWEyZTZkMDhkOTUyZiIsIkJpZlVzZXJCaWQiOiJkaWQ6YmlkOmVmWmR2NXJKTERiU0xGcFFwUENydDkzZXhGOFU2MnR3IiwiZXhwIjoxNzA2MjcxOTM3LCJpYXQiOjE3MDYyNjQ3Mzd9.RybVRFHzH4w7EiAF3vF-gkz6dPmTi0qyJZvg4fGPNPQ")
- client := &http.Client{Timeout: time.Duration(3) * time.Second}
- res, err := client.Do(req)
- if err != nil {
- t.Log(err)
- return
- }
- body, err := io.ReadAll(res.Body)
- if err != nil {
- t.Log(err)
- return
- }
- t.Log(string(body))
- // var resp Resp
- // err = json.Unmarshal(body, &resp)
- // if err != nil {
- // t.Log(err)
- // return
- // }
- // if resp.RetCode != http.StatusOK || resp.RetMsg != "ok" {
- // t.Log(resp.RetCode, resp.RetMsg)
- // return
- // }
- }
- func Test_hash(t *testing.T) {
- data := []byte("http://github.com")
- // 使用SHA-256哈希算法计算哈希值
- hash := sha256.Sum256(data)
- // 将哈希值转换为十六进制字符串
- hashStr := hex.EncodeToString(hash[:])
- t.Log(hashStr)
- }
- func Test_Reg(t *testing.T) {
- pattern := `^tokenBID:did:bid:.*重复$`
- // 编译正则表达式
- regex, err := regexp.Compile(pattern)
- if err != nil {
- t.Log("正则表达式编译失败:", err)
- return
- }
- if regex.MatchString("tokenBID:did:bid:efLqdkWTLUFFKaDCRWFrr8j5RUB1euka重复") {
- t.Log("匹配成功!")
- } else {
- t.Log("未匹配到符合条件的字符串.")
- }
- }
|