예제 #1
0
        private static AndroidApplication GetApplicationObject(string outPath, string valueXml, string apkPath)
        {
            string manifestXml = outPath + "\\AndroidManifest.xml";

            ReturnStruct rs = GetPathsAndPackageName(manifestXml);

            string appNV   = rs.appNameV;
            string package = rs.packageName;
            string appN    = rs.nameWritesDirectly ? rs.appNameV : GetAppNameByVariableName(valueXml, appNV);
            string logoPath;

            try
            {
                logoPath = GetLogoPath(rs.logoV, outPath);
            }
            catch (Exception)
            {
                logoPath = null;
            }


            AndroidApplication appO = new AndroidApplication(appN, package, apkPath, logoPath);

            return(appO);
        }
        private ReturnStruct ReturnAStruct()
        {
            var ret = new ReturnStruct
            {
                A = "123456778",
                B = "123456778",
                C = "123456778",
                D = "123456778",
                E = false,
                F = true
            };

            return(ret);
        }
예제 #3
0
        private static ReturnStruct GetPathsAndPackageName(string manifestXml)
        {
            /*
             * In order to find the package name and app name in the same time,
             * the method needs to return two values. Hence I wrapped the result
             * in a struct.
             */

            ReturnStruct rs = new ReturnStruct();

            using (StreamReader sr = new StreamReader(manifestXml))
            {
                using (XmlReader xmlr = XmlReader.Create(sr))    // Create an XML Reader with a specified document.
                {
                    while (xmlr.Read())
                    {
                        if (xmlr.NodeType == XmlNodeType.Element && xmlr.Name == "application") // <application> element
                        {
                            string label = xmlr.GetAttribute("android:label");                  // "android:label"
                            if (label != null)
                            {
                                if (label.Contains("@"))
                                {
                                    rs.appNameV           = label.Split('/')[1];
                                    rs.nameWritesDirectly = false;
                                }
                                else
                                {
                                    rs.appNameV           = label; // To handle with the apk which writes its name directly.
                                    rs.nameWritesDirectly = true;
                                }
                            }

                            rs.logoV = xmlr.GetAttribute("android:icon");
                            // android:icon="@mipmap/ic_launcher"   -- Sample
                        }
                        else if (xmlr.NodeType == XmlNodeType.Element && xmlr.Name == "manifest")   // <manifest>, to seek the package name.
                        {
                            rs.packageName = xmlr.GetAttribute("package");
                        }
                    }
                }
            }

            return(rs);
        }
예제 #4
0
        /// <summary>
        ///     Processes a HTTP POST request for uploading a file from fine-uploader.
        /// </summary>
        private void ProcessPostRequest(HttpContext httpContext)
        {
            ReturnStruct status = new ReturnStruct();

            status.success = true;

            try
            {
                if (httpContext.Request.Files.Count > 0)
                {
                    HttpPostedFile file = httpContext.Request.Files[0];
                    status.name = Path.GetFileName(file.FileName);
                    status.uuid = httpContext.Request["qquuid"];
                    status.size = file.ContentLength;

                    byte[] bte = new byte[file.InputStream.Length];

                    file.InputStream.Read(bte, 0, Convert.ToInt32(file.InputStream.Length));

                    if (this.RestContext.Equals("common", StringComparison.InvariantCultureIgnoreCase) && this.RestElement.Equals("attachmentdata", StringComparison.InvariantCultureIgnoreCase))
                    {
                        status.DataId = SaveAttachmentData(httpContext, file, status.name, bte);
                    }
                    else
                    {
                        throw new ApplicationException(string.Format("There is no implementation for uploading files to httpContext '{0}', element '{1}'", this.RestContext, this.RestElement));
                    }
                }
            }
            catch (Exception ex)
            {
                status.error        = ex.Message;
                status.preventRetry = true;
                status.success      = false;
            }

            this.ProcessResponse(status);
        }
예제 #5
0
        static void Main(string[] args)
        {
            Mid engine = new Mid();

            ReturnStruct r = engine.EncryptString("test", "abc123");

            Console.WriteLine(r.Result);
            Console.WriteLine();

            StringBuilder sb = new StringBuilder();

            sb.Append("[");

            int it = 0;

            foreach (int ti in r.RandomKeys)
            {
                sb.Append(ti);
                if (it != (r.RandomKeys.Length) - 1)
                {
                    sb.Append(",");
                }
                it++;
            }

            sb.Append("]");

            Console.WriteLine(sb.ToString());

            Console.ReadLine();

            Console.Clear();

            Console.WriteLine(engine.DecryptString(r.Result, "abc123", r.RandomKeys));

            Console.ReadLine();
        }
예제 #6
0
 public override IEnumerable <string> Dependencies() =>
 ArgumentStruct.Dependencies().Concat(ReturnStruct.Dependencies());
예제 #7
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";

            var result = new ApiResult();

            /*var macIsInDatabase = false;
             * foreach (var nic in NetworkInterface.GetAllNetworkInterfaces())
             * {
             *  if (nic.OperationalStatus == OperationalStatus.Up)
             *  {
             *      var mac = nic.GetPhysicalAddress().ToString().Replace("-", "").ToUpper();
             *      foreach (DataRow row in Global.GetClientMacs().Rows)
             *      {
             *          if (mac.Equals(row.ItemArray[0]))
             *          {
             *              macIsInDatabase = true;
             *              break;
             *          }
             *      }
             *
             *      if (macIsInDatabase)
             *      {
             *          break;
             *      }
             *  }
             * }
             *
             * if (macIsInDatabase == false)
             * {
             *  result.code = 0x03;
             *  result.message = "非法请求";
             *
             *  context.Response.Write(JsonConvert.SerializeObject(result));
             *
             *  return;
             * }*/

            if (context.Request.HttpMethod != "POST")
            {
                result.code    = 0x01;
                result.message = "需要使用POST请求";

                context.Response.Write(JsonConvert.SerializeObject(result));

                return;
            }

            // 没有图片的请求
            if (string.IsNullOrEmpty(context.Request.Form["facesImage"]))
            {
                result.code    = 0x02;
                result.message = "参数错误";

                context.Response.Write(JsonConvert.SerializeObject(result));
                return;
            }

            // 人脸检测引擎初始化
            pMemDetect     = Marshal.AllocHGlobal(detectSize);
            detectInitCode = ArcSoft.AFD_FSDK_InitialFaceEngine(appId, sdkFDKey, pMemDetect, detectSize,
                                                                ref detectEngine,
                                                                (int)ArcSoft.AFD_FSDK_OrientPriority.AFD_FSDK_OPF_0_HIGHER_EXT, nScale, nMaxFaceNum);
            if (detectInitCode != 0)
            {
                // 检测引擎初始化错误
                result.code    = 0x211;
                result.message = "服务器错误";

                context.Response.Write(JsonConvert.SerializeObject(result));
                return;
            }

            // 人脸识别引擎初始化
            pMemRecognition     = Marshal.AllocHGlobal(detectSize);
            recognitionInitCode =
                ArcSoft.AFR_FSDK_InitialEngine(appId, sdkFRKey, pMemRecognition, detectSize, ref recognitionEngion);
            if (recognitionInitCode != 0)
            {
                // 识别引擎初始化错误
                result.code    = 0x212;
                result.message = "服务器错误";

                // 销毁检测引擎
                ArcSoft.AFD_FSDK_UninitialFaceEngine(detectEngine);

                context.Response.Write(JsonConvert.SerializeObject(result));
                return;
            }

            // base64编码的图片
            var base64 = context.Request.Form["facesImage"];

            // 检测人脸
            Bitmap faceImage = null;

            byte[] faceImageBytes;
            int    width = 0, height = 0, pitch = 0;

            faceImageBytes = Global.ProcessBase64(base64, ref faceImage, ref width, ref height, ref pitch);

            // 创建图片指针,并复制图片信息
            var imageDataPtr = Marshal.AllocHGlobal(faceImageBytes.Length);

            Marshal.Copy(faceImageBytes, 0, imageDataPtr, faceImageBytes.Length);

            // 创建图片其他信息指针,并设置内容
            var offInput = new ArcSoft.ASVLOFFSCREEN
            {
                u32PixelArrayFormat = 513,
                ppu8Plane           = new IntPtr[4],
                i32Width            = width,
                i32Height           = height,
                pi32Pitch           = new int[4]
            };

            offInput.ppu8Plane[0] = imageDataPtr;
            offInput.pi32Pitch[0] = pitch;
            var offInputPtr = Marshal.AllocHGlobal(Marshal.SizeOf(offInput));

            Marshal.StructureToPtr(offInput, offInputPtr, false);

            // 检测结果对象指针
            var faceRes    = new ArcSoft.AFD_FSDK_FACERES();
            var faceResPtr = Marshal.AllocHGlobal(Marshal.SizeOf(faceRes));
            // 进行检测
            int detectResult;

            try
            {
                detectResult = ArcSoft.AFD_FSDK_StillImageFaceDetection(detectEngine, offInputPtr, ref faceResPtr);
            }
            catch (AccessViolationException e)
            {
                result.code    = -1;
                result.message = e.Message;

                context.Response.Write(JsonConvert.SerializeObject(result));

                Marshal.FreeHGlobal(imageDataPtr);
                Marshal.FreeHGlobal(offInputPtr);
                //Marshal.FreeHGlobal(faceResPtr);

                // 销毁检测引擎
                ArcSoft.AFD_FSDK_UninitialFaceEngine(detectEngine);
                // 销毁识别引擎
                ArcSoft.AFR_FSDK_UninitialEngine(recognitionEngion);

                return;
            }

            // 从指针转化为对象
            faceRes = (ArcSoft.AFD_FSDK_FACERES)Marshal.PtrToStructure(faceResPtr, typeof(ArcSoft.AFD_FSDK_FACERES));

            if (detectResult == 0)
            {
                if (faceRes.nFace == 0)
                {
                    result.code    = 0x11;
                    result.message = "没有检测到人脸";

                    context.Response.Write(JsonConvert.SerializeObject(result));

                    Marshal.FreeHGlobal(imageDataPtr);
                    Marshal.FreeHGlobal(offInputPtr);
                    //Marshal.FreeHGlobal(faceResPtr);

                    // 销毁检测引擎
                    ArcSoft.AFD_FSDK_UninitialFaceEngine(detectEngine);
                    // 销毁识别引擎
                    ArcSoft.AFR_FSDK_UninitialEngine(recognitionEngion);
                }
                else if (faceRes.nFace > 1)
                {
                    result.code    = 0x12;
                    result.message = "检测到多个人脸";

                    context.Response.Write(JsonConvert.SerializeObject(result));

                    Marshal.FreeHGlobal(imageDataPtr);
                    Marshal.FreeHGlobal(offInputPtr);
                    //Marshal.FreeHGlobal(faceResPtr);

                    // 销毁检测引擎
                    ArcSoft.AFD_FSDK_UninitialFaceEngine(detectEngine);
                    // 销毁识别引擎
                    ArcSoft.AFR_FSDK_UninitialEngine(recognitionEngion);
                }
                else
                {
                    result.code    = 0x0;
                    result.message = "成功";

                    // 识别模型对象和指针
                    var modelRes    = new ArcSoft.AFR_FSDK_FaceModel();
                    var modelResPtr = Marshal.AllocHGlobal(Marshal.SizeOf(modelRes));
                    // 输入的人脸信息
                    var faceInput = new ArcSoft.AFR_FSDK_FaceInput();
                    // 人脸角度
                    faceInput.lOrient = (int)Marshal.PtrToStructure(faceRes.lfaceOrient, typeof(int));
                    // 人脸矩形框
                    faceInput.rcFace = (ArcSoft.MRECT)Marshal.PtrToStructure(faceRes.rcFace, typeof(ArcSoft.MRECT));
                    // 输入人脸信息指针
                    var faceInputPtr = Marshal.AllocHGlobal(Marshal.SizeOf(faceInput));
                    Marshal.StructureToPtr(faceInput, faceInputPtr, false);
                    // 进行识别
                    var recognitionResult =
                        ArcSoft.AFR_FSDK_ExtractFRFeature(recognitionEngion, offInputPtr, faceInputPtr,
                                                          modelResPtr);
                    // 从指针转化为对象
                    modelRes = (ArcSoft.AFR_FSDK_FaceModel)Marshal.PtrToStructure(modelResPtr,
                                                                                  typeof(ArcSoft.AFR_FSDK_FaceModel));

                    Marshal.FreeHGlobal(imageDataPtr);
                    Marshal.FreeHGlobal(offInputPtr);
                    //Marshal.FreeHGlobal(faceResPtr);
                    Marshal.FreeHGlobal(faceInputPtr);
                    Marshal.FreeHGlobal(modelResPtr);

                    if (recognitionResult == 0)
                    {
                        // 获取人脸特征
                        var featureContent = new byte[modelRes.lFeatureSize];
                        Marshal.Copy(modelRes.pbFeature, featureContent, 0, modelRes.lFeatureSize);

                        var similarity   = 0f;
                        var returnStruct = new ReturnStruct();
                        var compareRes   = Compare(featureContent, ref similarity, ref returnStruct);
                        // 存在匹配的人脸
                        if (compareRes == 0)
                        {
                            result.message = "成功";
                            result.data    = returnStruct;

                            context.Session["uid"] = returnStruct.userId;
                        }
                        // 不存在匹配的人脸
                        else if (compareRes == -1)
                        {
                            result.data = -1;
                        }
                        // 函数错误
                        else
                        {
                            result.code    = 0x24;
                            result.message = "系统错误";
                            result.data    = compareRes;
                        }

                        context.Response.Write(JsonConvert.SerializeObject(result));

                        // 销毁检测引擎
                        ArcSoft.AFD_FSDK_UninitialFaceEngine(detectEngine);
                        // 销毁识别引擎
                        ArcSoft.AFR_FSDK_UninitialEngine(recognitionEngion);
                    }
                    else
                    {
                        result.code    = 0x23;
                        result.message = "服务器错误";
                        result.data    = recognitionResult;

                        context.Response.Write(JsonConvert.SerializeObject(result));

                        // 销毁检测引擎
                        ArcSoft.AFD_FSDK_UninitialFaceEngine(detectEngine);
                        // 销毁识别引擎
                        ArcSoft.AFR_FSDK_UninitialEngine(recognitionEngion);
                    }
                }
            }
            else
            {
                result.code    = 0x22;
                result.message = "服务器错误";
                result.data    = detectResult;

                context.Response.Write(JsonConvert.SerializeObject(result));

                // 销毁检测引擎
                ArcSoft.AFD_FSDK_UninitialFaceEngine(detectEngine);
                // 销毁识别引擎
                ArcSoft.AFR_FSDK_UninitialEngine(recognitionEngion);
            }
        }
예제 #8
0
        /// <summary>
        ///     将人脸数据与数据库的人脸数据进行一一对比
        /// </summary>
        /// <param name="feature"></param>
        /// <param name="similarity"></param>
        /// <returns>有匹配返回0, 没有匹配返回-1,失败返回code</returns>
        private int Compare(byte[] feature, ref float similarity, ref ReturnStruct returnStruct)
        {
            // 检测到的脸部信息
            var localFaceModels  = new ArcSoft.AFR_FSDK_FaceModel();
            var sourceFeaturePtr = Marshal.AllocHGlobal(feature.Length);

            Marshal.Copy(feature, 0, sourceFeaturePtr, feature.Length);
            localFaceModels.lFeatureSize = feature.Length;
            localFaceModels.pbFeature    = sourceFeaturePtr;
            var localFacePtr = Marshal.AllocHGlobal(Marshal.SizeOf(localFaceModels));

            Marshal.StructureToPtr(localFaceModels, localFacePtr, false);

            // 服务器的脸部信息
            var libraryFaceModel = new ArcSoft.AFR_FSDK_FaceModel();
            var libaryFeaturePtr = IntPtr.Zero;
            var libraryFacePtr   = IntPtr.Zero;

            // 与数据库中每条人脸特征信息进行比较
            foreach (DataRow row in Global.GetlibraryFeatures().Rows)
            {
                var libaryFeature = (byte[])row.ItemArray[0];

                // 准备服务器的脸部信息
                libaryFeaturePtr = Marshal.AllocHGlobal(libaryFeature.Length);
                Marshal.Copy(libaryFeature, 0, libaryFeaturePtr, libaryFeature.Length);
                libraryFaceModel.lFeatureSize = libaryFeature.Length;
                libraryFaceModel.pbFeature    = libaryFeaturePtr;
                libraryFacePtr = Marshal.AllocHGlobal(Marshal.SizeOf(libraryFaceModel));
                Marshal.StructureToPtr(libraryFaceModel, libraryFacePtr, false);

                similarity = 0f;
                // 进行比较
                var ret = ArcSoft.AFR_FSDK_FacePairMatching(recognitionEngion, localFacePtr, libraryFacePtr,
                                                            ref similarity);

                // 释放空间
                Marshal.FreeHGlobal(libaryFeaturePtr);
                Marshal.FreeHGlobal(libraryFacePtr);

                // 比较函数正常
                if (ret == 0)
                {
                    // 找到匹配的人脸
                    if (similarity >= minSimilarity)
                    {
                        returnStruct.userId = int.Parse(row.ItemArray[1].ToString());
                        returnStruct.name   = row.ItemArray[2].ToString();
                        var privilege = int.Parse(row.ItemArray[3].ToString());
                        // 如果是访客
                        if (privilege == 3)
                        {
                            var inTime    = DateTime.Parse(row.ItemArray[4].ToString().Replace("T", " "));
                            var validDays = int.Parse(row.ItemArray[5].ToString());
                            // 已到时间
                            if (inTime.AddDays(validDays) <= DateTime.Now)
                            {
                                continue;
                            }
                        }

                        return(0);
                    }
                }
                // 函数错误,停止比较
                else if (ret != 0)
                {
                    return(ret);
                }
            }

            // 没有找到匹配的人脸
            return(-1);
        }
예제 #9
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";

            var result = new ApiResult();

            if (context.Request.HttpMethod != "POST")
            {
                result.code    = 0x01;
                result.message = "需要使用POST请求";

                context.Response.Write(JsonConvert.SerializeObject(result));
                return;
            }

            var phone = context.Request.Form["phone"];
            var code  = context.Request.Form["code"];

            if (phone == null || code == null)
            {
                result.code    = 0x03;
                result.message = "参数错误";

                context.Response.Write(JsonConvert.SerializeObject(result));
                return;
            }

            var returnStruct = new ReturnStruct();

            var sql = "select count(*) from user where phone = ?p;";
            var ret = int.Parse(MySQLHelper.ExecuteScalar(sql, new MySqlParameter("?p", phone)).ToString());

            // 存在于user表中
            if (ret == 1)
            {
                returnStruct.firstLogin = false;
                sql = "select id, name from user where phone = ?p;";
                var ds = MySQLHelper.ExecuteDataSet(sql, new MySqlParameter("?p", phone));
                returnStruct.userId = int.Parse(ds.Tables[0].Rows[0].ItemArray[0].ToString());
                returnStruct.name   = ds.Tables[0].Rows[0].ItemArray[1].ToString();

                context.Session["uid"] = returnStruct.userId;

                result.message = "成功";
                result.data    = returnStruct;
            }
            else
            {
                sql = "select count(*) from owner where phone = ?p;";
                ret = int.Parse(MySQLHelper.ExecuteScalar(sql, new MySqlParameter("?p", phone)).ToString());
                // 存在于owner表中
                if (ret == 1)
                {
                    returnStruct.firstLogin = true;
                    returnStruct.userId     = 0;
                    sql = "select name, id from owner where phone = ?p;";
                    var ds = MySQLHelper.ExecuteDataSet(sql, new MySqlParameter("?p", phone));
                    returnStruct.name = ds.Tables[0].Rows[0].ItemArray[0].ToString();

                    context.Session["oid"] = ds.Tables[0].Rows[0].ItemArray[1].ToString();

                    result.message = "成功";
                    result.data    = returnStruct;
                }
                else
                {
                    result.message = "成功";
                    result.data    = null;
                }
            }

            context.Response.Write(JsonConvert.SerializeObject(result));
        }