本文实例为大家分享C++短信接口代码,短信接口适用于:网站APP短信验证码、群发短信会议通知、会员/客户关系交流、订单生成通知、发货通知、日程提醒、催费通知等等供大家参考,具体内容如下:
#include <stdio.h>
#include <curl/curl.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#define MAXPARAM 2048
CURL*curl;
CURLcoderes;
/**
* 本样例依赖libcurl库
* 下载地址 https://curl.haxx.se/download.html
*/
/* 短信内容 */
char *msg = "【秒赛科技】您的验证码是:1234";
/* 发送url 请咨询客服 */
char *url = "xxxxxxxxxxxxxxxxxxxxxxx";
void send_data( char *url, char *data )
{
/* specify the url */
curl = curl_easy_init();
curl_easy_setopt( curl, CURLOPT_URL, url );
printf( "url:%s\n", url );
/* specify the POST data */
curl_easy_setopt( curl, CURLOPT_POSTFIELDS, data );
printf( "data:%s\n", data );
/* get response data */
CURLcode res = curl_easy_perform( curl );
printf( "%d\n", res );
/* printf("\n\n"); */
}
/**
* 发送短信
*/
void send_sms( char *url, char *account, char *pswd, char *mobile, char *msg )
{
charparams[MAXPARAM + 1];
char*cp = params;
sprintf( params, "account=%s&pswd=%s&mobile=%s&msg=%s&needstatus=true&product=", account, pswd, mobile, msg );
send_data( url, params );
}
int main( void )
{
/* 账号 */
char *account = "***************";
/* 密码 */
char *pswd = "***************";
/* 修改为您要发送的手机号 */
char *mobile = "***************";
/* 发送验证码短信 */
send_sms( url, account, pswd, mobile, msg );
return(0);
}