微信小程序> 图片滑块验证码的解决-微信图形验证码不显示-小程序图形验证码

图片滑块验证码的解决-微信图形验证码不显示-小程序图形验证码

浏览量:4066 时间: 来源:瞌睡先生想睡觉
1.

其他的不多说,直奔主题:

2.

本次是以微信注册中所遇到滑块验证码为例,主要的目的就是让脚本实现自动识别阴影部分的位置,然后计算出距离拖动滑块完成验证操作

3.

想要从1处滑动到2处,就需要知道1处和2处的中间点的x轴坐标位置,1点的坐标基本是固定的,2点的坐标是不断在变化的.我的方法也是在网上查到的,思路就是得出原图,然后和有阴影的图片进行对比从而得出阴影部分的位置.图片只需要得到3位置的部分就可以了.左边的部分不需要.

4.

获取原图的方式还是比较麻烦的,我尝试了抓包,但是失败了,第一次抓iOS的包,微信的这些数据是https的,数据是加密后的.当然也有可能是我比较水.我最终获取的方式是截取3中除去2的右边部分,然后在不断刷新,直至刷出2在3的右边的时候,截取左边的部分,然后将2张截图合并在一起.获取完整图片.脚本端我是使用触动精灵来做的,触动精灵有提供屏幕截取以及图片合并的api下面是我收集原图的代码,比较笨,如果有人有更好的方法,欢迎交流

require("TSLib")require("sz")--[[(200,232)(609,232)(200,563)(609,563)]]--name"马路"--i的值为你需要的位置i0--snapshot(name.."前.png",200,232,i-1,563);--snapshot(name.."后.png",i,232,609,563);--图片合成--imageOperMerge({name.."前.png",name.."后.png"},name..".png",0);--滑块图截取--snapshot("测试1.png",200,232,609,563)nLog("执行完成")5.

触动精灵文档地址

6.

滑块验证的图片都是固定的几张图片,在我写这篇博客的时候微信的滑块验证共13张图片.获取到我们需要的原图之后.因为触动没有直接提供对本地图片像素的提取访问,而我对lua的库第三方库也不是很熟悉,所以图片对比的代码我是用我最熟悉的Java来完成的

packagecom.wkk.test;importjavax.imageio.ImageIO;importjavax.imageio.ImageWriter;importjavax.imageio.stream.ImageOutputStream;importjava.awt.*;importjava.awt.image.BufferedImage;importjava.io.File;importjava.io.IOException;importjava.util.Iterator;publicclassTest{publicstaticvoidmain(String[]arg){Stringpath1"D:\马路.png";Stringpath2"D:\测试1.png";intdvgetDifferenceValue(path1,path2);System.out.println(dv);}/***通过像素对比来计算偏差值**@parampath1原图位置*@parampath2滑块图位置*@return偏差值*/publicstaticintgetDifferenceValue(Stringpath1,Stringpath2){intresult0;FilefilenewFile(path1);Filefile1newFile(path2);if(!file.exists()||!file1.exists()){System.out.println("文件不存在");return0;}try{BufferedImageimageImageIO.read(file);BufferedImageimage1ImageIO.read(file1);intheightimage.getHeight();intwidthimage.getWidth();//遍历每一个像素点,对比,相同为0,不同为1int[][]intsnewint[height][width];for(intx1;xwidth;x++){for(inty1;yheight;y++){intcolorimage.getRGB(x,y);intcolor1image1.getRGB(x,y);if(colorcolor1){ints[y-1][x-1]0;}else{ints[y-1][x-1]1;}}}//通过上下左右像素的对比来去除杂色,并且计算最大值最小值intmaxX-1;intminX999;for(inty0;yints.length;y++){intis[]ints[y];for(intx0;xis.length;x++){if(is[x]1){ints[y][x]checkPixel(x,y,ints);if(ints[y][x]1){if(xmaxX){maxXx;}if(xminX){minXx;}}}}}//此处只是为了生成效果图方便观察,实际操作中不必执行createImage(width,height,ints);result(maxX+minX)/2;}catch(Exceptione){e.printStackTrace();}returnresult;}/***通过上下左右像素的对比来检测像素点是否是杂色**@paramx*@paramy*@paramints*@return*/publicstaticintcheckPixel(intx,inty,int[][]ints){booleanresult1true;booleanresult2true;ints10;for(inti0;i30;i++){if((x+i)ints[1].lengthints[y][x+i]!1){s1++;}}if(s115){result1false;}ints20;for(inti0;i30;i++){if(x-i0ints[y][x-i]!1){s2++;}}if(s215){result2false;}if(result1||result2){s10;for(inti0;i30;i++){if(y+iints.lengthints[y+i][x]!1){s1++;}}if(s115){result1false;}s20;for(inti0;i30;i++){if(y-i0ints[y-i][x]!1){s2++;}}if(s215){result2false;}if(result1||result2){return1;}}return0;}/***创建图片*@paramwidth*@paramheight*@paramints*@throwsIOException*/publicstaticvoidcreateImage(intwidth,intheight,intints[][])throwsIOException{BufferedImagebinewBufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR);Graphics2Dgraphicbi.createGraphics();graphic.setColor(newColor(0xffffff));graphic.fillRect(0,0,width,height);for(inty0;yints.length;y++){intis[]ints[y];for(intx0;xis.length;x++){if(is[x]1){bi.setRGB(x,y,0x0000ff);}}}IteratorImageWriteritImageIO.getImageWritersByFormatName("png");ImageWriterwriterit.next();FilefnewFile("c://img.png");ImageOutputStreamiosImageIO.createImageOutputStream(f);writer.setOutput(ios);writer.write(bi);}}7.

这个程序的重点就在像素的对比上,脚本的代码很简单没有放上去的必要,上面的代码就是核心的代码,整个流程就是脚本截取图片上传到服务器上,服务器对图片进行对比操作过后返回2点的中间位置x轴的坐标.然后脚本计算转化过后进行滑动操作.整个过程从开始到滑动结束,网络正常的情况下所需时间在3秒以内,贴一下效果图:

8.

对比图:

9.

不知道这样的操作叫不叫图片二值化-_-上面代码中有去除杂色的部分,因为截图和原图的像素除了滑块部分外并非完全相同,所以需要上下对比15个像素来确定是不是滑块中的点,下面这一张是没有去除杂色的图片:

10.

因为是计算滑块区域的x轴最大值最小值,所以杂色会对计算造成干扰.

11.

关于如何确定当前滑块图对应的哪一张原图问题,我采取的方法,也是比较笨的方法,每一张图都截取图片左下角的一小片位置然后循环区域找图,找到了就知道对应关系了.如果有更好的方法欢迎交流.

12.

脚本的代码只是关于点色的判断,都很简单就不贴了.看下最终效果图:实时桌面反应没那么快,将就着看吧.

13.

本文中的滑块验证码只是以微信的为例子,实际很多其他平台的滑块验证码也可以通过这种方式去解决,当前这种方式,这是解决方案的一种.如果有更好的思路,欢迎评论交流.

14.

2017-12-21上面对比像素的代码太乱了,而且还不大好用,现在重新整理优化下

/***通过像素对比来计算偏差值**@parampath1原图位置*@parampath2滑块图位置*@return偏差值*/publicintgetDifferenceValue(Stringpath1,Stringpath2){intresult0;FilefilenewFile(path1);Filefile1newFile(path2);try{BufferedImageimageImageIO.read(file);BufferedImageimage1ImageIO.read(file1);intwidthimage.getWidth();intheightimage.getHeight();int[][]colorsnewint[width][height];for(intx1;xwidth;x++){for(inty1;yheight;y++){intcolor1image.getRGB(x,y);intcolor2image1.getRGB(x,y);if(color1color2){colors[x-1][y-1]0;}else{colors[x-1][y-1]1;}}}intmin999;intmax-1;for(intx0;xcolors.length;x++){for(inty0;ycolors[x].length;y++){if(colors[x][y]1){colors[x][y]checkPixel(x,y,colors);if(colors[x][y]1){if(xmax){maxx;}elseif(xmin){minx;}}}}}result(max+min)/2;}catch(IOExceptione){e.printStackTrace();}returnresult;}publicintcheckPixel(intx,inty,int[][]colors){intresultcolors[x][y];intnum0;if((y+30)colors[x].length){for(inti1;i30;i++){intcolorcolors[x][y+i];if(color0){num+1;}}if(num15){return0;}}returnresult;}publicstaticvoidcreateImage(intwidth,intheight,intints[][],Stringname)throwsIOException{BufferedImagebinewBufferedImage(width,height,BufferedImage.TYPE_INT_RGB);Graphics2Dgraphicbi.createGraphics();graphic.setColor(newColor(0x003D1CFF));graphic.fillRect(0,0,width,height);for(intx0;xints.length;x++){for(inty0;yints[x].length;y++){if(ints[x][y]1){bi.setRGB(x,y,0xFF7F2E);}}}IteratorImageWriteritImageIO.getImageWritersByFormatName("png");ImageWriterwriterit.next();FilefnewFile("c://"+name+".png");ImageOutputStreamiosImageIO.createImageOutputStream(f);writer.setOutput(ios);writer.write(bi);}15.

https://mp.weixin.qq.com/s/6pMjn83xWkM4cvhXyh90tQ

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

最新资讯

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎