示例#1
0
        public static String SortedParams(CtuRequest request)
        {
            String eventCode = request.eventCode;
            String flag      = request.flag;
            Dictionary <string, string> data = request.data;

            StringBuilder sb = new StringBuilder();

            sb.Append(EVENT_CODE).Append(eventCode).Append(FLAG).Append(flag);
            // var dicSort = from objDic in data orderby objDic.Value ascending select objDic;
            Dictionary <string, string> dicSort = data.OrderBy(p => p.Key).ToDictionary(p => p.Key, o => o.Value);

            foreach (KeyValuePair <string, string> kvp in dicSort)
            {
                if (kvp.Value == null)
                {
                    sb.Append(kvp.Key).Append("null");
                }
                else
                {
                    sb.Append(kvp.Key).Append(kvp.Value);
                }
            }

            return(sb.ToString());
        }
示例#2
0
        public static String Sign(String appSecret, CtuRequest ctuRequest)
        {
            String sortedParams = SortedParams(ctuRequest);

            //  MD5 md5Hash = MD5.Create();

            return(GetMd5Hex(new StringBuilder(appSecret).Append(sortedParams)
                             .Append(appSecret).ToString()));
        }
示例#3
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);
            }
        }