| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx

C++如何调用手机短信验证码

0
PHP .NET C/C++ Go 3296 次浏览

创蓝253短信平台案例---C语言调用接口

[C++] 基于创蓝253云通讯paas平台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


//线上线下接口宏开关

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



/**
* * 发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: sms.253.com\r\n"
                "Content-type: application/x-www-form-urlencoded\r\n"
                "Content-length: %zu\r\n\r\n"
                "%s", page, strlen(poststr), 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 *un, char *pw)
{
    char params[MAXPARAM + 1];
    char *cp = params;

        sprintf(cp,"un=%s&pw=%s", un, pw);

    return http_post(query_balance_uri, cp);
}

/**
* * 发送短信
* */
ssize_t send_sms(char *un, char *pw, char *phone, char *msg)
{
    char params[MAXPARAM + 1];
    char *cp = params;

        sprintf(cp,"un=%s&pw=%s&phone=%s&msg=%s&rd=1", un, pw, phone, 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 *un = "账号";
        char *pw = "密码";
        char *phone = "手机号";
        //必须带签名
        char *msg = "【253云通讯】您的验证码是123400";

    //get_balance(un, pw);
    send_sms(un, pw, phone, msg);
    close(sockfd);
    exit(0);
}
 

 

91个答案

0

I admire the valuable information you o ffer in your articles. For more information visit here

Cricut.com/setup

Cricut.com/setup

0

Thanks for the valuable content for more information please visit to my sites.
Disneyplus.com/begin Disneyplus.com/begin Disneyplus.com/begin Disneyplus.com/begin Disneyplus.com/begin Disneyplus.com/begin Disneyplus.com/begin 

0

slot 666Online slot web ready to provide entertainment on the internet 666 slot

0

สล็อต โรม่าRoma slot, the most popular online slot game of all time, roma slot 888, play free, online roma slot game. playing for real money Legendary online gambling game 2021 Roma Slots from famous gaming companies

0

SLOTA very popular game camp that played many years ago. Until now because it's a simple game. The rules are not complicated, the game is played for fun.

0

พีจีสล็อตonline slot games Deposit-withdraw via automatic system It has been ranked number 1 in popularity right now and is the most popular slot website right now.

0

pg slot autoBig web slots, PG, direct websites, not through agents 2021 with a fast automatic deposit-withdrawal system within 8 seconds.

0

ทางเข้าpgIt is a new hot new game camp of the year 2021, in which this camp pg 168 is very different from other camps and one of them is clearly Pc game 168.

0

Jokerdirect online slots Not through a joker agent, deposit-withdraw, no minimum, quality online gambling website that receives international standards, joker slots, easy to play, get real money.

0

เครดิต ฟรีLatest free credit 2021 online gambling website latest free credit All in one website, free credit, PG, slot promotions. Free credit, no deposit, no sharing

0

โรม่าJoker online slots that come with a modern system roma joker web slot

0

เล่น สล็อตonline slot games The most popular of the year 2021, joker game, deposit-withdraw, no minimum, there is a popular game like roma slot, apply for a joker game today, get a 100% bonus if you ask about the hot online gambling game overtaking the curve.z

0

Betflixonline slot games The most popular of the year 2021, joker game, deposit-withdraw, no minimum, there is a popular game like roma slot, apply for a joker game today, get a 100% bonus if you ask about the hot online gambling game overtaking the curve.z

0

joker online slot games The most popular of the year 2021, joker game, deposit-withdraw, no minimum, there is a popular game like roma slot, apply for a joker game today, get a 100% bonus if you ask about the hot online gambling game overtaking the curve.z

0

pgslotFree Trial PG and Joker is to play slots for free without having to pay a deposit first. There are currently playing slots. mostly through the mobile internet without having to go to the casino to play slots

0

ฝาก50รับ150  Deposit 50, get 150, no need to turn or call it easy to understand is a promotion, deposit 50, get 150 wallet as another

0

ฝาก20รับ100  A promotion that many people like and think that it is a worthwhile promotion.

0

ฝาก30รับ100  Latest 2021 Promotion Hits Slots Can play all game camps, new members, deposit 30, get 100, give away free credit, no need to deposit, no need to share Promotion deposit 30 get 100 unlimited withdrawal No minimum deposit

0

pg slot เว็บใหม่  The hottest slot game camp now in 2021, including all slots, all game camps in one website, welcomes PG, a new website, free credit, no deposit required, easy to play, earn real money.

0

Super Slot 888  The number 1 online slot game in Thailand, slot 888 online that includes the slot 888 game camp to play more than 300 games, slot 888 auto, open for deposit-withdrawal service with an automatic system.

1 2 3 4 5