互億無線 · 文檔中心

運營商三要素MD5版 - 代碼示例


C++對接身份證核驗接口(MD5加密版)DEMO示例
本文為您提供了C++語言版本的運營商三要素核驗(MD5加密版)對接DEMO示例

運營商三要素接口文檔 點擊下載

運營商核驗接入指南 點擊訪問



// 接口類型:互億無線實名認證接口
// 賬戶注冊:https://user.ihuyi.com/register.html
// 注意事項:
// DEMO僅作參考
//linux下的編譯:g++ ./test.cpp -o ./test
//linux下的執(zhí)行:chmod +x test &&./test

#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netdb.h>
#include <unistd.h>

#define SA struct sockaddr
#define MAXLINE 4096
#define MAXSUB  2000
#define MAXPARAM 2048
#define LISTENQ 1024

extern int h_errno;

int basefd;
char *hostname = "api.ihuyi.com";
char *submit_uri = "/idcard/Submit.json";

/**
* 發(fā)http post請求
*/
ssize_t http_post(char *page, char *poststr)
{
    char sendline[MAXLINE + 1], recvline[MAXLINE + 1];
    ssize_t n;
    snprintf(sendline, MAXSUB,
        "POST %s HTTP/1.0\r\n"
        "Host: %s\r\n"
        "Content-type: application/x-www-form-urlencoded\r\n"
        "Content-length: %zu\r\n\r\n"
        "%s", page, hostname, strlen(poststr), poststr);

    write(basefd, sendline, strlen(sendline));
    while ((n = read(basefd, recvline, MAXLINE)) > 0) {
        recvline[n] = '\0';
        printf("%s", recvline);
    }
    return n;
}

/**
* 提交認證
*/
ssize_t submit(char *account, char *password, char *app, char *name, char *id_card_no, char *mobile)
{
    char params[MAXPARAM + 1];
    char *cp = params;
    sprintf(cp,"account=%s&password=%s&app=%s&name=%s&id_card_no=%s&mobile=%s", account, password, app, name, id_card_no, mobile);
    return http_post(submit_uri, cp);
}

int  socked_connect(char *arg)
{
    struct sockaddr_in their_addr = {0};
    char buf[1024] = {0};
    char rbuf[1024] = {0};
    char pass[128] = {0};
    struct hostent *host = NULL;

    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if(sockfd<0)
    {
        printf ("create the sockfd is failed\n");
        return -1;
    }

    if((host = gethostbyname(arg))==NULL)  
    {  
        printf("Gethostname error, %s\n");  
        return -1; 
    }

    memset(&their_addr, 0, sizeof(their_addr));  
    their_addr.sin_family = AF_INET;  
    their_addr.sin_port = htons(80);  
    their_addr.sin_addr = *((struct in_addr *)host->h_addr);
    if(connect(sockfd,(struct sockaddr *)&their_addr, sizeof(struct sockaddr)) < 0)
    {
        close(sockfd);
        return  -1;
    }
    printf ("connect is success\n");
    return sockfd;
    
}

int main(void)
{
    struct sockaddr_in servaddr;
    char str[50];

    #if 0
    //建立socket連接
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_addr =*(hostname);
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(80);
    inet_pton(AF_INET, str, &servaddr.sin_addr);
    connect(sockfd, (SA *) & servaddr, sizeof(servaddr));
    #endif
    
    if((basefd= socked_connect(hostname))==-1)
    {
        printf("connect is failed\n");
        return -1;
    }
    printf("basefd is =%d\n",basefd);

    char *account = "APIID";
    char *password = "APIKEY";
    char *app = "oper3m";//固定值
    char *name = "15db57aa314529aaa0fbe95b3e95bd3"; //明文:張三
    char *id_card_no = "9efebb3d7d059bff092842bf31dd2816"; //明文:123456789012345678
    char *mobile = '112d01c8f09ff66df96979d7d7e3056c'; //明文:13600000000

    /**************** 提交認證 *****************/
    submit(account, password, app, name, id_card_no, mobile);
    printf("submit is success\n");
    close(basefd);
    exit(0);
}

現在注冊,即享新用戶禮包!

在線咨詢
電話咨詢

服務熱線:

4008 808 898

服務熱線(工作時間):

4008 808 898

業(yè)務咨詢(非工作時間):

售后咨詢(非工作時間):

驗證碼已發(fā)送到您的手機,請查收!

輸入驗證碼后,點擊“開通體驗賬戶”按鈕可立即開通體驗賬戶。

收不到短信驗證碼?
互億無線不提供接碼服務,接碼用戶請勿點擊開通按鈕。
×