#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<curl/curl.h>
#include<string>
#include<iostream>
#include<fstream>
#include<openssl/pem.h>
#include<openssl/bio.h>
#include<openssl/evp.h>
#include <openssl/buffer.h>
#include<unistd.h>
#include<openssl/md5.h>
using namespace std;
char * base64Encode(const char *buffer, int length)
{
BIO *bmem = NULL;
BIO *b64 = NULL;
BUF_MEM *bptr;
b64 = BIO_new(BIO_f_base64());
//BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
BIO_write(b64, buffer, length);
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);
BIO_set_close(b64, BIO_NOCLOSE);
char *buff = (char *)malloc(bptr->length + 1);
memcpy(buff, bptr->data, bptr->length);
buff[bptr->length] = '\0';
BIO_free_all(b64);
return buff;
}
int main(int argc,char *argv[]) {
string PAHT = "test.png";
string url = "http://www.seemmark.com/external-api/external/captcha/ve";
string key = "58f0a437e7798958a686bb33";
string codeID = "1001adf11eefe";
string userId = "1234";
//cin>>userId;
FILE *p = fopen("test.png", "rb");
// 判断打开文件是否成功
// 定义读取文件的缓冲区
char buf[1024];
// 循环读取文件
string s;
while(fread(&buf,sizeof(char),sizeof(buf),p) > 0){
string tmp = buf;
s += tmp;
memset(buf,0,sizeof(buf));
}
cout<<s<<endl;
const char *buffer = s.c_str();
char * buff;
buff = base64Encode(buffer, s.length());
string image = buff;
//cout<<image<<endl;
codeID = "codeID=" + codeID;
image = "image=" + image;
userId = "userId" + userId;
string param = codeID + "&" + image + "&" + userId + "&" + key;
//cout<<param<<endl;
MD5_CTX ctx;
unsigned char md[16];
char bufs[33] = {'\0'};
char tmp[3] = {'0'};
int i;
const char *ps = param.c_str();
MD5_Init(&ctx);
MD5_Update(&ctx, p, param.length());
MD5_Final(md, &ctx);
for(i = 0; i < 16;i++)
{
sprintf(tmp, "%02X", md[i]);
strcat(buf, tmp);
}
//printf("%s\n", buf);
return 0;
}
http://www.seemmark.com/developer/image-captcha/sample-codes
test.png









网友评论