Example #1
0
        internal void Test()
        {
            var s = new MvcSocket(IP, Port);

            var data = Build(new ASObject());

            s.Send(data);
            var result = s.Receive();

            s.Dispose();
        }
Example #2
0
        /// <summary>
        /// 充值
        /// </summary>
        internal Int32 Recharge(Int64 user_id, Int32 amount)
        {
            var s = new MvcSocket(IP, Port);

            var str = string.Format("{0}|{1}", user_id, amount);
            var dic = new Dictionary <string, object>()
            {
                { "key", "" },
                { "data", CryptoHelper.Encrypt(str, "") },
            };

            XTrace.WriteLine("充值:{0}", str);
            var data = Build(new ASObject(dic));

            s.Send(data);
            var result = s.Receive();

            s.Dispose();
            //解析返回结果
            var len = result.Length - 8;
            var da  = new byte[len];

            Array.Copy(result, 8, da, 0, len);

            var bytea  = new ByteArray(da);
            var dy     = bytea.ReadObject();
            var retype = dy.GetType().Name;
            //XTrace.WriteLine("retype:{0}", retype);
            ASObject obj;

            switch (retype)  //判断接收数据类型
            {
            case "ASObject": { obj = (ASObject)dy; break; }

            case "ProtocolVo": { obj = AMFConvert.ToASObject(dy); break; }

            default: { return((int)ApiType.FAIL); }
            }
            var pv = AutoParseAsObject <ProtocolVo> .Parse(obj);

            //XTrace.WriteLine("pv.className:{0}", pv.className);
            if (pv.className != "ProtocolVo")
            {
                return((int)ApiType.FAIL);
            }
            var r = pv.data;

            // 解析返回结果数据
            var _state = Convert.ToInt32(r.FirstOrDefault(q => q.Key == "state").Value);

            return(_state);
        }
Example #3
0
        /// <summary>
        /// 停止公告
        /// </summary>
        internal Int32 StopNotice(Int64 nid)
        {
#if DEBUG
            IP   = "192.168.1.111";
            Port = 10086;
#endif
            var s   = new MvcSocket(IP, Port);
            var str = string.Format("{0}", nid);
            var dic = new Dictionary <string, object>()
            {
                { "key", "" },
                { "data", CryptoHelper.Encrypt(str, "") },
            };

            var data = Build(new ASObject(dic));
            s.Send(data);
            var result = s.Receive();
            s.Dispose();
            //解析返回结果
            var len = result.Length - 8;
            var da  = new byte[len];
            Array.Copy(result, 8, da, 0, len);

            var      bytea  = new ByteArray(da);
            var      dy     = bytea.ReadObject();
            var      retype = dy.GetType().Name;
            ASObject obj;
            switch (retype)  //判断接收数据类型
            {
            case "ASObject": { obj = (ASObject)dy; break; }

            case "ProtocolVo": { obj = AMFConvert.ToASObject(dy); break; }

            default: { return((int)ApiType.FAIL); }
            }
            var pv = AutoParseAsObject <ProtocolVo> .Parse(obj);

            if (pv.className != "ProtocolVo")
            {
                return((int)ApiType.FAIL);
            }
            var r = pv.data;

            // 解析返回结果数据
            var state = Convert.ToInt32(r.FirstOrDefault(q => q.Key == "state").Value);
            return(state);
        }