예제 #1
0
    private void VerifyAccountWorker(LB_VerifyAccount msg, PBChannel channel)
    {
        try
        {
            int    tag       = CreateTag();
            string signParam = string.Format("{0}{1}{2}{3}{4}{5}", msg.OpCode, msg.Data, m_AppKey, m_AppSecret, tag, msg.ChannelId);
            string sign      = CreateSign(signParam);

            HttpClient client = new HttpClient();
            client.Timeout = m_HttpRequestTimeout;
            HttpPost postMethod = new HttpPost(new Uri(m_TestBillingServerUrl));

            postMethod.Headers.Add("appkey", m_AppKey);
            postMethod.Headers.Add("sign", sign);
            postMethod.Headers.Add("tag", tag.ToString());
            postMethod.Headers.Add("opcode", msg.OpCode.ToString());
            postMethod.Headers.Add("channelId", msg.ChannelId.ToString());

            List <NameValuePair> nameValuePairList = new List <NameValuePair>();
            nameValuePairList.Add(new NameValuePair("data", msg.Data));

            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, Encoding.UTF8);
            postMethod.Entity = formEntity;

            LogSys.Log(LOG_TYPE.INFO, "Account:{0}, HttpPost headers. appkey:{1}, sign:{2}, tag:{3}, opcode:{4}, channelId:{5}",
                       msg.Account, m_AppKey, sign, tag, msg.OpCode, msg.ChannelId);
            LogSys.Log(LOG_TYPE.INFO, "Account:{0}, HttpPost parameters. data:{1}", msg.Account, msg.Data);
            //============================================

            HttpResponse response    = client.Execute(postMethod);
            string       responseStr = EntityUtils.ToString(response.Entity);

            DestroyTag(tag);

            //==================================================
            LogSys.Log(LOG_TYPE.INFO, "Account:{0}, Response:{1}", msg.Account, responseStr);
            //==================================================

            JsonVerifyAccountResult result = JsonConvert.DeserializeObject(responseStr, typeof(JsonVerifyAccountResult)) as JsonVerifyAccountResult;
            var reply = BL_VerifyAccountResult.CreateBuilder();
            reply.Account   = msg.Account;
            reply.OpCode    = result.opcode;
            reply.ChannelId = result.channelId;
            reply.AccountId = "";
            reply.Result    = false;
            int repState = result.state;
            if (repState == (int)BillingRepState.Success && result.data != null)
            {
                int status = int.Parse(result.data.status);
                if (status == 1 && result.channelId == msg.ChannelId && result.opcode == msg.OpCode)
                {
                    reply.AccountId = result.data.userid;
                    reply.Result    = true;
                }
            }
            if (reply.Result == true)
            {
                LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "Account verify success. Account:{0} ID:{1}", reply.Account, reply.AccountId);
            }
            else
            {
                LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Yellow, "Account verify failed. Account:{0} Msg:{1}", reply.Account, result.error);
            }
            channel.Send(reply.Build());
        }
        catch (Exception ex)
        {
            LogSys.Log(LOG_TYPE.ERROR, ConsoleColor.Red, "Exception Type:{0}", ex.GetType().ToString());
            LogSys.Log(LOG_TYPE.ERROR, ConsoleColor.Red, "Exception:{0}\n{1}", ex.Message, ex.StackTrace);
        }
    }
예제 #2
0
    private void VerifyAccountWorkerWithHttpRequest(LB_VerifyAccount msg, PBChannel channel)
    {
        HttpWebRequest  myHttpWebRequest  = null;
        HttpWebResponse myHttpWebResponse = null;

        try
        {
            int    tag       = CreateTag();
            string signParam = string.Format("{0}{1}{2}{3}{4}{5}", msg.OpCode, msg.Data, m_AppKey, m_AppSecret, tag, msg.ChannelId);
            string sign      = CreateSign(signParam);
            IDictionary <string, string> headers = new Dictionary <string, string>();
            headers.Add("appkey", m_AppKey);
            headers.Add("sign", sign);
            headers.Add("tag", tag.ToString());
            headers.Add("opcode", msg.OpCode.ToString());
            headers.Add("channelId", msg.ChannelId.ToString());
            IDictionary <string, string> parameters = new Dictionary <string, string>();
            parameters.Add("data", msg.Data);
            LogSys.Log(LOG_TYPE.INFO, "Account:{0}, HttpPost headers. appkey:{1}, sign:{2}, tag:{3}, opcode:{4}, channelId:{5}",
                       msg.Account, m_AppKey, sign, tag, msg.OpCode, msg.ChannelId);
            LogSys.Log(LOG_TYPE.INFO, "Account:{0}, HttpPost parameters. data:{1}", msg.Account, msg.Data);
            //============================================
            myHttpWebRequest  = HttpWebUtility.CreatePostHttpRequest(m_TestBillingServerUrl, headers, parameters, m_HttpRequestTimeout);
            myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
            string responseStr = string.Empty;
            using (Stream streamResponse = myHttpWebResponse.GetResponseStream())
            {
                using (StreamReader readStream = new StreamReader(streamResponse, Encoding.UTF8))
                {
                    responseStr = readStream.ReadToEnd();
                    readStream.Close();
                }
                streamResponse.Flush();
                streamResponse.Close();
            }
            DestroyTag(tag);
            //==================================================
            LogSys.Log(LOG_TYPE.INFO, "Account:{0}, Response:{1}", msg.Account, responseStr);
            //==================================================
            JsonVerifyAccountResult result = JsonConvert.DeserializeObject(responseStr, typeof(JsonVerifyAccountResult)) as JsonVerifyAccountResult;
            var reply = BL_VerifyAccountResult.CreateBuilder();
            reply.Account   = msg.Account;
            reply.OpCode    = result.opcode;
            reply.ChannelId = result.channelId;
            reply.AccountId = "";
            reply.Result    = false;
            int repState = result.state;
            if (repState == (int)BillingRepState.Success && result.data != null)
            {
                int status = int.Parse(result.data.status);
                if (status == 1 && result.channelId == msg.ChannelId && result.opcode == msg.OpCode)
                {
                    reply.AccountId = result.data.userid;
                    reply.Result    = true;
                }
            }
            if (reply.Result == true)
            {
                LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "Account verify success. Account:{0} ID:{1}", reply.Account, reply.AccountId);
            }
            else
            {
                LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Yellow, "Account verify failed. Account:{0} Msg:{1}", reply.Account, result.error);
            }
            channel.Send(reply.Build());
        }
        catch (Exception ex)
        {
            LogSys.Log(LOG_TYPE.ERROR, ConsoleColor.Red, "Exception Type:{0}", ex.GetType().ToString());
            LogSys.Log(LOG_TYPE.ERROR, ConsoleColor.Red, "Exception:{0}\n{1}", ex.Message, ex.StackTrace);
        }
        finally
        {
            if (myHttpWebResponse != null)
            {
                myHttpWebResponse.Close();
            }
            if (myHttpWebRequest != null)
            {
                myHttpWebRequest.Abort();
            }
        }
    }
예제 #3
0
 private void HandleVerifyAccount(LB_VerifyAccount msg, PBChannel channel, int handle, uint seq)
 {
     LogSys.Log(LOG_TYPE.INFO, "request billing to verify account: {0} ", msg.Account);
     //m_TaskDispatcher.DispatchAction(VerifyAccountWorker, msg, channel);
     m_TaskDispatcher.DispatchAction(VerifyAccountWorkerWithHttpRequest, msg, channel);
 }