c++利用飞信API免费发短信
2014-04-01 20:37
246 查看
一、飞信接口介绍
该飞信接口是基于HTTP协议的接口,可以在任何支持HTTP协议的程序中使用。一些不能用PHP的朋友们可以使用此飞信接口,另外可以避免飞信不断升级导致的源程序不可用。本接口同时支持HTTPS,可避免在网络传输中泄漏数据。
(1)飞信接口调用方式,参数同时支持GET、POST两种方式
(2)使用HTTPS调用飞信接口,只需将HTTP改为HTTPS
(3)返回结果为Json格式,result=0时表示发送成功
二、使用HTTPS调用飞信接口举例
1、头文件如下:
2、cpp文件如下:
3、main函数调用发送
该飞信接口是基于HTTP协议的接口,可以在任何支持HTTP协议的程序中使用。一些不能用PHP的朋友们可以使用此飞信接口,另外可以避免飞信不断升级导致的源程序不可用。本接口同时支持HTTPS,可避免在网络传输中泄漏数据。
(1)飞信接口调用方式,参数同时支持GET、POST两种方式
https://quanapi.sinaapp.com/fetion.php?u=飞信登录手机号&p=飞信登录密码&to=接收飞信的手机号&m=飞信内容 |
{“result”:0,”message”:”\u53d1\u9001\u6210\u529f”} |
1、头文件如下:
01 | /************************************************************************/ |
02 | /* |
03 | 文件名称:FeiXin.h |
04 | 功能介绍:利用飞信的免费API接口发送短信 |
05 | 版本:v1.00(初版) |
06 | 作者:moki |
07 | 日期:2014.01.06 |
08 | */ |
09 | /************************************************************************/ |
10 | #ifndef__FEIXIN__H_ |
11 | #define__FEIXIN__H_ |
1 | #include<Windows.h> |
2 | #include<string> |
3 | #include<wininet.h> |
4 | #include<stdio.h> |
01 | #defineFX_MAXSIZE4096 |
02 | #pragmacomment(lib,"Wininet.lib") |
03 | class CFeiXin |
04 | { |
05 | public : |
06 | //发送短信 |
07 | static int FX_SendMessage( char *_usrname, char *_password, char *_number, char *_sms); |
08 | //发送http请求 |
09 | static int FX_SendHttp( char *_url); |
10 | protected : |
11 | CFeiXin(){} |
12 | ~CFeiXin(){} |
13 | private : |
14 | static std::stringm_url; |
15 | }; |
1 | #endif |
01 | #include"FeiXin.h" |
02 | std::stringCFeiXin::m_url= " ; |
03 | int CFeiXin::FX_SendMessage( char *_usrname, char *_password, char *_number, char *_sms) |
04 | { |
05 | int ret=0; |
06 | char chbuf[FX_MAXSIZE]={0}; |
07 | sprintf (chbuf, "%s?u=%s&p=%s&to=%s&m=%s" ,m_url.c_str(),_usrname,_password,\ |
08 | _number,_sms); |
09 | ret=FX_SendHttp(chbuf); |
10 | return ret; |
11 | } |
12 | //发送http请求 |
13 | int CFeiXin::FX_SendHttp( char *_url) |
14 | { |
15 | int ret=0; |
16 | HINTERNEThSession=InternetOpen( "UrlFeiXin" ,INTERNET_OPEN_TYPE_PRECONFIG, |
17 | NULL,NULL,0); |
18 | char strresult[256]={0}; |
19 | if (hSession!=NULL) |
20 | { |
21 | HINTERNEThHttp=InternetOpenUrl(hSession,_url,NULL,0, |
22 | INTERNET_FLAG_DONT_CACHE,0); |
23 | if (hHttp!=NULL) |
24 | { |
25 | BYTE Temp[FX_MAXSIZE]; |
26 | ULONG Number=1; |
27 | while (Number>0) |
28 | { |
29 | InternetReadFile(hHttp,Temp,FX_MAXSIZE-1,&Number); |
30 | Temp[Number]= '\0' ; |
31 | sprintf (strresult, "%s" ,Temp); |
32 | //解析返回码 |
33 | std::stringstr=strresult; |
34 | int startpos=str.find_first_of( ":" )+1; |
35 | int endpos=str.find_first_of( "," ); |
36 | std::stringstrcode=str.substr(startpos,endpos-startpos); |
37 | ret= atol (strcode.c_str()); |
38 | } |
39 | InternetCloseHandle(hHttp); |
40 | hHttp=NULL; |
41 | } |
42 | InternetCloseHandle(hSession); |
43 | hSession=NULL; |
44 | } |
45 | return ret; |
46 | } |
01 | #include<iostream> |
02 | #include"..\FeiXin\FeiXin.h" |
03 | using namespace std; |
04 | int main( int argc, char *argv[]) |
05 | { |
06 | // |
07 | DWORD ret=CFeiXin::FX_SendMessage( "飞信登录手机号" , "飞信登录密码" , "接收飞信的手机号" , |
08 | "飞信内容" ); |
09 | if (ret!=0) |
10 | { |
11 | cout<< "发送短信失败" <<endl; |
12 | } |
13 | else |
14 | { |
15 | cout<< "发送短信成功" <<endl; |
16 | } |
17 | return 0; |
18 | } |
相关文章推荐
- c++利用飞信API免费发短信
- 飞信API免费发短信
- 飞信免费发短信API
- php利用飞信api给好友发短信
- 免费的午餐(编程利用GoogleAPI发短信)-移动联通都支持
- 中国移动飞信发短信免费,MSN与QQ受生死挑战
- PHP免费发短信飞信类实现
- 利用飞信免费每天给你发天气预报
- 中国移动飞信免费发短信API接口(第三方 Fetion API)
- 发送飞信免费短信API
- 利用飞信给自己发短信的shell脚本
- 飞信PHP接口|飞信PHP API免费发送手机短信接口,thinkphp发送单条函数
- 飞信免费发送接口API的测试 httpClient
- asp.net调用飞信免费发短信
- C++连接MySQL数据库(利用API)
- 中国移动飞信免费发短信API接口(第三方 Fetion API)
- 利用飞信给自己发短信的shell脚本(2012-12-31更新,处理验证码,目前可用)
- JAVA利用短信平台API免费发送短信的程序
- asp.net调用飞信免费发短信(测试有效)
- 中国移动飞信免费发短信API接口(第三方 Fetion API)