/// <summary>
    /// 建立客户端关系
    /// </summary>
    /// <param name="token">Hash 客户端信息</param>
    /// <param name="fromClientId">int 邀请人客户端编号</param>
    /// <param name="shareQuestionId">int 分享题目编号</param>
    /// <param name="scene">int 来源场景</param>
    /// <param name="encryptedData">string 群标识加密信息</param>
    /// <param name="iv">string 群标识加密向量</param>
    /// <returns>Hash 返回结果</returns>
    public static Hash Relation(Hash token, int fromClientId, int shareQuestionId, int scene, string encryptedData, string iv)
    {
        //  如果邀请人不存在,则跳出
        if (fromClientId == 0)
        {
            return(new Hash((int)CodeType.ClientRelateRequired, "邀请人不存在"));
        }

        //  初始化参数集合
        Hash data        = new Hash();
        Hash shareTicket = new Hash();
        Hash fromClient  = ClientData.GetByClientId(fromClientId);

        //  获取群标识
        if (!Genre.IsNull(encryptedData) && !Genre.IsNull(iv) && !token.IsNull("sessionKey"))
        {
            shareTicket = API.GetEncryptedData(encryptedData, token.ToString("sessionKey"), iv);
        }

        if (shareTicket.IsNull("openGId"))
        {
            //  如果不是来自群会话
            if (token.ToInt("clientId") != fromClientId)
            {
                ClientRelateData.Create(token.ToInt("clientId"), fromClientId, RelateType.FromFriend);
                ClientRelateData.Create(fromClientId, token.ToInt("clientId"), RelateType.FromFriend);
            }
        }
        else
        {
            //  如果来自群会话
            ClientGroupData.Create(token.ToInt("clientId"), shareTicket.ToString("openGId"));
            ClientGroupData.Renovate(shareTicket.ToString("openGId"));
        }

        //  初始化题目
        if (shareQuestionId > 0)
        {
            Hash question = ClientQuestionData.GetByClientIdAndQuestionId(token.ToInt("clientId"), shareQuestionId);
            if (question.ToInt("id") == 0)
            {
                ClientQuestionData.Ready(token.ToInt("clientId"), shareQuestionId);
            }
        }

        //  拼装结果信息
        data["openGId"]    = shareTicket.ToString("openGId");
        data["fromClient"] = fromClient;
        return(new Hash((int)CodeType.OK, "成功", data));
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 获取下一个题目
    /// </summary>
    /// <param name="token">Hash 客户端信息</param>
    /// <returns>Hash 返回结果</returns>
    public static Hash Next(Hash token)
    {
        //  获取下一个题目
        Hash question = ClientQuestionData.Next(token.ToInt("clientId"));
        Hash data     = ClientQuestionData.GetPositionByClientId(token.ToInt("clientId"));

        //  准备开始答题
        if (question.ToInt("questionId") > 0)
        {
            ClientQuestionData.Ready(token.ToInt("clientId"), question.ToInt("questionId"));
            data             = ClientQuestionData.GetPositionByClientId(token.ToInt("clientId"));
            data["question"] = question;
        }

        //  返回结果
        return(new Hash((int)CodeType.OK, "成功", data));
    }