1、飞信接口介绍php
该飞信接口是基于HTTP协议的接口,能够在任何支持HTTP协议的程序中使用。一些不能用PHP的朋友们能够使用此飞信接口,另外能够避免飞信不断升级致使的源程序不可用。本接口同时支持HTTPS,可避免在网络传输中泄漏数据。ios
(1)飞信接口调用方式,参数同时支持GET、POST两种方式 api
http://quanapi.sinaapp.com/fetion.php?u=飞信登陆手机号&p=飞信登陆密码&to=接收飞信的手机号&m=飞信内容 |
(2)使用HTTPS调用飞信接口,只需将HTTP改成HTTPS 网络
https://quanapi.sinaapp.com/fetion.php?u=飞信登陆手机号&p=飞信登陆密码&to=接收飞信的手机号&m=飞信内容 |
(3)返回结果为Json格式,result=0时表示发送成功 app
{“result”:0,”message”:”\u53d1\u9001\u6210\u529f”} |
2、使用HTTPS调用飞信接口举例函数
一、头文件以下:url
/************************************************************************/ /* 文件名称:FeiXin.h 功能介绍:利用飞信的免费API接口发送短信 版本:v1.00(第一版) 做者:moki 日期:2014.01.06 */ /************************************************************************/ #ifndef __FEIXIN__H_ #define __FEIXIN__H_
#include <Windows.h> #include <string> #include <wininet.h> #include <stdio.h>
#define FX_MAXSIZE 4096 #pragma comment(lib, "Wininet.lib") class CFeiXin { public: //发送短信 static int FX_SendMessage(char* _usrname,char* _password,char* _number,char* _sms); //发送http请求 static int FX_SendHttp(char* _url); protected: CFeiXin(){} ~CFeiXin(){} private: static std::string m_url; };
#endif
二、cpp文件以下:spa
#include "FeiXin.h" std::string CFeiXin::m_url = "https://quanapi.sinaapp.com/fetion.php"; int CFeiXin::FX_SendMessage(char* _usrname,char* _password,char* _number,char* _sms) { int ret = 0; char chbuf[FX_MAXSIZE] = {0}; sprintf(chbuf,"%s?u=%s&p=%s&to=%s&m=%s",m_url.c_str(),_usrname,_password,\ _number,_sms); ret = FX_SendHttp(chbuf); return ret; } //发送http请求 int CFeiXin::FX_SendHttp(char* _url) { int ret = 0; HINTERNET hSession = InternetOpen("UrlFeiXin", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); char strresult[256] = {0}; if(hSession != NULL) { HINTERNET hHttp = InternetOpenUrl(hSession, _url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0); if (hHttp != NULL) { BYTE Temp[FX_MAXSIZE]; ULONG Number = 1; while (Number > 0) { InternetReadFile(hHttp, Temp, FX_MAXSIZE - 1, &Number); Temp[Number] = '\0'; sprintf(strresult,"%s", Temp); //解析返回码 std::string str = strresult; int startpos = str.find_first_of(":")+1; int endpos = str.find_first_of(","); std::string strcode = str.substr(startpos,endpos-startpos); ret = atol(strcode.c_str()); } InternetCloseHandle(hHttp); hHttp = NULL; } InternetCloseHandle(hSession); hSession = NULL; } return ret; }
三、main函数调用发送3d
#include <iostream> #include "..\FeiXin\FeiXin.h" using namespace std; int main(int argc, char* argv[]) { // DWORD ret = CFeiXin::FX_SendMessage("飞信登陆手机号","飞信登陆密码","接收飞信的手机号", "飞信内容"); if (ret != 0) { cout << "发送短信失败" << endl; } else { cout << "发送短信成功" << endl; } return 0; }
使用vs2010编译经过,源码以下:code
http://yunpan.cn/QzJ3VmLT9iFmY
访问密码请发我邮箱索取,个人邮箱是: