有道智云OCR图片识别文字+返回数据处理技巧(实现语言-按键精灵脚本请求识别+java服务端处理数据)

开发者技术变现资源聚集地

https://www.baiydu.com

 

一.开始】、

     1.按键精灵android手机脚本

      1.1.截取手机上指定范围内的图片,通过api上传到有道智云处理后返回识别后的JSON格式数据。

      1.2.代码

Import "ShanHai.lua" 
//公用该方法 Function wangyiOcrDiscern(imagePath) Dim appKey,img,langType,detectType,imageType,salt,docType,sign,appsecret appsecret="应用程序key" appKey = "应用程序秘钥\'" Dim time_stamp = Time() salt = Encode.Md5(CStr(time_stamp)) img = Replace(ShanHai.ReadFileBase(imagePath), """", "") langType = "zh-en" detectType = "10012" imageType = "1" sign = Encode.Md5(appKey & img & salt & appsecret) Dim goupParameter goupParameter = "img=" & ShanHai.CharToUrl(img) & "&" & "langType=" & ShanHai.CharToUrl(langType) & "&" & "detectType=" & ShanHai.CharToUrl(detectType) & "&" & "imageType=" & ShanHai.CharToUrl(imageType) & "&" & "appKey=" & ShanHai.CharToUrl(appKey) & "&" & "salt=" & ShanHai.CharToUrl(salt) & "&" & "sign=" & ShanHai.CharToUrl(sign) & "&" & "docType=" & ShanHai.CharToUrl(docType) wangyiOcrDiscern = URL.Post("http://openapi.youdao.com/ocrapi", goupParameter) End Function

 

//调用部分代码
Dir
.Delete ("/storage/emulated/0/ocr.jpg") SnapShot "/storage/emulated/0/ocr.jpg", 166, 215, 597, 1680 ocrJson = wangyiOcrDiscern("/storage/emulated/0/ocr.jpg") ocrJson = UTF8.Mid(ocrJson, charPostion + 8, Len(ocrJson)) ocrJson = "[" & Replace(ocrJson, "}]}}", "")
通过上面的处理得到的ocrJson是一个 JSONArray数组字符串,里面每个成员都为字典JSONObject

  

//将数据传给java处理,这里为什么不直接给按键精灵处理了,首先按键处理数据的能力不能和java比,然后是这些数据都是要往服务器里走的。
Function
shareHttpRequest(checkJsonData,appName) Dim parameter,posturl parameter = "checkJson=" & checkJsonData & "&appName=" & appName posturl = "https://www.?.com/?/?" Dim returnData,wetherGoOnRun URL.Post(posturl,parameter) End Function

 

 2.java服务端脚本

     2.1. 接受从按键来的数据后,进行一系列的规范处理,然后入数据库。

     2.2.代码(由于下面处理数据部分代码太多就不一一说了,不明白的可以问我)

           

  else if(appName.contains("?"))
                          {
                           shareArray=new JSONArray();
                          int weatherPostNikeNameError=0;
                           for(int i=0;i<serverArray.length();i++)
                           {
                              weatherPostNikeNameError=0;
                               tempValueJsonobject=serverArray.getJSONObject(i);
                               //审核中的id,已遍历出来
                                 checkId=tempValueJsonobject.getString("weixinNumber");
                                 id=tempValueJsonobject.getString("id");
                                 publisher=tempValueJsonobject.getString("publisher");
                                 
                                 if(parameterArray==null)
                                  {
                                   
                                     parameterArray=new JSONArray(ocrStrValue);
                                     
                               
                                       
                                        for(int t=0;t<10;t++)
                                       {
                                        JSONObject singlexxxx= parameterArray.getJSONObject(0);
                                       String dltTxtxxx=singlexxxx.getString("text").replace(" ", "");
                                        if (!dltTxtxxx.contains("用户"))
                                        {
                                          parameterArray.remove(0); 
                                           
                                        }
                                        else
                                        {
                                            break;
                                        }
                                       } 
                                   
                                    //最后一个成员移除
                                     for(int k=0;k<10;k++)
                                    {
                                        JSONObject singlexx= parameterArray.getJSONObject(parameterArray.length()-1);
                                       String dltTxt=singlexx.getString("text").replace(" ", "");
                                        if (dltTxt.contains("奖励"))
                                        {
                                            
                                          break;
                                        }
                                       
                                        else
                                        {
                                           parameterArray.remove(parameterArray.length()-1);
                                        }
                                      
                                    }
                                       
                                    tempSaveObject=new JSONObject();
                                    String checkIdgroup="";
                                    String monery="";
                                    
                                    for(int j=1;j<parameterArray.length();j++)
                                    {
                                          singleObjet=parameterArray.getJSONObject(j-1);
                                          String text=singleObjet.getString("text").replace(" ", "");
                                          
                                          if(j%4!=0)
                                           { 
                                             
                                              if(text.contains("已到账")&&!text.contains("今日"))
                                              {
                                                monery=text.replace("已到账", "").replace("元", ""); 
                                              } 
                                              else
                                              {
                                                checkIdgroup=checkIdgroup+text;
                                              }
                                              
                                             
                                            
                                          }
                                          else
                                          {
                                        
                                           
                                          if(text.contains("已到账")&&!text.contains("今日"))
                                          {
                                            monery=text.replace("已到账", "").replace("元", "");  
                                          } 
                                             else
                                             {
                                               checkIdgroup=checkIdgroup+text;
                                             }
                                             
                                          tempSaveObject.put("checkId",checkIdgroup );  
                                            tempSaveObject.put("monery", monery);  
                                           
                                            
                                            shareArray.put(tempSaveObject);
                                            
                                             
                                             
                                          tempSaveObject=new JSONObject();
                                           checkIdgroup="";
                                           monery="";
                                         }
                                    
                                     }
                                   
                             
                              }
                                  
                                   
                                    taskTitle=tempValueJsonobject.getString("taskTitle");
                                    addTotalScore="0";
                                   
                              for(int j=0;j<shareArray.length();j++)
                              {
                                  tempSaveObject=shareArray.getJSONObject(j);
                                   shareStr=tempSaveObject.getString("checkId");
                                  
                                   if(shareStr.contains(checkId))
                                   {
                                       
                                      weatherPostNikeNameError=1;
                                       
                                       //数据库记录用户获得的总共奖励
                                          double rewardJiangliTotalMonery= Double.valueOf(tempValueJsonobject.getString("rewardJiangliTotalMonery"));
                                      
                                           
                                          //截图数据显示当前奖励的总数
                                           double jieTumonery=Double.valueOf(tempSaveObject.getString("monery"));
                                              
                                            if(rewardJiangliTotalMonery==0 && jieTumonery>=1)
                                            {
                                              addTotalScore=tempValueJsonobject.getString("addTotalScore");
                                       
                                            }  
                                             //截图显示的金钱数     //已经奖励的金钱数量
                                           if(jieTumonery>1 && rewardJiangliTotalMonery>1)
                                           {
                                                 
                                            double  againJiangliMonery=jieTumonery-rewardJiangliTotalMonery;
                                               sharemal =   new   BigDecimal(againJiangliMonery );
                                             againJiangliMonery=  sharemal.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();
                                          
                                              if (againJiangliMonery>=1)
                                              {
                                                  addTotalScore=String.valueOf(againJiangliMonery*0.5);
                                                   
                                              }
                                          }
                                           
                                           if(addTotalScore.contains("."))
                                           {
                                               addTotalScore=addTotalScore+"0"; 
                                           }
                                              
                                       
                                       if(!addTotalScore.equals("0"))//获得奖励,给用户增加金钱
                                       {
                                              userAccount=tempValueJsonobject.getString("account");
                                                mysqlParameter=new String[]{ addTotalScore,addTotalScore,userAccount};
                                                helper.executeUpdate("update  ? set score=score+?,xiajiReturnScore=xiajiReturnScore+? where account=?",mysqlParameter);
                                               
                                                mysqlParameter=new String[]{userAccount};
                                                JSONArray  TempShareArray=helper.executeQueryT("select * from ? where account=?", mysqlParameter);
                                                  singleObjet=TempShareArray.getJSONObject(0);
                                                 String Master=singleObjet.getString("masterAccount");
                                               
                                                if(!Master.equals("666")&& !Master.equals("13983918071"))
                                                {
                                                    
                                                 try{
                                                 mysqlParameter=new String[]{Master};
                                                TempShareArray=helper.executeQueryT("select * from userSheet where account=?", mysqlParameter);
                                                  singleObjet=TempShareArray.getJSONObject(0);
                                                
                                                    masterType=singleObjet.getString("userType");
                                                
                                                 
                                                
                                                  if(masterType.equals("铜牌"))
                                               {
                                                    singleObjet= AAAAYulebaoShareSingleton.getInstance().member_calss_sheet.getJSONObject(0);
                                               }
                                               else  if(masterType.equals("银牌"))
                                               {
                                                   singleObjet= AAAAYulebaoShareSingleton.getInstance().member_calss_sheet.getJSONObject(1);
                                               }
                                               else//金牌
                                               {
                                                   singleObjet= AAAAYulebaoShareSingleton.getInstance().member_calss_sheet.getJSONObject(2);
                                               } 
                                                   masteraddMonery=singleObjet.getString("fandian");
                                                }catch(Exception e){
                                                    masteraddMonery="0.1";
                                                }
                                                
                                               mysqlParameter=new String[] {masteraddMonery,masteraddMonery,Master};
                                              helper.executeUpdate("update userSheet set score=score+?,messageCount=messageCount+1,xiajiReturnScore=xiajiReturnScore+? where account=? and score>=0", mysqlParameter);    
                                              mysqlParameter=null;
                                              mysqlParameter=new String[]{"下级返点", "好友"+userAccount+"完成"+taskTitle+"任务,你获得"+masteraddMonery+"元",NowData,Master,"1"};
                                              helper.executeUpdate("insert into ?(title,content,datatime,account,infoType) values (?,?,?,?,?)", mysqlParameter);
                                                }
                                                
                                                mysqlParameter=new String[]{"任务奖励", taskTitle+"app任务再次完成,获得"+addTotalScore+"宝币",NowData,userAccount};
                                                
                                               helper.executeUpdate("insert into ?(title,content,datatime,account) values (?,?,?,?)", mysqlParameter);
                                                    
                                               String  subId;
                                              if(userAccount.length()==11)
                                              {     
                                                  subId=userAccount.substring(0, 3)+"******"+userAccount.substring(9);
                                              }
                                              else if(userAccount.length()==8)
                                               {
                                                   subId=userAccount.substring(0, 3)+"******"+userAccount.substring(6);
                                               }
                                               
                                              else
                                              {
                                                  userAccount="13983918071";
                                                   subId=userAccount.substring(0, 3)+"******"+userAccount.substring(9);
                                              }
                                                 
                                              mysqlParameter=new String[]{"已完成",tempSaveObject.getString("monery"),id,publisher};
                                               helper.executeUpdate("update ? set taskState=?,rewardJiangliTotalMonery=?,taskRecordTimes=taskRecordTimes+1 where id=? and publisher=?",mysqlParameter);
                                             
                                                String   lunboinfo="恭喜"+subId+taskTitle+"任务再次完成,获得"+addTotalScore+"元";
                                                 JSONArray  singleArray=AAAAYulebaoShareSingleton.getInstance().homePageSessionDictionary.getJSONArray("lunboinfoSheet");
                                                      singleArray.put(lunboinfo);
                                                      if(singleArray.length()>5)
                                                      {
                                                        singleArray.remove(0);
                                                      }
                                                   AAAAYulebaoShareSingleton.getInstance().homePageSessionDictionary.put("lunboinfoSheet", singleArray);
                                                  singleArray=null;
                                                  lunboinfo=null;
                                                 singleObjet=null;masterType=null;
                                       }
                                     
                                      else//审核失败
                                      {
                                          
                                          mysqlParameter=new String[]{"进行中","任务失败,?",id};
                                    helper.executeUpdate("update ? set taskState=?,finishTime=? where id=?",mysqlParameter);
                                   
                                      }
                              }
                            }

 

本人做的一款androidApp, 下载量已经有2000多万,各种当前热门的网络手机奖励红包全部集成,另外还有热门电影和淘宝高额优惠券!很适合各类型的用户。

 

 

 

 

     

版权声明:本文为xiaoliao原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/xiaoliao/p/10798584.html