以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  高级功能研发区  (http://weistock.com/bbs/list.asp?boardid=5)
----  [转帖]飞信api源码  (http://weistock.com/bbs/dispbbs.asp?boardid=5&id=9730)

--  作者:z7c9
--  发布时间:2012/1/26 10:23:08
--  [转帖]飞信api源码
以下内容为程序代码:

1 <?php
2 /* Copyright 2010 princehaku
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Created on : 2010-11-18
17 * Last Update: 2011-12-06
18 * Author : princehaku
19 * Site : http://3haku.net
20 *
21 * 注意 : 请不要将此脚本用于商业用途..
22 * 此脚本完全是模拟了一个浏览器让用户自主操作,不存在破解或重打包客户端等行为。
23 * 此脚本以学习为目的,不涉及任何商业利益。任何企业和个人与此接口有关的商业行为,请与移动公司联系。
24 * 任何人使用此脚本而造成的不良后果,均由使用者承担,与此脚本的作者没有任何关系。
25 *
26 *
27 * 1.4fix
28 * 修复了移动修改jsessionid发生错误的问题
29 * 修复了cookie获取代码,按照rfc规范进行解析
30 * 修复了部分warning
31 *
32 * 1.3fix
33 * 感谢:
34 * 七子狴犴 指出的一个bug,修复了添加好友的时候姓名错误
35 * 追赶太阳 指出的一个bug,修复了cookie获取的代码
36 * 一路狂飙 提供的给自己发信的函数
37 */
38 define("DEBUG", 0);
39
40 if (DEBUG == 1) {
41 error_reporting(9);
42 } else {
43 error_reporting(0);
44 }
45
46 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
47 header("Cache-Control: no-cache, must-revalidate");
48 header("Pragma: no-cache");
49
50 /**用curl做的联网类
51 */
52 class httpconnector {
53 /**Curl类
54 *
55 */
56 private $curl;
57 /**cookie字符串
58 */
59 private $cookie;
60 /**源(用于最后结果调试)
61 */
62 private $sourceWmlStack = array();
63 /**得到源wml栈
64 */
65 public function getSource() {
66 return $this->sourceWmlStack;
67 }
68 /**get方式下载网页内容
69 *@param $url
70 *@return web conntent
71 */
72 public function get($url) {
73
74 $this->curl = curl_init();
75
76 curl_setopt($this->curl, CURLOPT_URL, $url);
77
78 // 设置header
79 curl_setopt($this->curl, CURLOPT_HEADER, 1);
80 curl_setopt($this->curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
81 curl_setopt($this->curl, CURLOPT_COOKIE, $this->cookie);
82
83 // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
84 curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
85
86 // 运行cURL,请求网页
87 $data = curl_exec($this->curl);
88 // 关闭URL请求
89 curl_close($this->curl);
90 // 找到cookie 放入cookiestring
91 preg_match_all("/Set-Cookie:(.*?);/", $data, $match, PREG_SET_ORDER);
92 foreach ($match as $r) {
93 if ($this->cookie != \'\') {
94     $this->cookie = $this->cookie . \';\';
95 }
96 if (isset($r[1])) {
97 $this->cookie .= trim(str_replace("\\r\\n", "", $r[1]));
98 }
99 }
100 //放入调试栈
101 array_push($this->sourceWmlStack, " [$url] " . $data);
102
103 return $data;
104
105 }
106
107 /**POST方式下载网页内容
108 *@param $url
109 *@param $params post的信息串
110 *@return web conntent
111 */
112 public function post($url, $params) {
113
114 $this->curl = curl_init();
115
116 curl_setopt($this->curl, CURLOPT_URL, $url);
117
118 // 设置header
119 curl_setopt($this->curl, CURLOPT_HEADER, 1);
120 curl_setopt($this->curl, CURLOPT_COOKIE, $this->cookie);
121 curl_setopt($this->curl, CURLOPT_POST, 1);
122 curl_setopt($this->curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
123 curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params);
124
125 // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
126 curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
127
128 // 运行cURL,请求网页
129 $data = curl_exec($this->curl);
130
131 // 关闭URL请求
132 curl_close($this->curl);
133 // 找到cookie 放入cookiestring
134 preg_match_all("/Set-Cookie:(.*?);/", $data, $match, PREG_SET_ORDER);
135
136 foreach ($match as $r) {
137 if ($this->cookie != \'\') {
138     $this->cookie = $this->cookie . \';\';
139 }
140 if (isset($r[1])) {
141 $this->cookie .= trim(str_replace("\\r\\n", "", $r[1]));
142 }
143 }
144
145 //放入调试栈
146 array_push($this->sourceWmlStack, " [$url] " . $data);
147
148 return $data;
149
150 }
151 }
152 /**飞信类
153 */
154 class fection {
155
156 private $jsession;
157
158 private $r;
159
160 private $httpconnector;
161 /**发送方手机号码
162 */
163 private $phonenum;
164 /**发送方飞信密码
165 */
166 private $pwd;
167 /**是否成功登陆
168 */
169 private $islogin = 0;
170 /**操作记录
171 */
172 private $status = array();
173
174 function track($action, $statu, $ph") {
176 $phone = $this->phonenum;
177 }
178 $r = array("action" => $action, "statu" => $statu, "phone" => $phone);
179 array_push($this->status, $r);
180 }
181 function __construct($phonenum, $pwd) {
182 $this->phonenum = $phonenum;
183 $this->pwd = $pwd;
184 $this->httpconnector = new httpconnector();
185 }
186 /**登陆飞信
187 */
188 function login() {
189 // 得到ssid
190 $data = $this->httpconnector->get(\'http://f.10086.cn/im/login/login.action\');
191 preg_match("/jsessionid=(.*?)[\\"\\?]/", $data, $r);
192 if (empty($r[1])) {
193 $this->track("login", "faild");
194 $this->islogin = 0;
195 return;
196 }
197 $this->jsession = $r[1];
198 // 效验是否需要验证码
199 preg_match("/verifycode.jpg\\?code=(.*?)\\"/", $data, $r);
200 if (isset($r[1])) {
201 $this->track("login", "need verify");
202 $this->islogin = 0;
203 return;
204 }
205 // 开始登陆
206 $data = $this->httpconnector->post(\'http://f.10086.cn/im/login/inputpasssubmit1.action;jsessiquery\'])) {
210 $this->track("login", "faild");
211 $this->islogin = 0;
212 return;
213 }
214 $r = explode("=", $r[\'query\']);
215 $this->t = $r[\'1\'];
216 if ($this->t == "") {
217 $this->track("login", "faild");
218 $this->islogin = 0;
219 return;
220 } else {
221 $this->track("login", "success");
222 $this->islogin = 1;
223 }
224
225 }
226 /**退出飞信
227 */
228 function logout() {
229 if ($this->islogin) {
230 $this->httpconnector->get("http://f.10086.cn/im/index/logoutsubmit.action;jsessionid=$this->jsession?t=$this->t");
231 }
232 }
233 /** 给自己发送短信
234 *
235 * @param mixed $msg
236 */
237 function sendToSelf($msg) {
238 if (!$this->islogin) {
239 return;
240 }
241
242 $data = $this->httpconnector->post("http://f.10086.cn/im/user/sendMsgToMyselfs.action?t=$this->t", "msg=$msg");
243
244 if ((int)strpos($data, "成功") > 10) {
245 $this->track("sendmessage", "success");
246 return;
247 }
248
249 $this->track("sendmessage", "faild");
250
251 }
252 /**
253 * 给某飞信id发送消息
254 *
255 * @param mixed $fid
256 * @param mixed $msg
257 * @param mixed $towho
258 */
259 function sendTofid($fid, $msg, $towho) {
260 if (!$this->islogin) {
261 return;
262 }
263 if ($towho == "") {
264 $towho = "0";
265 }
266 $data = $this->httpconnector->post("http://f.10086.cn/im/chat/sendMsg.action?t=$this->t&touserid=$fid", "msg=$msg&touchTextLength=&touchTitle=");
267
268 if ((int)strpos($data, "成功") > 10) {
269 $this->track("sendmessage", "success", $towho);
270 $this->savefidLocal($towho, $fid);
271 return;
272 }
273
274 $this->track("sendmessage", "faild", $towho);
275 }
276 /**发送飞信短信
277 *@param $fid 接收方的手机号码或者昵称
278 *@param $msg 消息正文
279 */
280 function send($towho, $msg) {
281 if (!$this->islogin) {
282 return;
283 }
284 $fid = $this->phonenum;
285 //如果不是给自己发送的转换uid
286 if ($towho != $this->phonenum) {
287 $fid = $this->getfidLocal($towho);
288 if ($fid == "") {
289 $fid = $this->getfidNet($towho);
290 }
291 }
292 if ($fid != $this->phonenum && $fid == "") {
293 $this->track("tofid", "faild", $towho);
294 return;
295 }
296 $data = "";
297
298 if ($towho == $this->phonenum) {
299 $this->sendToSelf($msg);
300 } else {
301 $this->sendTofid($fid, $msg, $towho);
302 }
303 }
304 /**添加用户为好友
305 */
306 function addfriend($phone, $name) {
307 if (!$this->islogin) {
308 return;
309 }
310
311 if ($name == "") {
312 $name = "haku";
313 }
314
315 $data = $this->httpconnector->post("http://f.10086.cn/im/user/insertfriendsubmit.action?t=$this->t", "nickname=$name&number=$phone&type=0");
316
317 if ((int)strpos($data, "对不起,") > 0) {
318 $this->track("addfriend", "faild", $phone);
319 return;
320 }
321
322 $this->track("addfriend", "success", $phone);
323 }
324 /**用于将手机号或者飞信号或者昵称转换为飞信id
325 * param $val
326 */
327 function getfidNet($val) {
328 if (!$this->islogin) {
329 return;
330 }
331 $data = $this->httpconnector->post("http://f.10086.cn/im/index/searchOtherInfoList.action?t=$this->t", "searchText=$val");
332
333 $pos1 = (int)strpos($data, "touserid=");
334 $pos2 = (int)strpos($data, "&", $pos1);
335 $uid = "";
336 if ($pos1 > 0 && $pos2 > 0) {
337 $uid = substr($data, $pos1 + 9, $pos2 - $pos1 - 9);
338 }
339
340 return $uid;
341 }
342 /**用于从本地将手机号或者飞信号或者昵称转换为飞信id
343 * param $val
344 */
345 function getfidLocal($val) {
346 $data = file_get_contents("pafetion.cache");
347 preg_match("/$val==####==(\\d*)/", $data, $r);
348
349 if (@$r[1] == null) {
350 $r[1] = "";
351 }
352 return $r[1];
353 }
354 function savefidLocal($val, $fid) {
355 if ($this->getfidLocal($val) != "") {
356 return;
357 }
358 $data = file_get_contents("pafetion.cache");
359 $data = $data . "$val==####==$fid\\n";
360 file_put_contents("pafetion.cache", $data);
361 return;
362 }
363 /**输出结果至xml
364 *
365 */
366 function toXml() {
367 header("Content-Type: text/xml");
368 echo "<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>\\r\\n";
369 echo "<pafetion>";
370 echo "<status>";
371 foreach ($this->status as $i => $j) {
372 echo "<action>" . $j[\'action\'] . "</action>";
373 echo "<statu>" . $j[\'statu\'] . "</statu>";
374 echo "<phone><![CDATA[" . $j[\'phone\'] . "]]></phone>";
375 }
376 echo "</status>";
377 if (DEBUG == 1) {
378 echo "<sources>";
379 foreach ($this->httpconnector->getSource() as $i => $j) {
380 echo "<source><![CDATA[";
381 echo ($j);
382 echo "]]></source>";
383 }
384 echo "</sources>";
385 }
386 echo "</pafetion>";
387 }
388 }
389
390 $phone = @$_GET["phone"];
391 $pwd = @$_GET["pwd"];
392 $to = @$_GET["to"];
393 $msg = @$_GET[\'msg\'];
394 $add = @$_GET[\'add\'];
395 if (@$_GET[\'u\'] == "") {
396 @$msg = iconv("gbk", "UTF-8", $msg);
397 }
398 if (!($phone && $pwd && ($msg && $to || $add))) {
399 die("wrong parameters, please refer to <a href=\'http://3haku.net/tag/pafetion\'>princehaku</a>");
400 }
401     
402 $fection = new fection($phone, $pwd);
403 $fection->login();
404 //添加好友的操作
405 if ($add != "") {
406 $res = explode(",", $add);
407 foreach ($res as $i => $adds) {
408 $fection->addfriend($adds, @$_GET[\'name\']);
409 }
410 } else {
411 //发送短信的操作
412 $res = explode(",", $to);
413 foreach ($res as $i => $tos) {
414 $fection->send($tos, $msg);
415 }
416 }
417
418 $fection->logout();
419 //打印结果
420 $fection->toXml();
421 ?>

--  作者:z7c9
--  发布时间:2012/1/26 10:24:01
--  
/* Copyright 2010 princehaku
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Created on : 2010-11-18
* Last Update: 2011-12-06
* Author : princehaku
* Site : http://3haku.net
*
* 注意 : 请不要将此脚本用于商业用途..
* 此脚本完全是模拟了一个浏览器让用户自主操作,不存在破解或重打包客户端等行为。
* 此脚本以学习为目的,不涉及任何商业利益。任何企业和个人与此接口有关的商业行为,请与移动公司联系。
* 任何人使用此脚本而造成的不良后果,均由使用者承担,与此脚本的作者没有任何关系。
*
*
* 1.4fix
* 修复了移动修改jsessionid发生错误的问题
* 修复了cookie获取代码,按照rfc规范进行解析
* 修复了部分warning
*
* 1.3fix
* 感谢:
* 七子狴犴 指出的一个bug,修复了添加好友的时候姓名错误
* 追赶太阳 指出的一个bug,修复了cookie获取的代码
* 一路狂飙 提供的给自己发信的函数
*/
define("DEBUG", 0);

if (DEBUG == 1) {
error_reporting(9);
} else {
error_reporting(0);
}

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

/**用curl做的联网类
*/
class httpconnector {
/**Curl类
*
*/
private $curl;
/**cookie字符串
*/
private $cookie;
/**源(用于最后结果调试)
*/
private $sourceWmlStack = array();
/**得到源wml栈
*/
public function getSource() {
return $this->sourceWmlStack;
}
/**get方式下载网页内容
*@param $url
*@return web conntent
*/
public function get($url) {

$this->curl = curl_init();

curl_setopt($this->curl, CURLOPT_URL, $url);

// 设置header
curl_setopt($this->curl, CURLOPT_HEADER, 1);
curl_setopt($this->curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($this->curl, CURLOPT_COOKIE, $this->cookie);

// 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);

// 运行cURL,请求网页
$data = curl_exec($this->curl);
// 关闭URL请求
curl_close($this->curl);
// 找到cookie 放入cookiestring
preg_match_all("/Set-Cookie:(.*?);/", $data, $match, PREG_SET_ORDER);
foreach ($match as $r) {
if ($this->cookie != \'\') {
$this->cookie = $this->cookie . \';\';
}
if (isset($r[1])) {
$this->cookie .= trim(str_replace("\\r\\n", "", $r[1]));
}
}
//放入调试栈
array_push($this->sourceWmlStack, " [$url] " . $data);

return $data;

}

/**POST方式下载网页内容
*@param $url
*@param $params post的信息串
*@return web conntent
*/
public function post($url, $params) {

$this->curl = curl_init();

curl_setopt($this->curl, CURLOPT_URL, $url);

// 设置header
curl_setopt($this->curl, CURLOPT_HEADER, 1);
curl_setopt($this->curl, CURLOPT_COOKIE, $this->cookie);
curl_setopt($this->curl, CURLOPT_POST, 1);
curl_setopt($this->curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params);

// 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);

// 运行cURL,请求网页
$data = curl_exec($this->curl);

// 关闭URL请求
curl_close($this->curl);
// 找到cookie 放入cookiestring
preg_match_all("/Set-Cookie:(.*?);/", $data, $match, PREG_SET_ORDER);

foreach ($match as $r) {
if ($this->cookie != \'\') {
$this->cookie = $this->cookie . \';\';
}
if (isset($r[1])) {
$this->cookie .= trim(str_replace("\\r\\n", "", $r[1]));
}
}

//放入调试栈
array_push($this->sourceWmlStack, " [$url] " . $data);

return $data;

}
}
/**飞信类
*/
class fection {

private $jsession;

private $r;

private $httpconnector;
/**发送方手机号码
*/
private $phonenum;
/**发送方飞信密码
*/
private $pwd;
/**是否成功登陆
*/
private $islogin = 0;
/**操作记录
*/
private $status = array();

function track($action, $statu, $ph") {
$phone = $this->phonenum;
}
$r = array("action" => $action, "statu" => $statu, "phone" => $phone);
array_push($this->status, $r);
}
function __construct($phonenum, $pwd) {
$this->phonenum = $phonenum;
$this->pwd = $pwd;
$this->httpconnector = new httpconnector();
}
/**登陆飞信
*/
function login() {
// 得到ssid
$data = $this->httpconnector->get(\'http://f.10086.cn/im/login/login.action\');
preg_match("/jsessionid=(.*?)[\\"\\?]/", $data, $r);
if (empty($r[1])) {
$this->track("login", "faild");
$this->islogin = 0;
return;
}
$this->jsession = $r[1];
// 效验是否需要验证码
preg_match("/verifycode.jpg\\?code=(.*?)\\"/", $data, $r);
if (isset($r[1])) {
$this->track("login", "need verify");
$this->islogin = 0;
return;
}
// 开始登陆
$data = $this->httpconnector->post(\'http://f.10086.cn/im/login/inputpasssubmit1.action;jsessiquery\'])) {
$this->track("login", "faild");
$this->islogin = 0;
return;
}
$r = explode("=", $r[\'query\']);
$this->t = $r[\'1\'];
if ($this->t == "") {
$this->track("login", "faild");
$this->islogin = 0;
return;
} else {
$this->track("login", "success");
$this->islogin = 1;
}

}
/**退出飞信
*/
function logout() {
if ($this->islogin) {
$this->httpconnector->get("http://f.10086.cn/im/index/logoutsubmit.action;jsessionid=$this->jsession?t=$this->t");
}
}
/** 给自己发送短信
*
* @param mixed $msg
*/
function sendToSelf($msg) {
if (!$this->islogin) {
return;
}

$data = $this->httpconnector->post("http://f.10086.cn/im/user/sendMsgToMyselfs.action?t=$this->t", "msg=$msg");

if ((int)strpos($data, "成功") > 10) {
$this->track("sendmessage", "success");
return;
}

$this->track("sendmessage", "faild");

}
/**
* 给某飞信id发送消息
*
* @param mixed $fid
* @param mixed $msg
* @param mixed $towho
*/
function sendTofid($fid, $msg, $towho) {
if (!$this->islogin) {
return;
}
if ($towho == "") {
$towho = "0";
}
$data = $this->httpconnector->post("http://f.10086.cn/im/chat/sendMsg.action?t=$this->t&touserid=$fid", "msg=$msg&touchTextLength=&touchTitle=");

if ((int)strpos($data, "成功") > 10) {
$this->track("sendmessage", "success", $towho);
$this->savefidLocal($towho, $fid);
return;
}

$this->track("sendmessage", "faild", $towho);
}
/**发送飞信短信
*@param $fid 接收方的手机号码或者昵称
*@param $msg 消息正文
*/
function send($towho, $msg) {
if (!$this->islogin) {
return;
}
$fid = $this->phonenum;
//如果不是给自己发送的转换uid
if ($towho != $this->phonenum) {
$fid = $this->getfidLocal($towho);
if ($fid == "") {
$fid = $this->getfidNet($towho);
}
}
if ($fid != $this->phonenum && $fid == "") {
$this->track("tofid", "faild", $towho);
return;
}
$data = "";

if ($towho == $this->phonenum) {
$this->sendToSelf($msg);
} else {
$this->sendTofid($fid, $msg, $towho);
}
}
/**添加用户为好友
*/
function addfriend($phone, $name) {
if (!$this->islogin) {
return;
}

if ($name == "") {
$name = "haku";
}

$data = $this->httpconnector->post("http://f.10086.cn/im/user/insertfriendsubmit.action?t=$this->t", "nickname=$name&number=$phone&type=0");

if ((int)strpos($data, "对不起,") > 0) {
$this->track("addfriend", "faild", $phone);
return;
}

$this->track("addfriend", "success", $phone);
}
/**用于将手机号或者飞信号或者昵称转换为飞信id
* param $val
*/
function getfidNet($val) {
if (!$this->islogin) {
return;
}
$data = $this->httpconnector->post("http://f.10086.cn/im/index/searchOtherInfoList.action?t=$this->t", "searchText=$val");

$pos1 = (int)strpos($data, "touserid=");
$pos2 = (int)strpos($data, "&", $pos1);
$uid = "";
if ($pos1 > 0 && $pos2 > 0) {
$uid = substr($data, $pos1 + 9, $pos2 - $pos1 - 9);
}

return $uid;
}
/**用于从本地将手机号或者飞信号或者昵称转换为飞信id
* param $val
*/
function getfidLocal($val) {
$data = file_get_contents("pafetion.cache");
preg_match("/$val==####==(\\d*)/", $data, $r);

if (@$r[1] == null) {
$r[1] = "";
}
return $r[1];
}
function savefidLocal($val, $fid) {
if ($this->getfidLocal($val) != "") {
return;
}
$data = file_get_contents("pafetion.cache");
$data = $data . "$val==####==$fid\\n";
file_put_contents("pafetion.cache", $data);
return;
}
/**输出结果至xml
*
*/
function toXml() {
header("Content-Type: text/xml");
echo "\\r\\n";
echo "";
echo "";
foreach ($this->status as $i => $j) {
echo "" . $j[\'action\'] . "";
echo "" . $j[\'statu\'] . "";
echo "";
}
echo "
";
if (DEBUG == 1) {
echo "";
foreach ($this->httpconnector->getSource() as $i => $j) {
echo "<![CDATA[";
echo ($j);
echo "]]>";
}
echo "
";
}
echo "
";
}
}

$phone = @$_GET["phone"];
$pwd = @$_GET["pwd"];
$to = @$_GET["to"];
$msg = @$_GET[\'msg\'];
$add = @$_GET[\'add\'];
if (@$_GET[\'u\'] == "") {
@$msg = iconv("gbk", "UTF-8", $msg);
}
if (!($phone && $pwd && ($msg && $to || $add))) {
die("wrong parameters, please refer to princehaku");
}

$fection = new fection($phone, $pwd);
$fection->login();
//添加好友的操作
if ($add != "") {
$res = explode(",", $add);
foreach ($res as $i => $adds) {
$fection->addfriend($adds, @$_GET[\'name\']);
}
} else {
//发送短信的操作
$res = explode(",", $to);
foreach ($res as $i => $tos) {
$fection->send($tos, $msg);
}
}

$fection->logout();
//打印结果
$fection->toXml();
?>