class:

<?php
/*** PHP飞信发送类** @author quanhengzhuang <blog.quanhz.com>* @version 1.5.0*/
class PHPFetion
{/*** 发送者手机号* @var string*/protected $_mobile;/*** 飞信密码* @var string*/protected $_password;/*** Cookie字符串* @var string*/protected $_cookie = '';/*** Uid缓存* @var array*/protected $_uids = array();/*** csrfToken* @var string*/protected $_csrfToten = null;/*** 构造函数* @param string $mobile 手机号(登录者)* @param string $password 飞信密码*/public function __construct($mobile, $password){if ($mobile === '' || $password === ''){return;}$this->_mobile = $mobile;$this->_password = $password;$this->_login();}/*** 析构函数*/public function __destruct(){$this->_logout();}/*** 登录* @return string*/protected function _login(){$uri = '/huc/user/space/login.do?m=submit&fr=space';$data = 'mobilenum='.$this->_mobile.'&password='.urlencode($this->_password);$result = $this->_postWithCookie($uri, $data);//解析Cookiepreg_match_all('/.*?\r\nSet-Cookie: (.*?);.*?/si', $result, $matches);if (isset($matches[1])){$this->_cookie = implode('; ', $matches[1]);}$result = $this->_postWithCookie('/im/login/cklogin.action', '');return $result;}/*** 向指定的手机号发送飞信* @param string $mobile 手机号(接收者)* @param string $message 短信内容* @return string*/public function send($mobile, $message){if ($message === ''){return '';}//判断是给自己发还是给好友发if ($mobile == $this->_mobile){return $this->_toMyself($message);}else{$uid = $this->_getUid($mobile);return $uid === '' ? '' : $this->_toUid($uid, $message);}}/*** 获取飞信ID* @param string $mobile 手机号* @return string*/protected function _getUid($mobile){if (empty($this->_uids[$mobile])){$uri = '/im/index/searchOtherInfoList.action';$data = 'searchText='.$mobile;$result = $this->_postWithCookie($uri, $data);//匹配preg_match('/toinputMsg\.action\?touserid=(\d+)/si', $result, $matches);$this->_uids[$mobile] = isset($matches[1]) ? $matches[1] : '';}return $this->_uids[$mobile];}/*** 获取csrfToken,给好友发飞信时需要这个字段* @param string $uid 飞信ID* @return string*/protected function _getCsrfToken($uid){if ($this->_csrfToten === null){$uri = '/im/chat/toinputMsg.action?touserid='.$uid;$result = $this->_postWithCookie($uri, '');preg_match('/name="csrfToken".*?value="(.*?)"/', $result, $matches);$this->_csrfToten = isset($matches[1]) ? $matches[1] : '';}return $this->_csrfToten;}/*** 向好友发送飞信* @param string $uid 飞信ID* @param string $message 短信内容* @return string*/protected function _toUid($uid, $message){$uri = '/im/chat/sendMsg.action?touserid='.$uid;$csrfToken = $this->_getCsrfToken($uid);$data = 'msg='.urlencode($message).'&csrfToken='.$csrfToken;$result = $this->_postWithCookie($uri, $data);return $result;}/*** 给自己发飞信* @param string $message* @return string*/protected function _toMyself($message){$uri = '/im/user/sendMsgToMyselfs.action';$result = $this->_postWithCookie($uri, 'msg='.urlencode($message));return $result;}/*** 退出飞信* @return string*/protected function _logout(){$uri = '/im/index/logoutsubmit.action';$result = $this->_postWithCookie($uri, '');return $result;}/*** 携带Cookie向f.10086.cn发送POST请求* @param string $uri* @param string $data*/protected function _postWithCookie($uri, $data){$fp = fsockopen('f.10086.cn', 80);fputs($fp, "POST $uri HTTP/1.1\r\n");fputs($fp, "Host: f.10086.cn\r\n");fputs($fp, "Cookie: {$this->_cookie}\r\n");fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");fputs($fp, "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1\r\n");fputs($fp, "Content-Length: ".strlen($data)."\r\n");fputs($fp, "Connection: close\r\n\r\n");fputs($fp, $data);$result = '';while (!feof($fp)){$result .= fgets($fp);}fclose($fp);return $result;}}

调用方式:
<?php
require '../lib/PHPFetion.php';$fetion = new PHPFetion('xxxxxxxxxxx', 'xxxxxxxxxxxx');   // 手机号、飞信密码
$fetion->send('xxxxxxxxxxxxxxxx', '自动程序,收到请回复!'); // 接收人手机号、飞信内容
												

php利用飞信api给好友发短信相关推荐

  1. 使用飞信定时给好友发短信

    飞信的定时短信功能应该在2008年底都推出了吧,园子一直也没有用过.今天试了下发现非常好用,本文简单分享下飞信定时短信的使用方法. 定时发送短信的好处 在朋友生日的时候,有时候为了把发送祝福的时间卡在 ...

  2. 使用聚合数据API查询快递数据-短信验证码-企业核名

    有位朋友让我给他新开的网站帮忙做几个小功能,如下: 输入快递公司.快递单号,查询出这个快件的所有动态(从哪里出发,到了哪里) 在注册.登录等场景下的手机验证码(要求有一定的防刷策略) 通过输入公司名的 ...

  3. 系统监控:linux命令行-飞信客户端发送免费报警短信

    linux命令行下用Fetion飞信发送免费短信 一.最新版本2009 通过linux命令行来发送短信的方法,觉得甚是好用,适用运维监控.这里向大家推荐的是飞信机器人的软件,支持linux.命令行下的 ...

  4. Total Control脚本功能JS API之获取设备短信内容

    每一个设备对象都对应了 Total Control 中已连接的一台手机设备. 通过设备对象,用户可以获取到手机设备的各种属性,以及使用控制接口对设备进行各种操作,比如 打开或关闭指定APP,发送短信等 ...

  5. c++利用飞信API免费发短信

    一.飞信接口介绍 该飞信接口是基于HTTP协议的接口,可以在任何支持HTTP协议的程序中使用.一些不能用PHP的朋友们可以使用此飞信接口,另外可以避免飞信不断升级导致的源程序不可用.本接口同时支持HT ...

  6. java 利用飞信,Java利用飞信API给自己或者好友发信息

    Java利用飞信接口,可以给好友或者自己发送信息. 1.[代码][Java]代码 package com.crawler.core; import java.io.IOException; impor ...

  7. jeecg 手机注册 阿里云短信API 【 阿里云短信发送验证码 平台配置和项目中使用】

    文章目录 jeecg 项目效果展示 短息通知页面入口 代码中调用短信api 配置和代码 API中的重要参数配置项: 阿里控制台注册 注册签名 注册短信模板  阿里云短信发送验证码配置和项目使用 je ...

  8. 采用API方式发送,接收短信(嘉信)

    API方式: 首选要在jx01移动代理服务器中进行如下配置 系统管理-->接口管理-->短信接口模块增加如下配置信息 接口编码:   接口名称:   接口类型: DB接口 API接口   ...

  9. uni-app中使用native.js调用android API实现双卡发送短信

    uni-app 是一个使用 Vue.js 开发所有前端应用的框架,开发者编写一套代码,可发布到iOS.Android.H5.以及各种小程序(微信/支付宝/百度/头条/QQ/钉钉)等多个平台官网地址 因 ...

最新文章

  1. 自学成才翁_如何发挥自学成才的内在游戏
  2. 链表问题4——反转单向链表
  3. token验证_如何利用 C# 爬取带 Token 验证的网站数据?
  4. Taro+react开发(61) 一条虚线
  5. Java常见排序算法之堆排序
  6. Qt:Qt实现飞秋拦截助手—ARP攻击
  7. JEECG开源团队,欢迎技术爱好者加入
  8. spring boot配置虚拟路径(替代docBase配置)访问本地图片
  9. 一起谈.NET技术,用NuGet掌管你的Visual Studio扩展
  10. 「JXOI2018」游戏
  11. 高斯光束matlab 仿真,高斯光束的matlab仿真
  12. Frsky X9D Plus遥控器和 Frisky R8 Pro接收机对频
  13. 计算机网络实践报告--网络安全
  14. 使用支付宝小程序input组件的坑
  15. c语言输入abc求方程的根,编写程序,输入系数abc,计算任意二次方根的实根
  16. 搭建ARM交叉编译环境
  17. 重置或者修改mysql的root密码
  18. Combined attach
  19. linux操作系统-----用户与组管理(3)
  20. css 高度塌陷_css中父元素高度塌陷是什么意思,如何解决?(附代码)

热门文章

  1. 基于Vivado MIG IP核的DDR3读写实验(top_rom_ddr/ddr_top)
  2. 有一家做BPM的公司叫K2,Gartner和IDC都说好!
  3. 餐馆点餐系统(Java GUI + mysql)
  4. python 文件上传之---断点续传
  5. mysql 字符串截取
  6. Kibana KQL查询语法
  7. Android中FlowLayout的使用方法,监控布局大小并设置页面高度
  8. Python程序员都知道的5个彩蛋
  9. js如何运行python代码_手把手教你如何使用Python执行js代码
  10. 龙芯3a5000部署nacos 1.4低版本方法