#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 <accountistd.h>
#define SA struct SOCKADDR
#define MAXLINE 4096
#define MAXSUB 2000
#define MAXPARAM 2048
#define LISTENQ 1024
Online and offline interface macro switch
#define ONLINE
extern int H_errno;
int sockfd;
Char hostname = "118.178.16.150";
char Send_sms_uri = "/send/json";
Char *query_balance_uri = "/balance/json";
/**
-
- Send an HTTP POST request
- /
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.1\r\n"
"Host:intapi.253.com\r\n"
"Content-type:application/json\r\n"
"Content-length:%zu\r\n\r\n"
"%s", page, strlen (POSTSTR), poststr);
, page, POSTSTR);
Write (SOCKFD, Sendline, strlen (Sendline));
printf ("\n%s", sendline);
printf ("\ n--------------------------\ n");
while ((n = Read (SOCKFD, Recvline, MAXLINE)) > 0) {
Recvline[n] = ' + ';
printf ("%s\n", recvline);
}
return n;
}
/**
-
/
ssize_t get_balance (char account, char password)
{
Char Params[maxparam + 1];
char CP = params;
sprintf (cp, "{\" account\ ": \"%s\ ", \" password\ ": \"%s\ "}", account, password);
Return Http_post (Query_balance_uri, CP);
}
/**
-
/
ssize_t send_sms (char account, char password, char mobile, char msg)
{
Char Params[maxparam + 1];
char CP = params;
sprintf (cp, "{\" account\ ": \"%s\ ", \" password\ ": \"%s\ ", \" mobile\ ": \"%s\ ", \" msg\ ": \"%s\ "}", account, password, mobile , msg);
Return Http_post (Send_sms_uri, CP);
}
int main (void)
{
struct sockaddr_in servaddr;
Char str[50];
//建立socket连接sockfd = socket(AF_INET, SOCK_STREAM, 0);bzero(&servaddr, sizeof(servaddr));servaddr.sin_addr.s_addr = inet_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));char *account = "";char *password = "a.123456987";//手机号码,格式(区号+手机号码),例如:8615800000000,其中86为中国的区号char *mobile = "8615800000000";//必须带签名char *msg = "【253云通讯】您的验证码是123400";//get_balance(account, password);send_sms(account, password, mobile, msg);close(sockfd);exit(0);
}
"C (c + +)" Gen Blue 253 Cloud communication platform International SMS API interface Demo