zoukankan      html  css  js  c++  java
  • RTX二次开发(二)(基于ASP.NET)

    上一篇,我们讲到我开发环境的配置,还没配置好开发环境或再看一遍开发环境配置?接下来,我们开始coding......

    在coding之前,我们先添加引用。

    我们在SDK的安装目录中引用这个文件。

     引用之后,我们会在bin目录下看到这些dll文件。

    之后,我们在在cs文件中引用

    接下来,我们就可以真正进行coding啦。

    先初始化服务器配置

    int retval;
               //初始化服务器属性
               RTXSAPILib.IRTXSAPIRootObj RootObj;
               RootObj = new RTXSAPIRootObj();
               //创建根对象
               RootObj.ServerIP = "172.0.0.1"
    
               RootObj.ServerPort ="8006"; //设置服务器端口
    

    然后进行相关的代码操作,我写了一部分实现的代码,大家可以根据SDK文档写自己的代码。

      1 using System;
      2 using System.Collections.Generic;
      3 using System.Linq;
      4 using System.Web;
      5 using RTXSAPILib;
      6 using System.Data;
      7 using System.Configuration;
      8 /// <summary>
      9 /// RTXactive 的摘要说明
     10 /// </summary>
     11 public class RTXactive
     12 {
     13     private static string Ip = ConfigurationManager.AppSettings["rtxServerIP"];     //RTX服务器IP地址 127.0.0.1
     14     private static short Iport = Convert.ToInt16(ConfigurationManager.AppSettings["rtxServerAppPort"]);//RTX服务器端口,8006; 
     15     /// <summary>
     16     /// 发送消息提醒(待办事宜)
     17     /// </summary>
     18     /// <param name="receiverAccount">接收者</param>
     19     /// <param name="title">标题</param>
     20     /// <param name="holdtime">停留时间 0为等待用户关闭,以毫秒计</param>
     21     /// <param name="content">发送内容,自动识别链接</param>
     22     /// <returns></returns>
     23     public static int SendNotify(string receiverAccount, string title, string holdtime, string content)
     24     {
     25         int retval;
     26         //初始化服务器属性
     27         RTXSAPILib.IRTXSAPIRootObj RootObj;
     28         RootObj = new RTXSAPIRootObj();
     29         //创建根对象
     30         RootObj.ServerIP = Ip;
     31         RootObj.ServerPort = Iport; //设置服务器端口
     32 
     33         try
     34         {
     35             RootObj.SendNotify(receiverAccount, title, 0, content); //获取版本信息
     36             retval = 1;
     37             return retval;
     38         }
     39         catch (Exception xe)
     40         {
     41             retval = 0;
     42             return retval;
     43         }
     44     }
     45     /// <summary>
     46     /// 发送IM聊天消息
     47     /// </summary>
     48     /// <param name="senderAccount">发送人</param>
     49     /// <param name="password">发送人密码</param>
     50     /// <param name="receiver">接收者,不能超过128人一次</param>
     51     /// <param name="content">发送内容</param>
     52     /// <returns>0为发送出错 1为成功</returns>
     53     public int SendIM(string senderAccount, string password, string receiver, string content)
     54     {
     55         int retval;
     56 
     57         //初始化服务器属性
     58         RTXSAPILib.IRTXSAPIRootObj RootObj;
     59         RootObj = new RTXSAPIRootObj();
     60         //创建根对象
     61         RootObj.ServerIP = Ip;
     62         RootObj.ServerPort = Iport; //设置服务器端口
     63         //获致sessionkey
     64         string sessionKey = GetSessionKey(senderAccount);
     65         try
     66         {
     67             RootObj.SendIM(senderAccount, password, receiver, content, sessionKey);
     68             retval = 1;
     69             return retval;
     70         }
     71         catch (Exception xe)
     72         {
     73             retval = 0;
     74             return retval;
     75         }
     76     }
     77     /// <summary>
     78     /// 获得session
     79     /// </summary>
     80     /// <param name="Account">账号</param>
     81     /// <returns></returns>
     82     public static string GetSessionKey(string Account)  //服务器端代码
     83     {
     84         RTXSAPILib.IRTXSAPIRootObj RootObj;
     85         RootObj = new RTXSAPIRootObj();
     86         //创建根对象
     87         RootObj.ServerIP = Ip;
     88         RootObj.ServerPort = Iport; //设置服务器端口
     89         string SessionKey = "";
     90         RTXSAPILib.RTXSAPIUserAuthObj UserAuthObj = RootObj.UserAuthObj; //创建一个用户认证对象
     91         try
     92         {
     93             SessionKey = "{" + UserAuthObj.GetSessionKey(Account) + "}";  //通过用户认证对象获取SessionKey
     94         }
     95         catch (Exception ex)
     96         {
     97             return ex.Message.ToString();
     98         }
     99         return SessionKey; //返回SessionKey
    100     }
    101     /// <summary>
    102     /// 添加用户
    103     /// </summary>
    104     /// <param name="bstrUserName">用户名</param>
    105     /// <param name="lAuthType">用户类型</param>
    106     /// <returns></returns>
    107     public static int AddUser(string bstrUserName, int lAuthType)
    108     {
    109         RTXSAPILib.IRTXSAPIRootObj RootObj;
    110         RootObj = new RTXSAPIRootObj();
    111         //创建根对象
    112         RootObj.ServerIP = Ip;
    113         RootObj.ServerPort = Iport; //设置服务器端口
    114         try
    115         {
    116             RootObj.UserManager.AddUser(bstrUserName, lAuthType);
    117             return 0;
    118         }
    119         catch (Exception ex)
    120         {
    121             return 1;
    122         }
    123     }
    124     /// <summary>
    125     /// 删除用户
    126     /// </summary>
    127     /// <param name="userAccount">用户账号</param>
    128     /// <returns></returns>
    129     public static bool DeleteUserAccount(string userAccount)
    130     {
    131         RTXSAPILib.IRTXSAPIRootObj RootObj;
    132         RootObj = new RTXSAPIRootObj();
    133         //创建根对象
    134         RootObj.ServerIP = Ip;
    135         RootObj.ServerPort = Iport; //设置服务器端口
    136         try
    137         {
    138             RootObj.UserManager.DeleteUser(userAccount);
    139 
    140             return true;
    141         }
    142         catch (Exception xe)
    143         {
    144             return false;
    145 
    146         }
    147     }
    148     /// <summary>
    149     /// 设置用户密码
    150     /// </summary>
    151     /// <param name="bstrUserName">用户名</param>
    152     /// <param name="bstrPwd">密码</param>
    153     /// <returns></returns>
    154     public static int AddUser(string bstrUserName, string bstrPwd)
    155     {
    156         RTXSAPILib.IRTXSAPIRootObj RootObj;
    157         RootObj = new RTXSAPIRootObj();
    158         //创建根对象
    159         RootObj.ServerIP = Ip;
    160         RootObj.ServerPort = Iport; //设置服务器端口
    161         try
    162         {
    163             RootObj.UserManager.SetUserPwd(bstrUserName, bstrPwd);
    164             return 0;
    165         }
    166         catch (Exception ex)
    167         {
    168             return 1;
    169         }
    170     }
    171     /// <summary>
    172     /// 检查是否存在用户
    173     /// </summary>
    174     /// <param name="userAccount">用户账号</param>
    175     /// <returns></returns>
    176     public static bool IfExist(string userAccount)
    177     {
    178         int retval;
    179         RTXSAPILib.IRTXSAPIRootObj RootObj;
    180         RootObj = new RTXSAPIRootObj();
    181         //创建根对象
    182         RootObj.ServerIP = Ip;
    183         RootObj.ServerPort = Iport; //设置服务器端口
    184         try
    185         {
    186             return RootObj.UserManager.IsUserExist(userAccount);
    187         }
    188         catch (Exception ex)
    189         {
    190             return false;
    191         }
    192     }
    193 
    194     /// <summary>
    195     /// 检查用户在线状态
    196     /// </summary>
    197     /// <param name="userAccount">用户账号</param>
    198     /// <returns></returns>
    199     public static string QueryUserState(string userAccount)
    200     {
    201         RTXSAPILib.IRTXSAPIRootObj RootObj;
    202         RootObj = new RTXSAPIRootObj();
    203         //创建根对象
    204         RootObj.ServerIP = Ip;
    205         RootObj.ServerPort = Iport; //设置服务器端口
    206         try
    207         {
    208             return RootObj.QueryUserState(userAccount);
    209 
    210         }
    211         catch (Exception ex)
    212         {
    213             return "Error";
    214         }
    215     }
    216     /// <summary>
    217     /// 用户名转换为RTX帐号
    218     /// </summary>
    219     /// <param name="bstrUserName"></param>
    220     /// <returns></returns>
    221     public int UserNameToUin(String bstrUserName)
    222     {
    223         RTXSAPILib.IRTXSAPIRootObj RootObj;
    224         RootObj = new RTXSAPIRootObj();
    225         //创建根对象
    226         RootObj.ServerIP = Ip;
    227         RootObj.ServerPort = Iport;
    228         try
    229         {
    230             return RootObj.UserManager.UserNameToUin(bstrUserName);
    231 
    232         }
    233         catch (Exception e)
    234         {
    235             return 1;
    236         }
    237     }
    238     /// <summary>
    239     /// RTX帐号转换为用户名
    240     /// </summary>
    241     /// <param name="lUin"></param>
    242     /// <returns></returns>
    243     public string UinToUserName(int lUin)
    244     {
    245         RTXSAPILib.IRTXSAPIRootObj RootObj;
    246         RootObj = new RTXSAPIRootObj();
    247         //创建根对象
    248         RootObj.ServerIP = Ip;
    249         RootObj.ServerPort = Iport;
    250         try
    251         {
    252             return RootObj.UserManager.UinToUserName(lUin);
    253 
    254         }
    255         catch (Exception e)
    256         {
    257             return "noUin";
    258         }
    259     }
    260     /// <summary>
    261     /// //添加部门
    262     /// </summary>
    263     /// <param name="DeptName">部门名</param>
    264     /// <param name="ParentDeptId">父部门ID</param>
    265     /// <returns></returns>
    266     public int addDept(String DeptName, String ParentDeptId)
    267     {
    268         RTXSAPILib.IRTXSAPIRootObj RootObj;
    269         RootObj = new RTXSAPIRootObj();
    270         //创建根对象
    271         RootObj.ServerIP = Ip;
    272         RootObj.ServerPort = Iport; //设置服务器端口
    273         try
    274         {
    275             RootObj.DeptManager.AddDept(DeptName, ParentDeptId);
    276             return 0;
    277         }
    278         catch (Exception ex)
    279         {
    280             return 1;
    281         }
    282     }
    283     /// <summary>
    284     /// 删除部门
    285     /// </summary>
    286     /// <param name="DeptName">部门名</param>
    287     /// <param name="ifDelectChild">是否删除子部门</param>
    288     /// <returns></returns>
    289     public int deleteDept(String DeptName, bool ifDelectChild)
    290     {
    291         RTXSAPILib.IRTXSAPIRootObj RootObj;
    292         RootObj = new RTXSAPIRootObj();
    293         //创建根对象
    294         RootObj.ServerIP = Ip;
    295         RootObj.ServerPort = Iport; //设置服务器端口
    296         try
    297         {
    298             RootObj.DeptManager.DelDept(DeptName, ifDelectChild);
    299             return 0;
    300         }
    301         catch (Exception ex)
    302         {
    303             return 1;
    304         }
    305     }
    306     /// <summary>
    307     /// 修改部门名
    308     /// </summary>
    309     /// <param name="DeptName">旧部门名</param>
    310     /// <param name="newDeptName">新部门名</param>
    311     /// <returns></returns>
    312     public int setDept(String DeptName, string newDeptName)
    313     {
    314         RTXSAPILib.IRTXSAPIRootObj RootObj;
    315         RootObj = new RTXSAPIRootObj();
    316         //创建根对象
    317         RootObj.ServerIP = Ip;
    318         RootObj.ServerPort = Iport; //设置服务器端口
    319         try
    320         {
    321             RootObj.DeptManager.SetDeptName(DeptName, newDeptName);
    322             return 0;
    323         }
    324         catch (Exception ex)
    325         {
    326             return 1;
    327         }
    328     }
    329     /// <summary>
    330     /// 查看部门名是否存在
    331     /// </summary>
    332     /// <param name="DeptName">部门名</param>
    333     /// <returns></returns>
    334     public int deptIsExist(String DeptName)
    335     {
    336         RTXSAPILib.IRTXSAPIRootObj RootObj;
    337         RootObj = new RTXSAPIRootObj();
    338         //创建根对象
    339         RootObj.ServerIP = Ip;
    340         RootObj.ServerPort = Iport; //设置服务器端口
    341         try
    342         {
    343             if (RootObj.DeptManager.IsDeptExist(DeptName))
    344             {
    345                 return 0;
    346             }
    347             else
    348             {
    349                 return 1;
    350             }
    351 
    352         }
    353         catch (Exception ex)
    354         {
    355             return 1;
    356         }
    357     }
    358     /// <summary>
    359     /// 获取部门下的所有用户
    360     /// </summary>
    361     /// <param name="bstrDeptName">部门名</param>
    362     /// <returns></returns>
    363     public String getDeptUsers(String bstrDeptName)
    364     {
    365         RTXSAPILib.IRTXSAPIRootObj RootObj;
    366         RootObj = new RTXSAPIRootObj();
    367         string DeptUsers = "";
    368         //创建根对象
    369         RootObj.ServerIP = Ip;
    370         RootObj.ServerPort = Iport; //设置服务器端口
    371         try
    372         {
    373             DeptUsers = RootObj.DeptManager.GetDeptUsers(bstrDeptName);
    374             return DeptUsers;
    375         }
    376         catch (Exception ex)
    377         {
    378             return "noUser";
    379         }
    380     }
    381     /// <summary>
    382     /// 将用户添加到部门下
    383     /// </summary>
    384     /// <param name="bstrUserName">用户名</param>
    385     /// <param name="bstrSrcDeptName"></param>
    386     /// <param name="bstrDestDeptName"></param>
    387     /// <param name="bIsCopy"></param>
    388     public void AddUserToDept(String bstrUserName, string bstrSrcDeptName, string bstrDestDeptName, bool bIsCopy)
    389     {
    390         RTXSAPILib.IRTXSAPIRootObj RootObj;
    391         RootObj = new RTXSAPIRootObj();
    392         //创建根对象
    393         RootObj.ServerIP = Ip;
    394         RootObj.ServerPort = Iport; //设置服务器端口
    395         try
    396         {
    397             RootObj.DeptManager.AddUserToDept(bstrUserName,bstrSrcDeptName,bstrDestDeptName,bIsCopy);
    398         }
    399         catch (Exception ex)
    400         {
    401 
    402         }
    403     }
    404     /// <summary>
    405     /// 设置用户信息
    406     /// </summary>
    407     /// <param name="bstrUserName">用户id</param>
    408     /// <param name="bstrName">姓名</param>
    409     /// <param name="lGender">性别</param>
    410     /// <param name="bstrMobile">电话</param>
    411     /// <param name="bstrEMail">邮箱</param>
    412     /// <param name="bstrPhone">手机</param>
    413     /// <param name="lAuthType">权值</param>
    414     public void SetUserBasicInfo(String bstrUserName, string bstrName, int lGender, string bstrMobile, string bstrEMail, string bstrPhone, int lAuthType)
    415     {
    416         RTXSAPILib.IRTXSAPIRootObj RootObj;
    417         RootObj = new RTXSAPIRootObj();
    418         //创建根对象
    419         RootObj.ServerIP = Ip;
    420         RootObj.ServerPort = Iport; //设置服务器端口
    421         try
    422         {
    423             RootObj.UserManager.SetUserBasicInfo(bstrUserName, bstrName, lGender, bstrMobile, bstrEMail, bstrPhone, lAuthType);
    424         }
    425         catch (Exception ex)
    426         {
    427 
    428         }
    429     }
    430     /// <summary>
    431     /// 将用户从部门中删除
    432     /// </summary>
    433     /// <param name="bstrUserName">用户名</param>
    434     /// <param name="bstrDestDeptName">部门名</param>
    435     public void DelUserFromDept(String bstrUserName, string bstrDestDeptName)
    436     {
    437         RTXSAPILib.IRTXSAPIRootObj RootObj;
    438         RootObj = new RTXSAPIRootObj();
    439         //创建根对象
    440         RootObj.ServerIP = Ip;
    441         RootObj.ServerPort = Iport; //设置服务器端口
    442         try
    443         {
    444             RootObj.DeptManager.DelUserFromDept(bstrUserName, bstrDestDeptName);
    445         }
    446         catch (Exception ex)
    447         {
    448 
    449         }
    450     }
    451 }

    RTX基本操作(发送待办事宜、发送消息,增删改查用户、部门)的代码就在这啦,后面咱将还有两篇,一个是RTX单点登录,一个是RTX反向单点登录。

    这次还是一样,有问题可以留言哈。

  • 相关阅读:
    2017.10.25总结与回顾
    2017.10.24总结与回顾
    CSS盒子模型
    2017.10.23学习知识总结回顾及编写新网页
    JAVA与mysql之间的编码问题
    想写好代码,送你三个神器
    Vue+highligh.js实现语法高亮(转)
    Vue.JS实现复制到粘帖板功能
    npm install、npm install --save与npm install --save-dev区别(转)
    ES7与ES8新特性
  • 原文地址:https://www.cnblogs.com/wjszxli/p/4216841.html
Copyright © 2011-2022 走看看