How to get SMS verification code---Gen Blue 253 SMS Service Platform

Source: Internet
Author: User
Tags http post sprintf

#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

Online and offline interface macro switch

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

/**

      • 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.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] = ' + ';
      printf ("%s\n", recvline);
      }
      return n;
      }

/**

      • Balance of Audit account
    • /
      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);
      }

/**

      • Send SMS
    • /
      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);

}

In addition to C + +, there are demos in other languages (java/php/asp, etc.)
Downloadable by yourself: www.253.com/?did=168

How to get SMS verification code---Gen Blue 253 SMS Service Platform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.