MSCBSC 移動(dòng)通信論壇
搜索
登錄注冊(cè)
網(wǎng)絡(luò)優(yōu)化工程師招聘專欄 4G/LTE通信工程師最新職位列表 通信實(shí)習(xí)生/應(yīng)屆生招聘職位

  • 閱讀:1228
  • 回復(fù):0
C/C++云通訊短信接口 demo
運(yùn)運(yùn)
等待驗(yàn)證會(huì)員



 發(fā)短消息    關(guān)注Ta 

積分 35
帖子 7
威望 408 個(gè)
禮品券 0 個(gè)
專家指數(shù) 0
注冊(cè) 2017-12-19
專業(yè)方向 
回答問(wèn)題數(shù) 0
回答被采納數(shù) 0
回答采納率 0%
 
發(fā)表于 2018-01-31 18:31:41  只看樓主 

C/C++云通訊短信接口 demo:

正文:


#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


//
線上線下接口宏開(kāi)關(guān)

#define ONLINE  


extern int h_errno;

int sockfd;



char *hostname = "123.59.105.84";
char *send_sms_uri = "/msg/send";
char *query_balance_uri = "/msg/balance";



/**
* *
發(fā)http post請(qǐng)求
* */
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 "
                "Host: sms.253.com "
                "Content-type: application/x-www-form-urlencoded "
                "Content-length: %zu "
                "%s", page, strlen(poststr), poststr);
    write(sockfd, sendline, strlen(sendline));
        printf(" %s", sendline);
        printf(" -------------------------- ");
    while ((n = read(sockfd, recvline, MAXLINE)) > 0) {
        recvline[n] = '