|
@@ -48,7 +48,7 @@ func init() {
|
|
|
|
|
|
func NatsInit() {
|
|
|
|
|
|
- // 请求-响应, 响应 test3 消息。
|
|
|
+ // 获取微信二维码 返回结果
|
|
|
_, _ = lib.Nats.Subscribe("Wx_BasicMessage_Event_QRCode", func(m *nats.Msg) {
|
|
|
fmt.Printf(" => Nats Wx_BasicMessage_Event_QRCode message: %s\n", string(m.Data))
|
|
|
|
|
@@ -70,151 +70,26 @@ func NatsInit() {
|
|
|
fmt.Println("EventKey-", person_QRCode.EventKey)
|
|
|
|
|
|
// 开始 处理消息
|
|
|
- if strings.Contains(person_QRCode.EventKey, "@宝智达 微信公众号通知") {
|
|
|
+ if strings.Contains(person_QRCode.EventKey, "@宝智达冷链 微信公众号通知") {
|
|
|
//"请将本内容发送到 深圳市宝智达科技有限公司 微信公众号-|"+lib.AesEncryptCBC(T_calss_id, "0123456789012345")+"|-",
|
|
|
Content_r := lib.GetBetweenStr(person_QRCode.EventKey, "-|", "|-")
|
|
|
decryptCode := lib.AesDecryptCBC(Content_r, "0123456789012345")
|
|
|
- decryptCode_int, err := strconv.Atoi(decryptCode)
|
|
|
- fmt.Println("解密结果:", decryptCode, " decryptCode_int", decryptCode_int, " Content_r:", Content_r)
|
|
|
- R_DeviceNotice, err := Company.Read_CompanyNotice_ById(decryptCode_int)
|
|
|
+ fmt.Println("解密结果 UUID:", decryptCode, " Content_r:", Content_r)
|
|
|
+ Admin_r, err := Account.Read_Admin_ByUuid(decryptCode)
|
|
|
if err != nil {
|
|
|
_ = lib.Nats.Publish(m.Reply, []byte(""))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if strings.Contains(R_DeviceNotice.T_Notice_wx, person_QRCode.FromUserName) {
|
|
|
+ Admin_r.T_wx = person_QRCode.FromUserName
|
|
|
+ Account.Update_Admin(Admin_r, "T_wx")
|
|
|
|
|
|
- _ = lib.Nats.Publish(m.Reply, []byte(R_DeviceNotice.T_name+" 已绑定,无需重复绑定!"))
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- R_DeviceNotice.T_Notice_wx = R_DeviceNotice.T_Notice_wx + person_QRCode.FromUserName + "/重令名|"
|
|
|
- Company.Update_CompanyNotice(R_DeviceNotice, "T_Notice_wx")
|
|
|
-
|
|
|
- _ = lib.Nats.Publish(m.Reply, []byte(R_DeviceNotice.T_name+" 绑定成功!"))
|
|
|
+ _ = lib.Nats.Publish(m.Reply, []byte(Admin_r.T_name+" 绑定成功!"))
|
|
|
return
|
|
|
}
|
|
|
_ = lib.Nats.Publish(m.Reply, []byte(""))
|
|
|
})
|
|
|
|
|
|
- // 请求-响应, 响应 test3 消息。
|
|
|
- _, _ = lib.Nats.Subscribe("Wx2_BasicMessage_Event_QRCode", func(m *nats.Msg) {
|
|
|
- fmt.Printf(" => Nats Wx2_BasicMessage_Event_QRCode message: %s\n", string(m.Data))
|
|
|
-
|
|
|
- type Person_QRCode struct {
|
|
|
- ToUserName string `xml:"ToUserName"` //注意这里有个反引号
|
|
|
- FromUserName string `xml:"FromUserName"` //注意这里有个反引号
|
|
|
- CreateTime string `xml:"CreateTime"` //注意这里有个反引号
|
|
|
- EventKey string `xml:"EventKey"`
|
|
|
- }
|
|
|
- var person_QRCode Person_QRCode
|
|
|
- err1 := xml.Unmarshal(m.Data, &person_QRCode)
|
|
|
- if err1 != nil {
|
|
|
- fmt.Println("Unmarshal error")
|
|
|
- _ = lib.Nats.Publish(m.Reply, []byte(""))
|
|
|
- return
|
|
|
- }
|
|
|
- // 进入 二维码配对
|
|
|
- fmt.Println("FromUserName-", person_QRCode.FromUserName)
|
|
|
- fmt.Println("EventKey-", person_QRCode.EventKey)
|
|
|
-
|
|
|
- // 开始 处理消息
|
|
|
- if strings.Contains(person_QRCode.EventKey, "@宝智达 微信公众号通知") {
|
|
|
- //"请将本内容发送到 深圳市宝智达科技有限公司 微信公众号-|"+lib.AesEncryptCBC(T_calss_id, "0123456789012345")+"|-",
|
|
|
- Content_r := lib.GetBetweenStr(person_QRCode.EventKey, "-|", "|-")
|
|
|
- decryptCode := lib.AesDecryptCBC(Content_r, "0123456789012345")
|
|
|
- decryptCode_int, err := strconv.Atoi(decryptCode)
|
|
|
- fmt.Println("解密结果:", decryptCode, " decryptCode_int", decryptCode_int, " Content_r:", Content_r)
|
|
|
- R_DeviceNotice, err := Company.Read_CompanyNotice_ById(decryptCode_int)
|
|
|
- if err != nil {
|
|
|
- _ = lib.Nats.Publish(m.Reply, []byte(""))
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if strings.Contains(R_DeviceNotice.T_Notice_wx2, person_QRCode.FromUserName+"/重令名|") {
|
|
|
- _ = lib.Nats.Publish(m.Reply, []byte(R_DeviceNotice.T_name+" 重复扫码!请在 5分钟内 回复您的名字,否则将 无法收到报警消息!如回复:张三"))
|
|
|
- return
|
|
|
- }
|
|
|
- if strings.Contains(R_DeviceNotice.T_Notice_wx2, person_QRCode.FromUserName) {
|
|
|
- _ = lib.Nats.Publish(m.Reply, []byte(R_DeviceNotice.T_name+" 已绑定,无需重复绑定!"))
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- R_DeviceNotice.T_Notice_wx2 = R_DeviceNotice.T_Notice_wx2 + person_QRCode.FromUserName + "/重令名|"
|
|
|
- Company.Update_CompanyNotice(R_DeviceNotice, "T_Notice_wx2")
|
|
|
- redisCache_NatsServer.Put(person_QRCode.FromUserName, decryptCode_int, 5*time.Minute)
|
|
|
- _ = lib.Nats.Publish(m.Reply, []byte(R_DeviceNotice.T_name+" 扫码成功!请在 5分钟内 回复您的名字,否则将 无法收到报警消息!如回复:张三"))
|
|
|
- return
|
|
|
- }
|
|
|
- _ = lib.Nats.Publish(m.Reply, []byte(""))
|
|
|
- })
|
|
|
-
|
|
|
- // 请求-响应, 响应 test3 消息。
|
|
|
- _, _ = lib.Nats.Subscribe("Wx2_BasicMessage_Text", func(m *nats.Msg) {
|
|
|
- logs.Println(" => Nats Wx2_BasicMessage_Text message: %s\n", string(m.Data))
|
|
|
-
|
|
|
- type Person_Text struct {
|
|
|
- ToUserName string `xml:"ToUserName"` //注意这里有个反引号
|
|
|
- FromUserName string `xml:"FromUserName"` //注意这里有个反引号
|
|
|
- CreateTime string `xml:"CreateTime"` //注意这里有个反引号
|
|
|
- MsgType string `xml:"MsgType"`
|
|
|
- Content string `xml:"Content"`
|
|
|
- }
|
|
|
-
|
|
|
- var person_Text Person_Text
|
|
|
- err1 := xml.Unmarshal(m.Data, &person_Text)
|
|
|
- if err1 != nil {
|
|
|
- fmt.Println("Unmarshal error")
|
|
|
- _ = lib.Nats.Publish(m.Reply, []byte(""))
|
|
|
- return
|
|
|
- }
|
|
|
- // 进入 二维码配对
|
|
|
- fmt.Println("FromUserName-", person_Text.FromUserName)
|
|
|
- fmt.Println("Content-", person_Text.Content)
|
|
|
-
|
|
|
- if len(person_Text.Content) > 8*3 || len(person_Text.Content) <= 1*3 {
|
|
|
- _ = lib.Nats.Publish(m.Reply, []byte("请正确输入您的名字!"))
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if !redisCache_NatsServer.IsExist(person_Text.FromUserName) {
|
|
|
- return
|
|
|
- }
|
|
|
- Class_ById := lib.To_int(redisCache_NatsServer.Get(person_Text.FromUserName))
|
|
|
- R_DeviceNotice, err := Company.Read_CompanyNotice_ById(Class_ById)
|
|
|
- if err != nil {
|
|
|
- _ = lib.Nats.Publish(m.Reply, []byte(""))
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- R_DeviceNotice.T_Notice_wx2 = strings.Replace(R_DeviceNotice.T_Notice_wx2,
|
|
|
- person_Text.FromUserName+"/重令名|",
|
|
|
- person_Text.FromUserName+"/"+person_Text.Content+"|",
|
|
|
- -1)
|
|
|
- Company.Update_CompanyNotice(R_DeviceNotice, "T_Notice_wx2")
|
|
|
-
|
|
|
- // 删除 缓存
|
|
|
- redisCache_NatsServer.Delete(person_Text.FromUserName)
|
|
|
-
|
|
|
- _ = lib.Nats.Publish(m.Reply, []byte("尊敬的 "+person_Text.Content+",您以成功绑定 "+R_DeviceNotice.T_name))
|
|
|
- })
|
|
|
-
|
|
|
- //// 发布-订阅 模式,异步订阅 test1
|
|
|
- //_, _ = Nats.Subscribe("test1", func(m *nats.Msg) {
|
|
|
- // fmt.Printf("Received a message: %s\n", string(m.Data))
|
|
|
- //})
|
|
|
-
|
|
|
- //// 队列 模式,订阅 test2, 队列为queue, test2 发向所有队列,同一队列只有一个能收到消息
|
|
|
- //_, _ = Nats.QueueSubscribe("test2", "queue", func(msg *nats.Msg) {
|
|
|
- // fmt.Printf("Queue a message: %s\n", string(msg.Data))
|
|
|
- //})
|
|
|
-
|
|
|
- //// 请求-响应, 响应 test3 消息。
|
|
|
- //_, _ = Nats.Subscribe("test3", func(m *nats.Msg) {
|
|
|
- // fmt.Printf("Reply a message: %s\n", string(m.Data))
|
|
|
- // _ = Nats.Publish(m.Reply, []byte("I can help!!"))
|
|
|
- //})
|
|
|
-
|
|
|
// 请求-响应 验证登录
|
|
|
_, _ = lib.Nats.Subscribe("Cold_User_verification", func(m *nats.Msg) {
|
|
|
fmt.Printf("Cold_User_verification message: %s\n", string(m.Data))
|