/// <summary>
        /// 识别图片中的所有文字
        /// </summary>
        /// <param name="imagedata"></param>
        /// <returns></returns>
        public string[] TextDetections(byte[] imagedata)
        {
            BaiduResult   baiduResult = Newtonsoft.Json.JsonConvert.DeserializeObject <BaiduResult>(client.GeneralBasic(imagedata).ToString());
            List <string> msgs        = new List <string>();

            baiduResult.words_result.ForEach(c => msgs.Add(c.words));
            return(msgs.ToArray());
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string platform  = Request.QueryString["platform"];
            string channelID = Request.QueryString["channelID"];
            string loginKey  = Request.QueryString["loginkey"];

            if (string.IsNullOrEmpty(loginKey))
            {
                Response.Write(BuildAccount.buildLuaReturn(-1, "data error"));
                return;
            }
            if (string.IsNullOrEmpty(loginKey))
            {
                Response.Write(BuildAccount.buildLuaReturn(-1, "data error"));
                return;
            }
            if (string.IsNullOrEmpty(channelID))
            {
                Response.Write(BuildAccount.buildLuaReturn(-1, "data error"));
                return;
            }
            loginKey = Encoding.Default.GetString(Convert.FromBase64String(loginKey));
            string decryptStr = AESHelper.AESDecrypt(loginKey, AES_KEY);

            string[] subString = decryptStr.Split(':');
            if (subString.Length < 2)
            {
                Response.Write(BuildAccount.buildLuaReturn(-1, "data error"));
                return;
            }
            string token    = subString[0];
            string sign     = subString[1];
            string remoteIP = Request.ServerVariables.Get("Remote_Addr").ToString();

            string url = string.Format("http://zhibo.v.baidu.com/token/tokencheck/?token={0}&ip={1}&sign={2}", token, remoteIP, sign);

            byte[] bytes = HttpPost.Get(new Uri(url));
            if (bytes == null)
            {
                Response.Write(BuildAccount.buildLuaReturn(-2, "http error"));
                return;
            }
            string result = Encoding.UTF8.GetString(bytes);

            BaiduResult baiduResult = JsonHelper.ParseFromStr <BaiduResult>(result);

            if (baiduResult.result == 0)
            {
                checkAccount(baiduResult, channelID);
            }
            else
            {
                Response.Write(BuildAccount.buildLuaReturn(-3, "check error"));
            }
        }
        void checkAccount(BaiduResult result, string channelID)
        {
            Random   rd      = new Random();
            DateTime now     = DateTime.Now;
            int      randkey = rd.Next();
            Dictionary <string, object> savedata = new Dictionary <string, object>();

            string acc = "bd_" + result.data.userid;

            savedata["acc"]       = acc;
            savedata["username"]  = result.data.username;
            savedata["randkey"]   = randkey;
            savedata["lasttime"]  = now.Ticks;
            savedata["ip"]        = Request.ServerVariables.Get("Remote_Addr").ToString();
            savedata["channelID"] = channelID;

            if (MongodbAccount.Instance.KeyExistsBykey("baiduview_login", "acc", acc) == false)
            {
                Dictionary <string, object> savelog = new Dictionary <string, object>();
                savelog["acc"]      = acc;
                savelog["acc_real"] = acc;
                savelog["ip"]       = Request.ServerVariables.Get("Remote_Addr").ToString();
                savelog["time"]     = now;
                savelog["channel"]  = channelID;

                MongodbAccount.Instance.ExecuteInsert("RegisterLog", savelog);
            }

            string msg = MongodbAccount.Instance.ExecuteStoreBykey("baiduview_login", "acc", acc, savedata);

            if (msg == "")
            {
                Dictionary <string, object> savelog = new Dictionary <string, object>();
                savelog["acc"]      = acc;
                savelog["acc_real"] = acc;
                savelog["ip"]       = Request.ServerVariables.Get("Remote_Addr").ToString();
                savelog["time"]     = now;
                savelog["channel"]  = channelID;

                MongodbAccount.Instance.ExecuteInsert("LoginLog", savelog);
            }

            string clientkey = randkey.ToString() + ":" + now.Ticks.ToString();
            string loginKey  = AESHelper.AESEncrypt(clientkey, AES_LOGINKEY);

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("local ret = {{code = 0, msg=\"{0}\"}};", loginKey);
            sb.AppendFormat("ret.userid = \"{0}\";", AESHelper.AESEncrypt(acc, AES_KEY));
            sb.AppendFormat("ret.username = \"{0}\";", AESHelper.AESEncrypt(result.data.username, AES_KEY));
            sb.Append("return ret;");

            Response.Write(sb.ToString());
        }
예제 #4
0
        /// <summary>
        /// 打开网点信息
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        private static List <SiteInfo> OpenFile(String filePath)
        {
            DataTable       dt      = ExcelHelper.ExcelToDataTable("输入", true, filePath);
            List <SiteInfo> lstSite = ConvertHelper <SiteInfo> .ConvertToList(dt);

            foreach (var site in lstSite)
            {
                BaiduResult geocoder = JsonHelper.JsonDeserialize <BaiduResult>(BaiduMap.Geocoder(site.address));
                site.lat = geocoder.result.location.lat;
                site.lng = geocoder.result.location.lng;
            }
            return(lstSite);
        }
예제 #5
0
        public string VerificationCodeKeyword()
        {
            BaiduConfig  baiduTextConfig  = ConfigUtil.LoadConfig <BaiduConfig>("appsettings.json", "BaiduTextConfig");
            BaiduConfig  baiduImageConfig = ConfigUtil.LoadConfig <BaiduConfig>("appsettings.json", "BaiduImageConfig");
            _12306Config _12306Config     = ConfigUtil.LoadConfig <_12306Config>("appsettings.json", "12306Config");

            ImageUtil.CaptureImage(verificationCodeGrayScalePng, 120, 0, verificationCodeKeywordPng, 170, 28);

            #region 获取验证码关键字

            var client = new Ocr(baiduTextConfig.ApiKey, baiduTextConfig.SecretKey);
            client.Timeout = 60000;
            var image   = File.ReadAllBytes(verificationCodeGrayScalePng);
            var options = new Dictionary <string, object> {
                { "language_type", "CHN_ENG" },
                { "detect_direction", "true" },
                { "detect_language", "true" },
                { "probability", "true" }
            };
            // 调用通用文字识别, 图片参数为本地图片,可能会抛出网络等异常,请使用try/catch捕获
            var         keywordJObj = client.GeneralBasic(image, options);
            BaiduResult baiduResult = keywordJObj.ToObject <BaiduResult>();
            Console.WriteLine(keywordJObj);
            string keyword = baiduResult.words_result.FirstOrDefault().words.TrimStart("请点击下图中所有的".ToArray());

            #endregion

            #region 将验证码切成八个图片
            ImageUtil.CaptureImage(verificationCodePng, 5, 40, verificationCodePng1, 67, 67);
            ImageUtil.CaptureImage(verificationCodePng, 76, 40, verificationCodePng2, 67, 67);
            ImageUtil.CaptureImage(verificationCodePng, 148, 40, verificationCodePng3, 67, 67);
            ImageUtil.CaptureImage(verificationCodePng, 224, 40, verificationCodePng4, 67, 67);

            ImageUtil.CaptureImage(verificationCodePng, 5, 115, verificationCodePng5, 67, 67);
            ImageUtil.CaptureImage(verificationCodePng, 76, 115, verificationCodePng6, 67, 67);
            ImageUtil.CaptureImage(verificationCodePng, 148, 115, verificationCodePng7, 67, 67);
            ImageUtil.CaptureImage(verificationCodePng, 224, 115, verificationCodePng8, 67, 67);
            #endregion

            var access_token = AccessToken.getAccessToken(baiduImageConfig);

            if (AdvancedGeneral.advancedGeneral(access_token.access_token, verificationCodePng1, keyword))
            {
                Console.WriteLine($"图片1命中 {keyword}");
            }
            if (AdvancedGeneral.advancedGeneral(access_token.access_token, verificationCodePng2, keyword))
            {
                Console.WriteLine($"图片2命中 {keyword}");
            }
            if (AdvancedGeneral.advancedGeneral(access_token.access_token, verificationCodePng3, keyword))
            {
                Console.WriteLine($"图片3命中 {keyword}");
            }
            if (AdvancedGeneral.advancedGeneral(access_token.access_token, verificationCodePng4, keyword))
            {
                Console.WriteLine($"图片4命中 {keyword}");
            }
            if (AdvancedGeneral.advancedGeneral(access_token.access_token, verificationCodePng5, keyword))
            {
                Console.WriteLine($"图片5命中 {keyword}");
            }
            if (AdvancedGeneral.advancedGeneral(access_token.access_token, verificationCodePng6, keyword))
            {
                Console.WriteLine($"图片6命中 {keyword}");
            }
            if (AdvancedGeneral.advancedGeneral(access_token.access_token, verificationCodePng6, keyword))
            {
                Console.WriteLine($"图片7命中 {keyword}");
            }
            if (AdvancedGeneral.advancedGeneral(access_token.access_token, verificationCodePng7, keyword))
            {
                Console.WriteLine($"图片8命中 {keyword}");
            }
            return(null);
        }