1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
if ($argc<>5){
	echo "Usage:\n";
	echo "\t$ php ".$argv[0]." from pass to content \n";
	echo "\tfrom:your Fetion Number\n";
	echo "\tpass:your Fetion password\n";
	echo "\tto:The phone number who recive the message\n";
	echo "\tcontent:message content\n";
	exit;
}
$fetion= new PHPFetion($argv[1],$argv[2]);
$fetion->send($argv[3],$argv[4]);
/**
 * PHP飞信发送类
 * @author quanhengzhuang &lt;phpqhz@gmail.com>
 * @version 1.0.0
 */
class PHPFetion {
	
	/**
	 * 发送者手机号
	 * @var string
	 */
	protected $_mobile;
	
	/**
	 * 飞信密码
	 * @param string
	 */
	protected $_password;
	
	/**
	 * Cookie路径
	 * @param string
	 */
	protected $_cookie;
	
	/**
	 * 构造函数
	 * @param string $mobile 手机号(登录者)
	 * @param string $password 飞信密码
	 */
	public function __construct($mobile, $password) {
		if($mobile === '' || $password === '') {
			return false;
		}
		
		$this->_mobile = $mobile;
		$this->_password = $password;
		$this->_cookie = dirname(__FILE__).'/'.$mobile.'_cookie.txt';
		
		$this->_login();
	}
	
	/**
	 * 向指定的手机号发送飞信
	 * @param string $mobile 手机号(接收者)
	 * @param string $message 短信内容
	 * @return string
	 */
	public function send($mobile, $message) {
		if($mobile == $this->_mobile) {
			// 给自己发短信
			return $this->_toMyself($message);
		} else {
			// 给好友发短信
			$uid = $this->_getUid($mobile);
			return $this->_toUid($uid, $message);
		}
	}
	
	/**
	 * 登录
	 * @return string
	 */
	protected function _login() {
		$post = array(
			'm' => $this->_mobile,
			'pass' => $this->_password,
			'loginstatus' => 1,
		);
		
		$curl = curl_init('http://f.10086.cn/im/login/inputpasssubmit1.action');
		curl_setopt($curl, CURLOPT_HEADER, 0);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($curl, CURLOPT_COOKIEJAR, $this->_cookie);
		curl_setopt($curl, CURLOPT_POST, 1);
		curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
		$result = curl_exec($curl);
		curl_close($curl);
		
		return $result;
	}
	
	/**
	 * 获取飞信ID
	 * @param string $mobile 手机号
	 * @return string
	 */
	protected function _getUid($mobile) {
		$post = array(
			'searchText' => $mobile,
		);
		
		$curl = curl_init('http://f.10086.cn/im/index/searchOtherInfoList.action');
		curl_setopt($curl, CURLOPT_HEADER, 0);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($curl, CURLOPT_COOKIEFILE, $this->_cookie);
		curl_setopt($curl, CURLOPT_POST, 1);
		curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
		$result = curl_exec($curl);
		curl_close($curl);
		
		// 匹配
		preg_match('/toinputMsg\.action\?touserid=(\d+)/si', $result, $matches);
		
		return isset($matches[1]) ? $matches[1] : '';
	}
	
	/**
	 * 向好友发送飞信
	 * @param string $uid 飞信ID
	 * @param string $message 短信内容
	 * @return string
	 */
	protected function _toUid($uid, $message) {
		$post = array(
			'msg' => $message,
		);
		
		$curl = curl_init('http://f.10086.cn/im/chat/sendMsg.action?touserid='.$uid);
		curl_setopt($curl, CURLOPT_HEADER, 0);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($curl, CURLOPT_COOKIEFILE, $this->_cookie);
		curl_setopt($curl, CURLOPT_POST, 1);
		curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
		$result = curl_exec($curl);
		curl_close($curl);
		
		return $result;
	}
	
	/**
	 * 给自己发飞信
	 * @param string $message
	 * @return string
	 */
	protected function _toMyself($message) {
		$post = array(
			'msg' => $message,
		);
		
		$curl = curl_init('http://f.10086.cn/im/user/sendMsgToMyselfs.action');
		curl_setopt($curl, CURLOPT_HEADER, 0);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($curl, CURLOPT_COOKIEFILE, $this->_cookie);
		curl_setopt($curl, CURLOPT_POST, 1);
		curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
		$result = curl_exec($curl);
		curl_close($curl);
		
		return $result;
	}
	
	/**
	 * 退出飞信
	 * @return string
	 */
	protected function _logout() {
		$curl = curl_init('http://f.10086.cn/im/index/logoutsubmit.action?t=30310469084920296');
		curl_setopt($curl, CURLOPT_HEADER, 0);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($curl, CURLOPT_COOKIEFILE, $this->_cookie);
		$result = curl_exec($curl);
		curl_close($curl);
		
		return $result;
	}

	/**
	 * 析构函数
	 */
	public function __destruct() {
		// 退出飞信
		$this->_logout();
		
		// 删除Cookie文件
		unlink($this->_cookie);
	}
	
}

里面大部分代码版权归源作者所有,我只不过加了几行,这坨代码的作用就是可以让你在shell下发送短信,当然只限于移动飞信用户,用的着的话就收下吧 SMSend.rar