宅男噜噜噜66在线观看,亚洲精品一区二区三区精品,亚洲一区二区三区乱码在线欧洲,亚洲精品久久麻豆蜜桃,亚洲色无色a片一区二区

您是否正受到短信簽名報(bào)備的困擾?互億無(wú)線解決方案讓您最快15分鐘內(nèi)恢復(fù)信息傳遞,馬上 注冊(cè)體驗(yàn)
所有文檔
銀行信息核驗(yàn)
應(yīng)用開(kāi)發(fā)
短信服務(wù)
文檔中心 > 短信服務(wù) > 彩信/視頻短信

彩信/視頻短信

C++對(duì)接彩信批量提交接口接口DEMO示例
本文為您提供了C++語(yǔ)言版本的彩信批量提交接口接口對(duì)接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;
const char *hostname = "api.ihuyi.com";
const char *send_sms_uri = "/mms/v1/batchSend";

/**
* 發(fā)http post請(qǐng)求
*/
ssize_t http_post(const char *page, const char *poststr)
{
    char sendline[MAXLINE + 1], recvline[MAXLINE + 1];
    ssize_t n;
    snprintf(sendline, MAXSUB,
        "POST %s HTTP/1.1\r\n"
        "Host: %s\r\n"
        "Content-type: application/json\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;
}

int  socked_connect(const 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", hstrerror(h_errno));
        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 params[MAXPARAM + 1];
    char *cp = params;

    const char *json_str = "{\"api_id\":\"sms-yx-xxxxxxx\",\"signature\":\"92b2919615570ceb0fa8a1b6c87c9a7a\",\"timestamp\":1756092730,\"request_id\":\"17560927306063\",\"product_id\":1001,\"phone\":[\"18800000000\",\"18800000001\"],\"sign_name\":\"xxxxxxxx\",\"title\":\"xxxxxxxxxxxx\",\"content\":[{\"con_type\":\"txt\",\"ext_type\":\"\",\"data\":\"將原始內(nèi)容base64編碼\"},{\"con_type\":\"img\",\"ext_type\":\"jpg\",\"data\":\"將原始內(nèi)容base64編碼\"}],\"template_id\":1,\"send_time\":\"2020-08-26 16:08:14\"}";
    
    strncpy(params, json_str, MAXPARAM);

    http_post(send_sms_uri, cp);

    printf("send the message is success\n");
    close(basefd);
    exit(0);
}

5分鐘快速自助開(kāi)通免費(fèi)體驗(yàn)賬戶

在線咨詢
電話咨詢

服務(wù)熱線:

4008 808 898

服務(wù)熱線(工作時(shí)間):

4008 808 898

業(yè)務(wù)咨詢(非工作時(shí)間):

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