package internal import ( "encoding/json" "fmt" mqtt "github.com/eclipse/paho.mqtt.golang" "strings" ) type MoneyBody struct { Uids string `json:"uids"` Money int32 `json:"money"` Type int32 `json:"type"` ModuleType string `json:"moduleType"` } type MqttChangeMoney struct { ReqId int64 `json:"reqId"` ModuleId string `json:"moduleId"` Body MoneyBody `json:"body"` } func SendMqttMoney(msg interface{}, c chan bool, server string) { registerFunc := func(client mqtt.Client, qtmsg mqtt.Message) { ss := string(msg.([]byte)) fmt.Println(ss) err := ClientSend("client", 0, false, ss) if err != nil { c <- false } } mailFunc := func(client mqtt.Client, qtmsg mqtt.Message) { res := &MqttResult{} client.Disconnect(1) ss := string(qtmsg.Payload()) ss = ss[1 : len(ss)-1] ss = strings.Replace(ss, "\\", "", -1) err := json.Unmarshal([]byte(ss), res) if err == nil && res.RespId == 1 && res.Error == nil { c <- true return } c <- false } if NewMqttClient(registerFunc, mailFunc, server) != nil { c <- false } }