package com.cqz.dm;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import javax.imageio.ImageIO;
import com.sun.jna.Library;
import com.sun.jna.Native;
/**
* 更多函数细节:dll.uuwise.com
*
*/
public class CQZDMDLL
{
public static String USERNAME = "UserName"; //UU用户名
public static String PASSWORD = "PassWord"; //UU密码
public static String DLLPATH = "lib\\UUWiseHelper"; //DLL
public static String IMGPATH = "img\\test.png";
public static int SOFTID = 2097; //软件ID
public static String SOFTKEY = "b7ee76f547e34516bc30f6eb6c67c7db"; //软件KEY
public interface DM extends Library
{
DM INSTANCE = (DM) Native.loadLibrary(DLLPATH, DM.class);
public int uu_reportError(int id);
public int uu_setTimeOut(int nTimeOut);
public void uu_setSoftInfoA(int softId, String softKey);
public int uu_loginA(String UserName, String passWord);
public int uu_getScoreA (String UserName, String passWord);
public int uu_recognizeByCodeTypeAndBytesA (byte[] picContent, int piclen, int codeType, byte[] returnResult);
public void uu_getResultA(int nCodeID,String pCodeResult);
}
public static void main(String[] args) throws Exception
{
int userID;
DM.INSTANCE.uu_setSoftInfoA(SOFTID, SOFTKEY);
userID=DM.INSTANCE.uu_loginA(USERNAME, PASSWORD);
if(userID>0){
System.out.println("userID is:"+userID);
System.out.println("user score is:"+DM.INSTANCE.uu_getScoreA(USERNAME, PASSWORD));
File f = new File(IMGPATH);
byte[] by = toByteArray(f);
byte[] resultBtye=new byte[30]; //为识别结果申请内存空间
int codeID=DM.INSTANCE.uu_recognizeByCodeTypeAndBytesA(by, by.length, 1, resultBtye); //调用识别函数,resultBtye为识别结果
String resultResult = new String(resultBtye,"UTF-8");
resultResult=resultResult.trim();
System.out.println("this img codeID:"+codeID);
System.out.println("return recongize Result:"+resultResult);
/*
//测试报错 开始,真实环境不可这样用,需要在实际验证码打错的情况下,执行报错函数进行报错,恶意报错会导致封号
System.out.println("报错前 user score is:"+DM.INSTANCE.uu_getScoreA(USERNAME, PASSWORD));
int reportErrorResult;
reportErrorResult=DM.INSTANCE.uu_reportError(codeID);
if(reportErrorResult==0)
{
System.out.println("报错后 user score is:"+DM.INSTANCE.uu_getScoreA(USERNAME, PASSWORD));
}else
{
System.out.println("报错失败,原因未知");
}
//测试报错 开始,真实环境不可这样用,需要在实际验证码打错的情况下,执行报错函数进行报错,恶意报错会导致封号
*/
}else{
System.out.println("登录失败,错误代码为:"+userID); //错误代码请对应dll.uuwise.com各函数值查看
}
}
public static byte[] toByteArray(File imageFile) throws Exception
{
BufferedImage img = ImageIO.read(imageFile);
ByteArrayOutputStream buf = new ByteArrayOutputStream((int) imageFile.length());
try
{
ImageIO.write(img, "jpg", buf);
} catch (Exception e)
{
e.printStackTrace();
return null;
}
return buf.toByteArray();
}
public static byte[] toByteArrayFromFile(String imageFile) throws Exception
{
InputStream is = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
try
{
is = new FileInputStream(imageFile);
byte[] b = new byte[1024];
int n;
while ((n = is.read(b)) != -1)
{
out.write(b, 0, n);
}// end while
} catch (Exception e)
{
throw new Exception("System error,SendTimingMms.getBytesFromFile", e);
} finally
{
if (is != null)
{
try
{
is.close();
} catch (Exception e)
{}// end try
}// end if
}// end try
return out.toByteArray();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
优优云验证码识别官方网站:http://www.uudama.com/ 相关函数说明:http://www.uudama.com/process.html 这个是DEMO下载,整个工程请去优优云验证码识别WIKI页面下载:http://dll.uuwise.com/index.php?n=ApiDoc.Java(界面的不要编译了,没有改) 如果您编译提示找不到DLL,请去这里看这篇文章:http://blog.csdn.net/a343390605/article/details/10589381
资源推荐
资源详情
资源评论
收起资源包目录
javaDemo.rar (1个子文件)
CQZDMDLL.java 4KB
共 1 条
- 1
资源评论
a343390605
- 粉丝: 1
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功