短信接口示例
這篇文章主要為大家分享C++短信接口代碼,C++短信發(fā)送、C++批量發(fā)送、C++短信驗證碼發(fā)送,感興趣的小伙伴們可以參考一下。
#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 */ /* 短信內(nèi)容 */ char *msg = "【秒賽科技】您的驗證碼是:1234"; /* 發(fā)送url 請咨詢客服 */ char *url = "http://139.196.108.241:8080/Api/HttpSendSMYzm.ashx"; 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"); */ } /** * 發(fā)送短信 */ 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", account, pswd, mobile, msg ); send_data( url, params ); } int main( void ) { /* 賬號 */ char *account = "您的賬號"; /* 密碼 */ char *pswd = "您的密碼"; /* 修改為您要發(fā)送的手機(jī)號 */ char *mobile = "手機(jī)號"; /* 發(fā)送驗證碼短信 */ send_sms( url, account, pswd, mobile, msg ); return(0); }