首页 > 未分类 > go语言调用QQ超人打码插件dll
2014
06-13

go语言调用QQ超人打码插件dll

dll头文件

#pragma once


#ifdef DC_EXPORT
#define DC_API extern "C" __declspec(dllexport)
#else
#define DC_API extern "C" __declspec(dllimport)
#endif


typedef struct DCDATA* DCCTX;


DC_API DCCTX WINAPI DC_Init(const char* host,unsigned short port,int timeoutsecond);
/*
reqname,reqpwd为付费用户的用户名密码
recotimeout为识别超时值,建议此值至少为40秒,否则很可能频繁超时导致失败
imglen,img表示被识别的图片,长度不能超过10k(10240字节),否则直接失败
imgid识别成功时返回的否一标识值
result识别成功时返回的识别结果

返回值说明
0--超时无人打码
1--识别成功
-1--识别失败,超时或者没有传放正确的参数或其它原因
-2--余额不足
-3--未绑定或者未在绑定机器上运行
-4--时间过期
-5--用户校验失败
*/
DC_API int WINAPI DC_RecogImg(DCCTX h,const char*reqname,const char*reqpwd,int softwaretype,int recotimeout,int imglen,char*img,char*imgid,char*result);

DC_API int  WINAPI DC_NotifyFail(DCCTX h,const char*reqname,const char*reqpwd,char*imgid);
DC_API void WINAPI DC_Uninit(DCCTX h);

//-1--失败 其它--成功
DC_API int  WINAPI DC_GetInfo(DCCTX h,const char*reqname,const char*reqpwd,int* left,int* today,int* total);

DC_API void WINAPI DC_GetLastError(DCCTX h,char*errmsg);

GO语言调用:

package main

import (
	"os"
	"syscall"
	"unsafe"
)

func abort(funcname string, err error) {
	panic(funcname + " failed: " + err.Error())
}

func main() {
	//打码帐号配置 http://sz789.net 注册帐号和密码
	var username, password string
	username = "youruser"
	password = "yourpass"
	softId := 3696 //软件id,作者后台添加
	//加载dll
	h, err := syscall.LoadLibrary("dc.dll")
	if err != nil {
		abort("LoadLibrary", err)
	}
	defer syscall.FreeLibrary(h)

	//初始化插件,连接打码服务器
	DC_Init, err := syscall.GetProcAddress(h, "DC_Init")
	if err != nil {
		abort("DC_Init", err)
	}
	dch, _, _ := syscall.Syscall(uintptr(DC_Init), 3, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("127.0.0.1"))), 13888, 50)

	//查询点数
	left := int32(0)
	today := int32(0)
	total := int32(0)
	DC_GetInfo, err := syscall.GetProcAddress(h, "DC_GetInfo")
	r, _, _ := syscall.Syscall6(uintptr(DC_GetInfo), 6,
		uintptr(dch),
		uintptr(unsafe.Pointer(syscall.StringBytePtr(username))),
		uintptr(unsafe.Pointer(syscall.StringBytePtr(password))),
		uintptr(unsafe.Pointer(&left)),
		uintptr(unsafe.Pointer(&today)),
		uintptr(unsafe.Pointer(&total)))
	//uintptr指针变量转整型
	rr := int32(r)
	if rr == 1 {
		print("left:", left, "\n")
		print("today:", today, "\n")
		print("total:", total, "\n")
	} else if rr == -5 {
		print("帐号或密码错误")
	}
	//上传识别
	imagePath := "image.jpg"
	fin, err := os.Open(imagePath)
	buf := make([]byte, 10240)
	for {
		n, _ := fin.Read(buf)
		if 0 == n {
			break
		}
	}

	DC_RecogImg, err := syscall.GetProcAddress(h, "DC_RecogImg")
	imageId := make([]byte, 32)
	result := make([]byte, 8)
	lenght := len(buf)

	r1, _, _ := syscall.Syscall9(uintptr(DC_RecogImg), 9,
		uintptr(dch),
		uintptr(unsafe.Pointer(syscall.StringBytePtr(username))),
		uintptr(unsafe.Pointer(syscall.StringBytePtr(password))),
		uintptr(softId),
		uintptr(60),
		uintptr(lenght),
		uintptr(unsafe.Pointer(&buf[0])),
		uintptr(unsafe.Pointer(&imageId[0])),
		uintptr(unsafe.Pointer(&result[0])))
	//uintptr指针变量转整型
	rrr := int32(r1)
	if rrr == 1 {
		print("success:")
		print(string(result), "  ", string(imageId), "\n")
	} else if rrr == 0 {
		print("识别成功")
	} else if rrr == -1 {
		print("识别失败,超时或者没有传放正确的参数或其它原因")
	} else if rrr == -2 {
		print("余额不足")
	} else if rrr == -3 {
		print("未绑定或者未在绑定机器上运行")
	} else if rrr == -4 {
		print("时间过期")
	} else if rrr == -5 {
		print("用户校验失败")
	}

	//报告错误验证码,验证码识别结果错误时调用
	/*
		DC_NotifyFail, err := syscall.GetProcAddress(h, "DC_NotifyFail")
		syscall.Syscall6(uintptr(DC_NotifyFail), 4,
			uintptr(dch),
			uintptr(unsafe.Pointer(syscall.StringBytePtr(username))),
			uintptr(unsafe.Pointer(syscall.StringBytePtr(password))),
			uintptr(unsafe.Pointer(&imageId[0])), 0, 0)
		print("done")
	*/

	//反初始化插件
	DC_Uninit, err := syscall.GetProcAddress(h, "DC_Uninit")
	syscall.Syscall(uintptr(DC_Uninit), 1, uintptr(dch), 0, 0)
}
最后编辑:
作者:NINE
这个作者貌似有点懒,什么都没有留下。

go语言调用QQ超人打码插件dll》有 1 条评论

  1. 新一 说:

    最近也学习了。博主golang功底也不错啊。学习了。

留下一个回复

你的email不会被公开。