コード例 #1
0
    protected override void OnRequest(request_login request, object userdata)
    {
        LoginActionParam param = userdata as LoginActionParam;

        if (param == null)
        {
            return;
        }

        string md5_value = MD5Utils.Encrypt(param.Passwd);

        request.clientversion = param.ClientVer;
        request.tencentlogin  = param.TencentLogin;

        request.usrname = param.UserName;
        request.passwd  = HMACUtils.HMacSha1Encrypt(md5_value, Net.Instance.GetSessionKey());

        request.openId       = param.OpenId;
        request.platform     = param.Platform;
        request.accesstoken  = param.AccessToken;
        request.paytoken     = param.PayToken;
        request.pf           = param.Pf;
        request.pfkey        = param.PfKey;
        request.regchannel   = param.RegChannel;
        request.setupchannel = param.SetupChannel;
        request.clientsystem = param.ClientSystem;
        request.txplat       = param.TXPlat;
    }
コード例 #2
0
ファイル: Net.cs プロジェクト: fengmin0722/qiangzhan
    private bool ParseData(byte[] data, ref uint sessionId, ref uint actionId, out byte [] msgBody)
    {
        msgBody = null;

        if (data.Length < 4 + 4 + 4 + 40 + 4)
        {
            return(false);
        }

        MemoryStream stream = new MemoryStream(data);

        byte [] hmacvalue = new byte[40];

        byte [] buff4 = new byte[4];

        stream.Read(buff4, 0, 4);
        if (BitConverter.ToUInt32(buff4, 0) != respond_msg_type_common)
        {
            return(false);
        }

        stream.Read(buff4, 0, 4);
        sessionId = BitConverter.ToUInt32(buff4, 0);

        stream.Read(buff4, 0, 4);
        actionId = BitConverter.ToUInt32(buff4, 0);

        stream.Read(hmacvalue, 0, 40);

        stream.Read(buff4, 0, 4);
        uint bodyLength = BitConverter.ToUInt32(buff4, 0);

        msgBody = new byte[bodyLength];

        if (msgBody.Length > 0)
        {
            stream.Read(msgBody, 0, (int)bodyLength);
        }

        if (HMACUtils.HMacSha1Encrypt(msgBody, Encoding.ASCII.GetBytes(mKey)).CompareTo(Encoding.ASCII.GetString(hmacvalue)) != 0)
        {
            return(false);
        }

        return(true);
    }
コード例 #3
0
ファイル: Net.cs プロジェクト: fengmin0722/qiangzhan
    private byte[] CompositeData(uint sessionId, uint actionId, byte [] msgBody)
    {
        string hmac_value = HMACUtils.HMacSha1Encrypt(msgBody, Encoding.ASCII.GetBytes(mKey));

        MemoryStream stream = new MemoryStream();

        byte [] sessiond_stream      = BitConverter.GetBytes(sessionId);
        byte[]  message_stream       = BitConverter.GetBytes(actionId);
        byte[]  msgbodyLength_stream = BitConverter.GetBytes(msgBody.Length);
        byte[]  hmac_stream          = Encoding.ASCII.GetBytes(hmac_value);

        stream.Write(sessiond_stream, 0, sessiond_stream.Length);
        stream.Write(message_stream, 0, message_stream.Length);
        stream.Write(hmac_stream, 0, hmac_stream.Length);
        stream.Write(msgbodyLength_stream, 0, msgbodyLength_stream.Length);
        stream.Write(msgBody, 0, msgBody.Length);

        return(stream.ToArray());
    }