7*24小时应急电话:15927160396
首页 新闻资讯 技术文章
飞信WEB接口的一个返回网页C#处理源码

代码说明:“返回网页”是指飞信接口有事件发生时把事件信息发送到的网页地址,并不是给用户访问,所以处理接受的数据应保存到数据库,以便在别的网页提取出来呈现给用户;这个页面地址应在发送登录时由reurl指定提交给接口服务器的。

详情参见http://io.feirobot.cn/的说明

以下WebDbClass控件是我的自定义数据库控件,请换成实际的数据库连接

        protected WebDbClass MyDb = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (MyDb == null) MyDb = new WebDbClass();
            try
            {
                string com = (string)Request["com"],fno=(string)Request["fno"],mno=(string)Request["mno"];
                if (fno == String.Empty && mno==String.Empty)
                {
                    Response.Write("号码信息错误");
                    MyDb.DbClose();
                    Response.End();
                    return;
                }
                if (com == "rmsg" || com == "senderr")
                {
                    string MsgType = "新接收", rgno = "", tofno = (string)Request["rfno"], tomno = (string)Request["rmno"], msg = (string)Request["msg"], senderr = "";
                    msg = HttpUtility.UrlDecode(msg, Encoding.GetEncoding("utf-8"));
                    if (com == "senderr")
                    {
                        MsgType = "新错误";
                        senderr = (string)Request["senderr"];
                        msg = "发送\"" + msg + "\"" + senderr;
                    }

                    //插入数据库
                    MyDb.ExecuteSql("INSERT INTO FetionUpdata (fno,mno,tofno,tomno,uptype,Msg,addTime)" +
                        "values('" + fno + "','" + mno + "','" + tofno + "','" + tomno + "','" + MsgType + "','" + msg.Replace("'", "''") + "','" + DateTime.Now.ToString() + "')");
                    Response.Write(msg); //输出是为了方便调试,实际没什么意义,正常后请全部注释掉
                }
                else if (com == "sendok")
                {

                     //发送成功
                    ;
                }
                else if (com == "loginok")
                {
                    string fname = (string)Request["fname"];
                    MyDb.ExecuteSql("INSERT INTO FetionUpdata (fno,mno,tofno,tomno,uptype,Msg,addTime)" +
                        "values('" + fno + "','" + mno + "','','','登录成功','" + fname.Replace("'", "''") + "','" + DateTime.Now.ToString() + "')");
                }
                else if (com == "loginerr")
                {
                    MyDb.ExecuteSql("INSERT INTO FetionUpdata (fno,mno,tofno,tomno,uptype,Msg,addTime)" +
                        "values('" + fno + "','" + mno + "','','','登录失败','','" + DateTime.Now.ToString() + "')");
                }
                else if (com == "fadd")
                {
                    string tofno = (string)Request["rfno"], tomno = (string)Request["rmno"], msg = (string)Request["msg"];
                    MyDb.ExecuteSql("INSERT INTO FetionUpdata (fno,mno,tofno,tomno,uptype,Msg,addTime)" +
                        "values('" + fno + "','" + mno + "','" + tofno + "','" + tomno + "','被添加为好友','" + msg.Replace("'", "''") + "','" + DateTime.Now.ToString() + "')");
                }
                else if (com == "list")
                {
                    MyDb.ExecuteSql("INSERT INTO FetionUpdata (fno,mno,tofno,tomno,uptype,Msg,addTime)" +
                        "values('" + fno + "','" + mno + "','','','列表完成','','" + DateTime.Now.ToString() + "')");
                }
                else if (com == "logout")
                {
                    MyDb.ExecuteSql("INSERT INTO FetionUpdata (fno,mno,tofno,tomno,uptype,Msg,addTime)" +
                        "values('" + fno + "','" + mno + "','','','被注销','','" + DateTime.Now.ToString() + "')");
                }
                else if (com == "changed")
                {//好友状态改变
                    string tofno = (string)Request["rfno"], tomno = (string)Request["rmno"], msg = (string)Request["msg"];
                    string[] farrm = msg.Trim().Split('|');
                    if (farrm.Length >= 7)
                        if (farrm[5] == "聊天") //好友打开聊天窗口
                        {
                            msg = msg.Replace("|聊天|", "|在线|");
                        }
                    MyDb.ExecuteSql("INSERT INTO FetionUpdata (fno,mno,tofno,tomno,uptype,Msg,addTime)" +
                        "values('" + fno + "','" + mno + "','" + tofno + "','" + tomno + "','好友状态改变','" + msg.Replace("'", "''") + "','" + DateTime.Now.ToString() + "')");
                }
                else
                    Response.Write("命令参数错误");
            }
            catch(Exception er)
            {
                Response.Write("接收信息错误:"+er.Message);
            }
            MyDb.DbClose();
            Response.End();
        }

飞信WEB接口主要是方便网站开发都使用,如果是Win桌面程序,要想返回信息,只能使用飞信WebService接口

版权所有:武汉网福互联科技有限公司    鄂ICP备09022096号
业务QQ:23444550 客服QQ:267052100 电邮:23444550@qq.com  

鄂公网安备 42010602000905号

手机站二维码