【C(C++)】创蓝253云通讯平台国际短信API接口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 <accountistd.h>

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

#define LISTENQ 1024

//线上线下接口宏开关

#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";

/**

    • 发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.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] = ‘\0‘;
    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);

}

原文地址:http://blog.51cto.com/13750674/2134063

时间: 2024-08-01 13:43:58

【C(C++)】创蓝253云通讯平台国际短信API接口DEMO的相关文章

【PYTHON】创蓝253云通讯平台国际短信API接口DEMO

#!/usr/local/bin/python#-- coding:utf-8 -- Author: jacky Time: 14-2-22 下午11:48 Desc: 短信http接口的python代码调用示例 import httplibimport urllibimport json#服务地址 host = "intapi.253.com" #端口号port = 80 #版本号version = "v1.1" #查账户信息的URIbalance_get_uri

【shell】创蓝253云通讯平台国际短信API接口DEMO

#!/bin/sh account and password can be change to what you wanna! #author ChuangLan#修改为您的accountaccount=""#修改为您的pwpassword="a.123456"#手机号码,格式(区号+手机号码),例如:8615800000000,其中86为中国的区号mobile="8615800000000"#设置您要发送的内容msg="[253云通讯

【ASP】创蓝253云通讯平台国际短信API接口DEMO

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% Function Post(url,data) dim Https set Https=server.createobject("MSXML2.XMLHTTP") Https.open "POST",url,false Https.setRequestHeader "Content-Type",&qu

【PHP】创蓝253云通信平台国际短信接口调用demo案例

PHP接口请求类<?phpheader("Content-type:text/html; charset=UTF-8"); / 类名:ChuanglanSmsApi 功能:创蓝接口请求类 详细:构造创蓝短信接口请求,获取远程HTTP数据 版本:1.3 日期:2017-04-12 说明: 以下代码只是为了方便客户测试而提供的样例代码,客户可以根据自己网站的需要,按照技术文档自行编写,并非一定要使用该代码. 该代码仅供学习和研究创蓝接口使用,只是提供一个参考.*/ class Chu

创蓝253云通讯平台---短信验证码接口说明

1协议说明 名称 说明 协议 HTTP POST 编码格式 UTF8 Content-Type application/json URL http://xxx/msg/send/json 或者 https://xxx/msg/send/json 完整地址请登录253云通讯自助通平台或者询问您的商务负责人获取 接口说明 此接口一次可提交不超过1000个手机号码. 2 请求包体 包体为json字符串,参数如下: { "account" : "N6000001", //用

创蓝253云通讯paas平台Python短信接口demo

#!/usr/local/bin/python#-- coding:utf-8 -- Author: jacky Time: 14-2-22 下午11:48 Desc: 短信http接口的python代码调用示例 import httplibimport urllib #服务地址host = "sms.253.com" #端口号port = 80 #版本号version = "v1.1" #查账户信息的URIbalance_get_uri = "/msg/

创蓝253云通讯短信平台变量说明

253云通讯变量说明文档1 变量短信发送用户通过HTTP的POST方式提交短信发送请求.1.1 系统提交URL地址http://sms.253.com/msg/HttpVarSM1.2 参数定义序号 参数 说明1 account 用户账号2 pswd 用户密码3 msg 短信模板.其中的变量用"{$var}"来替代.例如:"{$var},你好!,请你于{$var}日参加活动",该短信中具有两个变量参数.编码为UTF-8格式.最多支持20个{$var}4 params

【Python】短信验证码平台查询账户余额demo---创蓝253云通讯平台案例

#!/usr/local/bin/python#-- coding:utf-8 -- Author: jacky Time: 14-2-22 下午11:48 Desc: 短信http接口的python代码调用示例 import httplibimport urllibimport json#服务地址 host = "intapi.253.com" #端口号port = 80 #版本号version = "v1.1" #查账户信息的URIbalance_get_uri

【ASP】创蓝253云通讯paas平台短信验证码接口调用demo

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%><%Function Post(url,data)dim Https set Https=server.createobject("MSXML2.XMLHTTP")Https.open "POST",url,falseHttps.setRequestHeader "Content-Type","ap