Пример #1
0
        public IHttpActionResult UserLoginScan(ScanLoginModel model)
        {
            ApiServerMsg result = new ApiServerMsg();

            try
            {
                //new空对象
                MySocket        socket    = new MySocket();
                XzyWeChatThread xzy       = new XzyWeChatThread(socket, model.devicename);
                DicSocket       dicSocket = new DicSocket()
                {
                    socket       = socket,
                    weChatThread = xzy,
                    dateTime     = DateTime.Now
                };
                XzyWebSocket._dicSockets.Remove(model.uuid);
                XzyWebSocket._dicSockets.Add(model.uuid, dicSocket);
                while (xzy.ScanQrCode == "")
                {
                    Thread.Sleep(200);
                }
                result.Success = true;
                result.Context = xzy.ScanQrCode;
                return(Ok(result));
            }
            catch (Exception ex)
            {
                result.Success    = false;
                result.ErrContext = ex.Message;
                return(Ok(result));
            }
        }
Пример #2
0
 /// <summary>
 /// 初始化socket服务
 /// </summary>
 public static void Init()
 {
     new WebSocketServer("ws://0.0.0.0:" + ConfigurationManager.AppSettings["WebSocketHost"]).Start(delegate(IWebSocketConnection socket)
     {
         socket.OnOpen = delegate
         {
             string baseUrl = "";
             MyUtils.ParseUrl(socket.ConnectionInfo.Path, out baseUrl, out NameValueCollection nvc);
             string a          = nvc["action"];
             string key        = nvc["uuid"];
             string devicename = nvc["devicename"];
             string a2         = nvc["isreset"];
             string proxy      = nvc["proxy"];
             string proxyname  = nvc["proxyname"];
             string proxypwd   = nvc["proxypwd"];
             string text       = nvc["proxytype"];
             if (text == "")
             {
                 text = "1";
             }
             ScanLoginModel model = new ScanLoginModel
             {
                 devicename = devicename,
                 proxy      = proxy,
                 proxyname  = proxyname,
                 proxypwd   = proxypwd,
                 proxytype  = text.ConvertToInt32()
             };
             if (a == "scan")
             {
                 if (_dicSockets.ContainsKey(key) && a2 == "false")
                 {
                     _dicSockets[key].socket = socket;
                     _dicSockets[key].weChatThread._socket         = socket;
                     _dicSockets[key].weChatThread.SocketIsConnect = true;
                 }
                 else
                 {
                     XzyWeChatThread xzyWeChatThread = new XzyWeChatThread(socket, model);
                     DicSocket value = new DicSocket
                     {
                         socket       = socket,
                         weChatThread = xzyWeChatThread
                     };
                     _dicSockets.Remove(key);
                     _dicSockets.Add(key, value);
                     xzyWeChatThread.SocketIsConnect = true;
                 }
             }
             else if (a == "62")
             {
                 string username       = nvc["username"];
                 string password       = nvc["password"];
                 string str            = nvc["str62"];
                 string proxy2         = nvc["proxy"];
                 string proxyname2     = nvc["proxyname"];
                 string proxypwd2      = nvc["proxypwd"];
                 string s              = nvc["proxytype"];
                 UserLoginModel model2 = new UserLoginModel
                 {
                     username  = username,
                     password  = password,
                     str62     = str,
                     proxy     = proxy2,
                     proxyname = proxyname2,
                     proxypwd  = proxypwd2,
                     proxytype = s.ConvertToInt32()
                 };
                 if (_dicSockets.ContainsKey(key) && a2 == "false")
                 {
                     _dicSockets[key].socket = socket;
                     _dicSockets[key].weChatThread._socket         = socket;
                     _dicSockets[key].weChatThread.SocketIsConnect = true;
                 }
                 else
                 {
                     XzyWeChatThread xzyWeChatThread2 = new XzyWeChatThread(socket, model2);
                     DicSocket value2 = new DicSocket
                     {
                         socket       = socket,
                         weChatThread = xzyWeChatThread2
                     };
                     _dicSockets.Remove(key);
                     _dicSockets.Add(key, value2);
                     xzyWeChatThread2.SocketIsConnect = true;
                 }
             }
         };
         socket.OnClose = delegate
         {
             try
             {
                 (from p in _dicSockets
                  where p.Value.socket == socket
                  select p).ToList().FirstOrDefault().Value.weChatThread.SocketIsConnect = false;
             }
             catch (Exception)
             {
             }
         };
         socket.OnMessage = delegate
         {
         };
     });
 }