Exemple #1
0
        /// <summary>
        /// 接收到消息请求
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_xmppClient_IqRequestEvents(object sender, S22.Xmpp.Im.IqEventArgs e)
        {
            string innerText = e.IqInfo.Data["dreq"]["cnt"].InnerText;
            string message   = "业务平台未实现,未处理结果";
            int    num       = 1;
            ServiceRequestParam requestParam = null;

            try
            {
                string iqID = "";
                if (e != null && e.IqInfo != null)
                {
                    iqID = e.IqInfo.Id;
                }
                CommonConfig.Logger.WriteInfo("接收到的数据推送,IqID=:" + iqID);
                requestParam = JsonConvert.DeserializeObject <ServiceRequestParam>(XmlHelper.ResumeChar(innerText));
                if (requestParam != null)
                {
                    if (this.m_reqHandler != null && requestParam.serviceId != m_serviceIdForSelf)
                    {
                        if (!this.m_keyAndSource.Contains(e.IqInfo.Id))
                        {
                            this.m_keyAndSource.Add(e.IqInfo.Id, requestParam.source);
                        }
                        this.m_reqHandler.execute(e.Jid.ToString(), requestParam, e.IqInfo.Id, "SYNC");
                        return;
                    }
                    else if (requestParam.serviceId == m_serviceIdForSelf)   //直接返回成功
                    {
                        CommonConfig.Logger.WriteInfo("接收到自发自收心跳");
                        ServiceResponseData responseData = new ServiceResponseData
                        {
                            seqId      = requestParam.seqId,
                            message    = "",
                            resultCode = 0,
                            serviceId  = m_serviceIdForSelf
                        };
                        this.responseService(e.Jid.ToString(), responseData, e.IqInfo.Id, "", true);
                    }
                    else
                    {
                        //直接回复,返回失败,未实现
                        ServiceResponseData responseData = new ServiceResponseData
                        {
                            seqId      = (requestParam != null) ? requestParam.seqId : "0",
                            message    = message,
                            resultCode = num
                        };
                        this.responseService(e.Jid.ToString(), responseData, e.IqInfo.Id, "", true);
                    }
                }
            }
            catch (Exception exception)
            {
                CommonConfig.Logger.WriteError("接收到消息返回给业务系统出错", exception);
                message = exception.Message;
                num     = 0x65;
            }
        }
Exemple #2
0
        private void SendForSelf()
        {
            while (false)   //不启用自发自收,原因:业务已具有自发自收的功能。
            {
                //60分钟检测一次
                Thread.Sleep(60 * 1000);

                CommonConfig.Logger.WriteInfo("开始自发自收");
                string selfJID = m_xmppClient != null?m_xmppClient.Jid.ToString() : "";    // m_stringUserName + "@" + m_stringDomain + "/" + m_stringResource;

                ServiceRequestParam request = new ServiceRequestParam();
                request.serviceId = m_serviceIdForSelf;
                request.source    = DateTime.Now.ToString("HHmmssfff");
                ServiceResponseData response = new ServiceResponseData();
                response.resultCode = 1;

                try
                {
                    int result = syncRequestService(selfJID, request, 1, false, 5000, ref response);
                    if (response.resultCode == 0)
                    {
                        m_sendForSelfErrorTimes = 0;
                    }
                    else
                    {
                        m_sendForSelfErrorTimes++;
                    }
                    CommonConfig.Logger.WriteInfo("完成自发自收,m_sendForSelfErrorTimes=" + m_sendForSelfErrorTimes);
                }
                catch (Exception ex)
                {
                    m_sendForSelfErrorTimes++;
                    CommonConfig.Logger.WriteError("自发自收过程失败", ex);
                }

                try
                {
                    if (m_sendForSelfErrorTimes >= 3)  //连续3次失败
                    {
                        CommonConfig.Logger.WriteInfo("自发自收失败次数超过3次,准备重连");
                        m_sendForSelfErrorTimes = 0;
                        //需要重连
                        SendForSelfStatusConnecting = false;
                    }
                }
                catch (Exception ex1)
                {
                    CommonConfig.Logger.WriteError("自发自收超过3次,关闭连接过程出错", ex1);
                }
            }
        }
Exemple #3
0
        public int syncRequestService(string toUserJID, ServiceRequestParam requestParam, int mode, bool bCrc, int timeout, ref ServiceResponseData responseData)
        {
            string jsonData = JsonConvert.SerializeObject(requestParam);
            int    crc      = 0;
            int    result   = 1;

            if (bCrc)
            {
                crc = this.getDataCrc(jsonData);
            }
            string str2 = "SYNC";

            if (mode == 0)
            {
                str2 = "NOTIFY";
            }
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                if ((mode != 0) && (timeout < 0x1388))
                {
                    timeout = 0x1388;
                }

                responseData            = new ServiceResponseData();
                responseData.resultCode = result;

                if (this.IsXmppOK)
                {
                    Iq iq = this.m_xmppClient.IqRequestJieShun(toUserJID, jsonData, crc, str2, IqType.Get, timeout, requestParam.seqId);
                    stopwatch.Stop();
                    CommonConfig.Logger.WriteInfo("syncRequestService发送完成,耗时:" + stopwatch.ElapsedMilliseconds);
                    string str3 = iq.Data.Attributes["type"].Value;

                    if (str3.ToLower().Equals("error"))
                    {
                        responseData.message = iq.Data.InnerXml;
                        return(result);
                    }
                    XmlElement data = iq.Data;
                    if (data["dres"] != null)
                    {
                        if (data["dres"]["rc"] != null)
                        {
                            int.TryParse(data["dres"]["rc"].InnerText, out result);
                        }
                        if (data["dres"]["cnt"] != null)
                        {
                            responseData = JsonConvert.DeserializeObject <ServiceResponseData>(data["dres"]["cnt"].InnerText);
                        }
                        else
                        {
                            responseData.message = data.InnerXml;
                        }
                    }
                    this.m_sendErrorTimes = 0;
                    return(result);
                }
                responseData.resultCode = 0x194;
                CommonConfig.Logger.WriteInfo("未连接状态,不发送数据");
                WriteConnectingStatusLog();
            }
            catch (Exception exception)
            {
                if (mode != 0)
                {
                    this.m_sendErrorTimes++;
                    CommonConfig.Logger.WriteError("发送数据过程出错。超时时间:" + timeout, exception);
                }
                else
                {
                    CommonConfig.Logger.WriteError("发送数据过程出错", exception);
                }
            }
            return(result);
        }
Exemple #4
0
        public int requestService(string toUserJID, ServiceRequestParam requestParam, int mode, bool bCrc)
        {
            ServiceResponseData responseData = new ServiceResponseData();

            return(this.syncRequestService(toUserJID, requestParam, mode, bCrc, -1, ref responseData));
        }
Exemple #5
0
 public virtual int execute(string fromUser, ServiceRequestParam requestParam, string id, string mode)
 {
     return(1);
 }