<?php
/**
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*
* @author c.young@xicabin
* @license GPL
* @version 1.0
*/
Header("Expires: Mon, 05 June 2001 05:06:07 GMT");
Header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
Header('Cache-Control: pre-check=0, post-check=0, max-age=0');
Header("Cache-Control: no-cache, must-revalidate");
Header("Pragma: no-cache");
define('FETION_URL', 'http://221.130.44.194/ht/sd.aspx');
define('FETION_LOGIN_URL', 'https://nav.fetion.com.cn/ssiportal/SSIAppSignIn.aspx');
define('FETION_CONFIG_URL', 'http://nav.fetion.com.cn/nav/getsystemconfig.aspx');
define('FETION_SIPP', 'SIPP');
static $fetion_proxy = null;
static $fetion_debug = false;
/**
* generate guid for windows / *nix
*/
function guid(){
if (function_exists('com_create_guid')){
return com_create_guid();
}else{
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid = chr(123)// "{"
.substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12)
.chr(125);// "}"
return $uuid;
}
}
/**
* debug output
*
* @msg message
* @data addtional data
*/
function fetion_debug($msg, $data = null) {
global $fetion_debug;
if ($fetion_debug) {
print "[*] $msg\r\n";
if (!empty($data)) {
print_r($data);
}
}
}
/**
* create sip package
*
* @invite sip invite
* @fields array of fields
* @arg argument to send
*/
function fetion_sip_create($invite, $fields, $arg = '') {
$sip = $invite."\r\n";
foreach ($fields as $k=>$v) {
$sip .= "$k: $v\r\n";
}
$sip .= "L: ".strval(strlen($arg))."\r\n\r\n{$arg}";
return $sip;
}
/**
* create a curl handle with fetion option
*
* @url url
* @ssic user identification
* @post data to post
*/
function fetion_curl_init($url, $ssic = null, $post = null) {
// create a new guid, and keep it !
static $guid = null;
if ($guid == null) {
$guid = strtolower(trim(guid(), "{}"));
}
// set headers, e.g. pragma
$headers = array('Content-Type: application/oct-stream', 'Pragma: xz4BBcV'.$guid);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'IIC2.0/PC 3.2.0540');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// ssic
if ($ssic != null) {
curl_setopt($ch, CURLOPT_COOKIE, "ssic=$ssic");
}
// post data
if ($post != null) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
// proxy
global $fetion_proxy;
if ($fetion_proxy != null) {
curl_setopt($ch, CURLOPT_PROXY, $fetion_proxy);
}
return $ch;
}
/**
* run a curl query
*
* @see fetion_curl_init
*/
function fetion_curl_exec($url, $ssic = null, $post = null) {
$ch = fetion_curl_init($url, $ssic, $post);
$succeed = curl_exec($ch);
if (!$succeed) {
error_log(curl_error($ch));
}
curl_close($ch);
return $succeed;
}
/**
* login
*
* @mobileno mobile number
* @pwd password
*/
function fetion_login($mobileno, $pwd) {
$login_url = FETION_LOGIN_URL."?mobileno=$mobileno&pwd=$pwd";
$ssic_regex = '/ssic\s+(.*)/s';
$sid_regex = '/sip:(\d+)@(.+);/s';// sid@domain
$cookie_file = date('YmdHis').'_cookie.txt';// create a tmp file to save cookie
$return_val = false;
$ch = fetion_curl_init($login_url, null, null);
// do not verify host
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// save cookie for further process
file_put_contents($cookie_file, '');
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
$succeed = curl_exec($ch);
// close first, in order to make cookie file written
curl_close($ch);
fetion_debug("login to nav.fetion.com.cn");
if (!$succeed) {
error_log(curl_error($ch));
return false;
}
// get ssic from cookie
$ssic = false;
$matches = array();
if (!preg_match($ssic_regex, file_get_contents($cookie_file), $matches)) {
error_log("Fetion Error: No ssic found in cookie");
return false;
}
$ssic = trim($matches[1]);
fetion_debug("ssic: ".substr($ssic, 0, 10)."...");
// get other login info from output
$result_xml = simplexml_load_string($succeed);
$return_val = array(
'ssic' => $ssic,
'status-code' => strval($result_xml['status-code']),
'uri' => strval($result_xml->user['uri']),
'mobile-no' => strval($result_xml->user['mobile-no']),
'user-status' => strval($result_xml->user['user-status'])
);
// extract sid and domain for further use
if (preg_match($sid_regex, $return_val['uri'], $matches)) {
$return_val['sid'] = $matches[1];
$return_val['domain'] = $matches[2];
}
fetion_debug("sid: {$return_val['sid']}");
unlink($cookie_file);
return $return_val;
}
/**
* get fetion system config, not used
*/
function fetion_get_system_config() {
$post_fields = '<config><client type="PC" version="3.2.0540" platform="W5.1" /><client-config version="0" /></config>';
return fetion_curl_exec(FETION_CONFIG_URL, null, $post_fields);
}
/**
* hex to binary
*
* @hex string hex code
*/
function fetion_hex2bin($hex) {
$bin = '';
$len = strlen($hex);
for ($I = 0; $I < $len; $I += 2) {
$bin .= chr(hexdec(substr($hex, $I, 2)));
}
return $bin;
}
/**
* get hash password
*
* @password real password
*/
function fetion_hash_password($password) {
// in fact, salt is constant value
$salt = chr(0x77).chr(0x7A).chr(0x6D).chr(0x03);
$src = $salt.hash('sha1', $password, true);
return strtoupper(bin2hex($salt.sha1($src, true)));
}
/**
* create a random cnonce
*/
function fetion_calc_cnonce() {
return sprintf("%04X%04X%04X%04X%04X%04X%04X%04X",
rand() & 0xFFFF, rand() & 0xFFFF, rand() & 0xFFFF,
rand() & 0xFFFF, rand() & 0xFFFF, rand() & 0xFFFF,
rand() & 0xFFFF, rand() & 0xFFFF);
}
/**
* get salt from real password
*
* @password real password
*/
function fetion_calc_salt($password) {
return substr(fetion_hash_password($password), 0, 8);
}
/**
* calculate response
*
* @sid fetion id
* @domain domain
* @password real password
* @nonce nonce from server
* @cnonce cnonce
*/
function fetion_calc_response($sid, $domain, $password, $nonce, $cnonce) {
$password = fetion_hash_password($password);
$str = fetion_hex2bin(substr($password, 8));
$key = sha1("$sid:$domain:$str", true);
$h1 = strtoupper(md5("$key:$nonce:$cnonce"));
$h2 = strtoupper(md5("REGISTER:$sid"));
$res = strtoupper(md5("$h1:$nonce:$h2"));
return $res;
}
/**
* get url with next request number
*
* @t i don't known
*/
function fetion_next_url($t = 's') {
static $seq = 0;
++$seq;
return FETION_URL."?t=$t&i=$seq";
}
/**
* get next call id
*/
function fetion_next_call() {
static $call = 0;
++$call;
return $call;
}
/**
* register to server
*
* @ssic user identification
* @sid fetion id
* @domain domain
* @password real password
*/
function fetion_http_register($ssic, $sid, $domain, $password) {
$nonce_regex = '/nonce="(\w+)"/s';
$ok_regex = '/OK/s';
$arg = '<args><device type="PC" version="44" client-version="3.2.0540" />';
$arg .= '<caps value="simple-im;im-session;temp-group;personal-group" />';
$arg .= '<event
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【项目资源】:包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。【项目质量】:所有源码都经过严格测试,可以直接运行。功能在确认正常工作后才上传。【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。【附加价值】:项目具有较高的学习借鉴价值,也可直接拿来修改复刻。对于有一定基础或热衷于研究的人来说,可以在这些基础代码上进行修改和扩展,实现其他功能。【沟通交流】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。鼓励下载和使用,并欢迎大家互相学习,共同进步。
资源推荐
资源详情
资源评论
收起资源包目录
基于HTML实现其他类别网站_PHP用飞信接口免费发短信源码 1.0_fetion(HTML源码+数据集+项目使用说明).rar (4个子文件)
[其他类别]PHP用飞信接口免费发短信源码 1.0_fetion
fetion
reset.css 2KB
fetion
fetion.php 13KB
index.php 3KB
mootools.js 64KB
共 4 条
- 1
资源评论
CyMylive.
- 粉丝: 6610
- 资源: 3万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功