Beispiel #1
0
        public CtuResponse CheckRisk(CtuRequest request)
        {
            String sign             = SignUtil.Sign(appSecret, request);
            String reqUrl           = String.Format("{0}?appKey={1}&sign={2}&version={3}", url, appKey, sign, version);
            JavaScriptSerializer js = new JavaScriptSerializer();
            String reqJsonString    = js.Serialize(request);

            byte[]         bytes          = Encoding.UTF8.GetBytes(reqJsonString);
            string         postDataStr    = Convert.ToBase64String(bytes);
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(reqUrl);

            httpWebRequest.Method      = "POST";
            httpWebRequest.ContentType = "text/html";
            httpWebRequest.Timeout     = this.connectTimeout;
            try
            {
                StreamWriter writer = new StreamWriter(httpWebRequest.GetRequestStream(), Encoding.UTF8);
                writer.Write(postDataStr);
                writer.Flush();
                writer.Close();

                HttpWebResponse response     = (HttpWebResponse)httpWebRequest.GetResponse();
                Stream          stream       = response.GetResponseStream();
                StreamReader    streamReader = new StreamReader(stream, Encoding.GetEncoding("utf-8"));
                string          retString    = streamReader.ReadToEnd();
                streamReader.Close();
                stream.Close();
                response.Close();
                CtuResponse ctuResponse = js.Deserialize <CtuResponse>(retString);
                return(ctuResponse);
            }
            catch (Exception e) {
                httpWebRequest.Abort();
                CtuResponse response = new CtuResponse();
                CtuResult   result   = new CtuResult();
                result.RiskLevel = "ACCEPT";
                Dictionary <string, Object> ExtraInfo = new Dictionary <string, object>();
                ExtraInfo.Add("error", e.Message);
                result.ExtraInfo = ExtraInfo;
                response.result  = result;
                response.status  = CtuResponseStatus.SERVICE_INTERNAL_ERROR.ToString();
                return(response);
            }
        }
Beispiel #2
0
 public CtuResponse(String uuid, CtuResult ctuResult, CtuResponseStatus status)
 {
     this.uuid   = uuid;
     this.result = ctuResult;
     this.status = status.ToString();
 }
Beispiel #3
0
 public CtuResponse(String uuid, CtuResult ctuResult)
 {
     this.uuid   = uuid;
     this.result = ctuResult;
     this.status = CtuResponseStatus.SUCCESS.ToString();
 }