package test import ( "app.yhyue.com/moapp/MessageCenter/rpc/messageclient" "bytes" "context" "encoding/json" "github.com/tal-tech/go-zero/core/discov" "github.com/tal-tech/go-zero/zrpc" "io/ioutil" "log" "net/http" "testing" "time" ) func Test_ChangeReadStatus(t *testing.T) { ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) std := messageclient.NewMessage(zrpc.MustNewClient(zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: []string{"127.0.0.1:2379"}, Key: "message.rpc"}})) //std := stdlibclient.NewStdlib(zrpc.MustNewClient(zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: []string{"127.0.0.1:2379"}, Key: "jydocs.stdlib.rpc"}})) req := &messageclient.ChangeReadStatusRequest{Id: "1",ReadStatus: 1,Appid: "10000"} res, err := std.ChangeReadStatus(ctx, req) log.Println("err ", err,res) //if res.State == true { // log.Println("req true") //} else { // log.Println("req false", res) //} } func Test_MultipleSaveMessage(t *testing.T) { msg :=map[string]interface{}{ "sendUserId": "qmx", "sendName": "剑鱼后台", "title": "消息标题", "content": "消息内容", "msgType": 1, "link": "http://baidu.com", "appid": "10000", } userIds := "5c00eee91c298a03ab5bd82b,606433f6ad7bab226a81787c" userNames := "," log.Println("调用批量保存消息接口") idsJson, _ := json.Marshal(map[string]interface{}{"msgInfo": msg,"userIds":userIds,"userNames":userNames}) reqData := bytes.NewBuffer([]byte(idsJson)) url := "http://127.0.0.1:8888/messageCenter/MultipleSaveMsg" method := "POST" client := &http.Client{} req, err := http.NewRequest(method, url, reqData) if err != nil { log.Println(err) } req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) defer res.Body.Close() log.Println(res, err) if err != nil { log.Println("调用批量保存消息接口出错:", err) } body, err := ioutil.ReadAll(res.Body) //log.Println("body", string(body)) var dat map[string]interface{} err = json.Unmarshal(body, &dat) log.Println("结果:", dat) if err != nil { log.Println("结果:", err) } //errCount = errCount + qutil.IntAll(dat["errCount"]) return }