示例#1
0
 private void btnMoney_Click(object sender, EventArgs es)
 {
     try
     {
         TmcClient client = new TmcClient(appkey, secret, "default");
         client.OnMessage += (s, e) =>
         {
             try
             {
                 Console.WriteLine(e.Message.Content);
                 Console.WriteLine(e.Message.Topic);
                 // 默认不抛出异常则认为消息处理成功
             }
             catch (Exception exp)
             {
                 Console.WriteLine(exp.StackTrace);
                 e.Fail(); // 消息处理失败回滚,服务端需要重发
             }
         };
         client.Connect("ws://mc.api.taobao.com/");
     }
     catch (Exception ex)
     {
     }
 }
示例#2
0
 /// <summary>
 /// 连接消息服务
 /// </summary>
 /// <param name="handlerOnMessage"></param>
 public void TmcStartListen()
 {
     this.tmcClient            = new TmcClient(AppKey, AppSecret, "sunshine");
     this.tmcClient.OnMessage += (sender, e) =>
     {
         SignalRServer.Instance.PushMessage(e.Message);
     };
     this.tmcClient.Connect(url_TMCserveraddress);
     this.TmcListening = true;
 }
        public void main()
        {
            int i = 0;
            var c = new TmcClient("445663", "c4ab31cce352aa5df07caf842bb9f48c");

            c.OnMessage += (o, e) =>
            {
                if (Interlocked.Increment(ref i) % 1000 == 0)
                {
                    Console.WriteLine(DateTime.Now + " 1000 message received");
                }
            };
            c.Connect("ws://10.235.174.30:8000/");

            Thread.Sleep(1000 * 60 * 100);
        }
示例#4
0
            private static void AddListen()
            {
                TmcClient client = new TmcClient(XDHelper.Common.AppConfig.Appkey, XDHelper.Common.AppConfig.AppSecret, "default");

                //沙箱测试消息服务: TmcClient tmcClient=new TmcClient(ws://mc.api.tbsandbox.com/, 沙箱appkey, 沙箱secret, "groupName");
                client.OnMessage += (s, e) =>
                {
                    try
                    {
                        Console.WriteLine(e.Message.Content);
                        Console.WriteLine(e.Message.Topic);
                        // 默认不抛出异常则认为消息处理成功
                    }
                    catch (Exception exp)
                    {
                        Console.WriteLine(exp.StackTrace);
                        e.Fail(); // 消息处理失败回滚,服务端需要重发
                    }
                };
                client.Connect("ws://mc.api.taobao.com/");
            }
示例#5
0
        public void clientCallBack()
        {
            string    app_key    = ConfigUtil.App_key;
            string    app_secret = ConfigUtil.App_secret;
            TmcClient tmcClient  = new TmcClient(app_key, app_secret, "default");

            LogUtil.WriteInfo(this, "clientCallBack : 消息监听中", "appkey:" + app_key + " ;appsecret : " + app_secret);
            tmcClient.OnMessage += delegate(object s, MessageArgs e)
            {
                try
                {
                    DbOperation dbOperation = new DbOperation(ConfigUtil.ConnectionString);
                    LogUtil.WriteInfo(this, "e.Message.Topic:", e.Message.Topic);
                    LogUtil.WriteInfo(this, "e.Message.Content:", e.Message.Content);
                    //消息通知-商品基础消息创建  "taobao_ifashion_ItemInfoCreate"
                    if (e.Message.Topic == "taobao_ifashion_ItemInfoCreate")
                    {
                        try
                        {
                            QT_GoodsInfo qT_GoodsInfo = JsonParser.FromJson <QT_GoodsInfo>(e.Message.Content);
                            string       text         = string.Format(@"if not exists (select 1 from storesku_mid WITH(NOLOCK)
                                where store_id='{0}' and item_id='{1}' and sku_id='{2}' )
								begin
								insert into storesku_mid(store_id,item_id,sku_id) values('{0}','{1}','{2}') 
								end"                                , qT_GoodsInfo.store_id, qT_GoodsInfo.item_id, qT_GoodsInfo.sku_id
                                                                      );
                            dbOperation.ExecuteNonQuery(text);
                        }
                        catch (Exception ex)
                        {
                            LogUtil.WriteError(this, "e.Message.Topic: taobao_ifashion_ItemInfoCreate ", "入参数据传入错误,请检查数据是否正确." + ex.Message);
                        }
                    }
                    //消息通知-库存变更 "taobao_ifashion_ItemAmountChanged"
                    //{"amount":2,"item_id":604769130652,"msg_id":"300101a2c3f8445dade85057db0a31fc","current_amount":2,"store_id":947,"sku_id":4407918687796,"order_id":1064001,"type":"qt-stock-in"}
                    else if (e.Message.Topic == "taobao_ifashion_ItemAmountChanged")
                    {
                        try
                        {
                            lock (TmcClientInstance.lockobject)
                            {
                                QT_GoodsInfo qT_GoodsInfo = JsonParser.FromJson <QT_GoodsInfo>(e.Message.Content);

                                string text = string.Format(@"if not exists (select 1 from ItemAmountChanged WITH(NOLOCK)
                                where item_id='{0}' and store_id='{4}' and sku_id='{5}' and order_id='{6}')
								begin
								 insert into ItemAmountChanged(amount,current_amount,item_id,store_id,sku_id,order_id,order_type) 
                                 values('{1}','{2}','{3}','{4}','{5}','{6}','{7}') 
								end"                                , qT_GoodsInfo.item_id, qT_GoodsInfo.amount, qT_GoodsInfo.current_amount, qT_GoodsInfo.item_id, qT_GoodsInfo.store_id,
                                                            qT_GoodsInfo.sku_id, qT_GoodsInfo.order_id, qT_GoodsInfo.type
                                                            );
                                dbOperation.ExecuteNonQuery(text);
                            }
                        }
                        catch (Exception ex)
                        {
                            LogUtil.WriteError(this, "e.Message.Topic: taobao_ifashion_ItemAmountChanged ", "入参数据传入错误,请检查数据是否正确." + ex.Message);
                        }
                    }
                    //消息通知-创建单据 "taobao_ifashion_OrderCreate"
                    else if (e.Message.Topic == "taobao_ifashion_OrderCreate")
                    {
                        try
                        {
                            lock (TmcClientInstance.lockobject)
                            {
                                QT_GoodsInfo qT_GoodsInfo2 = JsonParser.FromJson <QT_GoodsInfo>(e.Message.Content);
                                string       text          = string.Format(@"if not exists (select 1 from
                                        OrderCreate WITH(NOLOCK) where storeId='{0}' and orderId='{1}' )  
										begin
											insert into OrderCreate(storeId,orderId,orderType) values('{0}','{1}','{2}')
                                        end", qT_GoodsInfo2.store_id, qT_GoodsInfo2.order_id, qT_GoodsInfo2.type
                                                                           );
                                dbOperation.ExecuteNonQuery(text);
                            }
                        }
                        catch (Exception ex)
                        {
                            LogUtil.WriteError(this, "e.Message.Topic: taobao_ifashion_OrderCreate ", "入参数据传入错误,请检查数据是否正确." + ex.Message + " \n e.Message.Content :  " + e.Message.Content);
                        }
                    }
                }
                catch (Exception ex2)
                {
                    LogUtil.WriteError(this, "获取消息失败:message:" + ex2.Message);
                    Console.WriteLine(ex2.StackTrace);
                    e.Fail();
                }
            };
            tmcClient.Connect("ws://mc.api.taobao.com/");
            Thread.Sleep(2000);
        }
示例#6
0
        public static void Main(string[] args)
        {
            TmcClient client = new TmcClient(appKey, appSecret, "default");

            client.OnMessage += (s, e) =>
            {
                try
                {
                    string status = e.Message.Topic;
                    //将消息进行转换
                    IDictionary obj = TopUtils.ParseJson(e.Message.Content);

                    if (obj != null)
                    {
                        #region //物流信息的处理20160916 yao
                        try
                        {
                            if (obj.Contains("action"))
                            {
                                Console.WriteLine(DateTime.Now.ToString() + ":物流提醒:" + e.Message.Content);
                                LogsticDetailTrace logstic = new LogsticDetailTrace();

                                logstic.Tid  = obj["tid"].ToString();
                                logstic.Desc = obj["desc"].ToString();
                                if (obj.Contains("out_sid"))
                                {
                                    logstic.Out_side = obj["out_sid"].ToString();
                                }
                                logstic.Time = obj["time"].ToString();
                                if (obj.Contains("company_name"))
                                {
                                    logstic.Company_name = obj["company_name"].ToString();
                                }
                                logstic.Action = obj["action"].ToString();
                                if (LogisticsBLL.TidIsExist(logstic.Tid))
                                {
                                    LogisticsBLL.updateLogistics(logstic);
                                }
                                else
                                {
                                    LogisticsBLL.AddLogistics(logstic);
                                }
                            }
                            else
                            {
                                NotifyTrade trade = null;
                                Console.WriteLine(DateTime.Now.ToString() + ":店铺管家订单:" + e.Message.Content);
                                trade            = new NotifyTrade();
                                trade.Tid        = obj["tid"].ToString();
                                trade.BuyerNick  = obj["buyer_nick"].ToString();
                                trade.Status     = status;
                                trade.SellerNick = obj["seller_nick"].ToString();
                                trade.Oid        = obj["oid"].ToString();
                                trade.Payment    = obj["payment"].ToString();
                                if (!DBUtil.CheckNoteTradeIsExit(trade.Tid.ToString()))
                                {
                                    DBUtil.AddNoteTradeToDB(trade);                //物流提醒之用
                                    if (status.Equals("taobao_trade_TradeCreate")) //订单拦截之用
                                    {
                                        DBUtil.AddTradeOrderDenfense(trade);
                                    }
                                }
                                else
                                {
                                    DBUtil.UpdateNoteTradeToDB(trade);
                                }
                            }
                        }
                        catch (Exception e1)
                        {
                            Console.WriteLine(e1.ToString());
                        }
                        #endregion
                    }
                    // 默认不抛出异常则认为消息处理成功
                }
                catch (Exception exp)
                {
                    ExceptionReporter.WriteLog(exp, ExceptionPostion.TBApply_Data);
                    e.Fail(); // 消息处理失败回滚,服务端需要重发
                }
            };
            client.Connect("ws://mc.api.taobao.com/");
            Console.ReadLine();
        }