PageRenderTime 61ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/b2b/core/model/service/mdl.certificate.php

http://phpfor.googlecode.com/
PHP | 860 lines | 683 code | 96 blank | 81 comment | 82 complexity | 60ee391ba942f673fc29f99469f6d4ca MD5 | raw file
  1. <?php
  2. /******************
  3. Certificate ??
  4. ******************/
  5. class mdl_certificate extends modelFactory {
  6. function get_app_instance_id($app_id){
  7. if(empty($this->app_instance_id)){
  8. $return = "";
  9. $post = array(
  10. 'certi_app' => 'app.get_instance_list',
  11. 'app_id' => VERIFY_APP_ID,
  12. 'version' => '1.0',
  13. 'certi_url' => $this->system->base_url(),
  14. 'certi_session' => $this->get_sess(),
  15. 'certi_validate_url' => $this->system->base_url() . "shopadmin/index.php?ctl=passport&act=certi_validate",
  16. 'format' => 'json'
  17. );
  18. $post['certi_ac'] = $this->make_shopex_ac($post,$this->getToken());
  19. $instance_list = $this->read_shopex_server($post);
  20. if($instance_list['res'] == 'succ'){
  21. $return = implode("|",$instance_list['info']);
  22. }else{
  23. $return = "";
  24. }
  25. $this->app_instance_id = $return;
  26. }else{
  27. $return = $this->app_instance_id;
  28. }
  29. return $return;
  30. }
  31. function to_shopex_certificate($certi_app,$certificate_id=NULL,$token=NULL,$identifier=NULL,$password=NULL,$certi_session=NULL,$version=NULL,$app_id=NULL,$app_instance_id=NULL,$certi_url=NULL,$certi_validate_url=NULL,$shop_version=NULL,$format='json'){
  32. $certificate_id = is_null($certificate_id)?$this->getCerti():$certificate_id;
  33. $token = is_null($token)?$this->getToken():$token;
  34. $identifier = is_null($identifier)?$this->getIdentifier():$identifier;
  35. $password = is_null($password)?$this->getPassword():$password;
  36. $certi_session = is_null($certi_session)?STORE_KEY:$certi_session;
  37. $version = is_null($version)?'1.2':$version;
  38. $app_id = is_null($app_id)?VERIFY_APP_ID:$app_id;
  39. $app_instance_id = is_null($app_instance_id)?$this->get_app_instance_id(VERIFY_APP_ID):$app_instance_id;
  40. //??base_url ?????????????url add liuguoqing
  41. $base_url = $this->system->getConf('store.shop_url')?$this->system->getConf('store.shop_url'):$this->system->base_url();
  42. $certi_url = is_null($certi_url)?$base_url:$certi_url;
  43. $certi_validate_url = is_null($certi_validate_url)?$base_url . "shopadmin/index.php?ctl=passport&act=certi_validate":$certi_validate_url;
  44. $format = empty($format)?'json':$format;
  45. $shop_version = is_null($shop_version)?$this->getVersion():$shop_version;
  46. $post = array(
  47. 'certi_app' => $certi_app,
  48. 'certificate_id' => $certificate_id,
  49. 'identifier' => $identifier,
  50. 'password' => $password,
  51. 'app_id' => $app_id,
  52. 'app_instance_id' => $app_instance_id,
  53. 'version' => $version,
  54. 'certi_url' => $certi_url,
  55. 'certi_session' => $certi_session,
  56. 'certi_validate_url' => $certi_validate_url,
  57. 'shop_version' => $shop_version,
  58. 'refer' => 'shopex',
  59. 'format' => $format
  60. );
  61. $post['certi_ac'] = $this->make_shopex_ac($post,$token);
  62. return $this->read_shopex_server($post);
  63. }
  64. function make_shopex_ac($temp_arr,$token){
  65. ksort($temp_arr);
  66. $str = '';
  67. foreach($temp_arr as $key=>$value){
  68. if($key!='certi_ac') {
  69. $str.=$value;
  70. }
  71. }
  72. return md5($str.$token);
  73. }
  74. function read_shopex_server($post){
  75. $url=SERVICE_HOST."/openapi/api.php";
  76. $net = $this->system->network();
  77. $net->agent="ShopEx_Cert_Client";
  78. $net->submit($url,$post);
  79. $debug_info['url']=$url;
  80. $debug_info['request']=$post;
  81. $results=$net->results;
  82. $debug_info['result']=$results;
  83. if( @constant( "DEBUG_API" ) ){
  84. error_log(date("c")."\t".print_r($debug_info,true),3,HOME_DIR."/logs/certificate_".date("Y-m-d").".log");
  85. }
  86. return json_decode($results,true);
  87. }
  88. function read_shopex_accountserver($post){
  89. $url=ACCOUNT_HOST."/api.php";
  90. $net = $this->system->network();
  91. //$net->agent="ShopEx_Cert_Client";
  92. $net->submit($url,$post);
  93. $results=$net->results;
  94. return json_decode($results,true);
  95. }
  96. function checkValid($sStr){
  97. if($sStr == 'valid'){
  98. return '??';
  99. }
  100. else{
  101. return '???';
  102. }
  103. }
  104. function delLicense(){
  105. $this->system->setConf('certificate.id','');
  106. $this->system->setConf('certificate.token','');
  107. $this->system->setConf('certificate.node_id','');
  108. }
  109. function explodeStr($sStr){
  110. $aTmp = explode("|||", $sStr);
  111. return $aTmp;
  112. }
  113. /**
  114. * ??license_id
  115. * @param $certi_id
  116. */
  117. function setCerti($certi_id){
  118. return $this->system->setConf('certificate.id',$certi_id,true);
  119. }
  120. /**
  121. * ??token
  122. * @param $token
  123. */
  124. function setToken($token){
  125. return $this->system->setConf('certificate.token',$token,true);
  126. }
  127. /**
  128. * ??shopex???ID
  129. * @param $nodeid
  130. */
  131. function setNodeId($nodeid){
  132. return $this->system->setConf('certificate.node_id',$nodeid,true);
  133. }
  134. /**
  135. * ??shopex???identifier(???ID?)
  136. * @param $identifier
  137. */
  138. function setIdentifier($identifier){
  139. return $this->system->setConf('shopexuser.identifier',$identifier,true);
  140. }
  141. /**
  142. * ??shopex?????
  143. * @param $email
  144. */
  145. function setIdentEmail($identemail){
  146. return $this->system->setConf('shopexuser.identemail',$identemail,true);
  147. }
  148. /**
  149. * ??shopex???????
  150. * @param $password
  151. */
  152. function setPassword($password){
  153. return $this->system->setConf('shopexuser.password',md5($password.ACCOUNT_PASS_HASH),true);
  154. }
  155. function setStr($str){
  156. $this->system->setConf('certificate.str',$str);
  157. }
  158. function setFormal($state){
  159. $this->system->setConf('certificate.formal',$state);
  160. }
  161. function set_channel_url($url){
  162. $this->system->setConf('certificate.channel.url',$url);
  163. }
  164. function set_channel_name($name){
  165. $this->system->setConf('certificate.channel.name',$name);
  166. }
  167. function set_channel_is($status){
  168. $this->system->setConf('certificate.channel.status',$status);
  169. }
  170. function set_channel_service($service){
  171. $this->system->setConf('certificate.channel.service',$service);
  172. }
  173. //????????node id ???????????
  174. function setTaoNodeId($node_id){
  175. $this->system->setConf('taofenxiao.node_id',$node_id);
  176. $status = $node_id ? 1 : 0;
  177. $this->db->exec('update sdb_application set status = \''.$status.'\' where act=\'app_taofenxiao\'');
  178. }
  179. function getTaoNodeId(){
  180. if($this->system->getConf('taofenxiao.node_id')){
  181. return $this->system->getConf('taofenxiao.node_id');
  182. }else{
  183. return false;
  184. }
  185. }
  186. // [node_id] => 1735373339
  187. // [status] => true
  188. // [session] => 405251265ec118214dekWJLWlSz0c17055f5a6f636d44e74670275721
  189. // [nickname] => ????
  190. //?????????????
  191. function set_taobao_session_status($status){
  192. $this->system->setConf('taofenxiao.taobao_session_status',$status);
  193. }
  194. function get_taobao_session_status(){
  195. if($this->system->getConf('taofenxiao.taobao_session_status')){
  196. return $this->system->getConf('taofenxiao.taobao_session_status');
  197. }else{
  198. return false;
  199. }
  200. }
  201. //??????????
  202. function set_taobao_nickname($nickname){
  203. $this->system->setConf('taofenxiao.taobao_nickname',$nickname);
  204. }
  205. function get_taobao_nickname($nickname){
  206. if($this->system->getConf('taofenxiao.taobao_nickname')){
  207. return $this->system->getConf('taofenxiao.taobao_nickname');
  208. }else{
  209. return false;
  210. }
  211. }
  212. //????????? taobao session
  213. function set_taobao_session($taobao_session){
  214. $this->system->setConf("taofenxiao.taobao_session",$taobao_session);
  215. }
  216. function get_taobao_session(){
  217. if($this->system->getConf("taofenxiao.taobao_session")){
  218. return $this->system->getConf("taofenxiao.taobao_session");
  219. }else{
  220. return false;
  221. }
  222. }
  223. function updateSess($op_id,$sess_id){
  224. $sSql = "update sdb_op_sessions set op_id = '$op_id' where sess_id = '$sess_id'";
  225. $this->db->query($sSql);
  226. }
  227. function get_sess(){
  228. $sql = "select sess_id from sdb_op_sessions WHERE status=1 ORDER BY last_time DESC";
  229. $data=$this->db->selectrow($sql);
  230. return $data['sess_id'];
  231. }
  232. function getCerti(){
  233. if($this->system->getConf('certificate.id')){
  234. return $this->system->getConf('certificate.id');
  235. }else{
  236. return false;
  237. }
  238. }
  239. function getToken(){
  240. if($this->system->getConf('certificate.token')){
  241. return $this->system->getConf('certificate.token');
  242. }else{
  243. return false;
  244. }
  245. }
  246. function getNoteId(){
  247. if($this->system->getConf('certificate.node_id')){
  248. return $this->system->getConf('certificate.node_id');
  249. }else{
  250. return false;
  251. }
  252. }
  253. function getIdentifier(){
  254. if($this->system->getConf('shopexuser.identifier')){
  255. return $this->system->getConf('shopexuser.identifier');
  256. }else{
  257. return false;
  258. }
  259. }
  260. function getIdentEmail(){
  261. if($this->system->getConf('shopexuser.identemail')){
  262. return $this->system->getConf('shopexuser.identemail');
  263. }else{
  264. return false;
  265. }
  266. }
  267. function getPassword(){
  268. if($this->system->getConf('shopexuser.password')){
  269. return $this->system->getConf('shopexuser.password');
  270. }else{
  271. return false;
  272. }
  273. }
  274. function get_channel_url(){
  275. return $this->system->getConf('certificate.channel.url');
  276. }
  277. function get_channel_name($name){
  278. return $this->system->getConf('certificate.channel.name');
  279. }
  280. function get_channel_is(){
  281. return $this->system->getConf('certificate.channel.status');
  282. }
  283. function get_channel_service(){
  284. return $this->system->getConf('certificate.channel.service');
  285. }
  286. function getName(){
  287. if($this->system->getConf('system.shopname')){
  288. return $this->system->getConf('system.shopname');
  289. }
  290. }
  291. function getSess($sess_id){
  292. $sSql="select * from sdb_op_sessions where sess_id='$sess_id'";
  293. if ($this->db->selectrow($sSql)) {
  294. return true;
  295. }else{
  296. return false;
  297. }
  298. }
  299. function setEncode($sess_id,$certi_id){
  300. $ENCODEKEY='ShopEx@License';
  301. $confirmkey = md5($sess_id.$ENCODEKEY.$certi_id);
  302. return $confirmkey;
  303. }
  304. function checkFile($files){
  305. if(empty($files)){
  306. return false;
  307. }else{
  308. return true;
  309. }
  310. }
  311. function checkPass($aIn){
  312. $sSql = "select * from sdb_operators where username = '".$aIn['username']."' and userpass = md5('".$aIn['userpass']."') and super=1 and status=1";
  313. if($this->db->selectrow($sSql)){
  314. return true;
  315. }else{
  316. return false;
  317. }
  318. }
  319. function upload($tmp){
  320. if(!$this->checkFile($tmp)){
  321. return false;
  322. }
  323. $certInfo = @file($tmp);
  324. $line = $certInfo[0];
  325. $result=$this->checkCerti($line,'check');
  326. if(!$result){
  327. return false;
  328. }
  329. $expTmp = explode('|||',$line);
  330. if(!$this->checkCerti($expTmp[0],'id')){
  331. return false;
  332. }
  333. if(!$this->checkCerti($expTmp[1],'token')){
  334. return false;
  335. }
  336. if( $cerinfo=$this->to_shopex_certificate('certi.login',$expTmp[0],$expTmp[1]) ){
  337. if($cerinfo['res'] == 'succ'){
  338. if( $cerinfo['info']['open'] == 'false' ){
  339. return false;
  340. }
  341. }else{
  342. return false;
  343. }
  344. }
  345. $this->delLicense();
  346. $_r1=$this->setCerti($expTmp[0]);
  347. $_r2=$this->setToken($expTmp[1]);
  348. if($_r1&&$_r2){
  349. return true;
  350. }
  351. return false;
  352. }
  353. function checkCerti($certi , $action){
  354. switch($action) {
  355. case 'check':
  356. if(strtok($certi, "|||")){
  357. return true;
  358. }
  359. else{
  360. return false;
  361. }
  362. break;
  363. case 'id':
  364. if(strlen($certi) < 12){
  365. return true;
  366. }else{
  367. return false;
  368. }
  369. break;
  370. case 'token':
  371. if(strlen($certi) == 64){
  372. return true;
  373. }else{
  374. return false;
  375. }
  376. break;
  377. }
  378. }
  379. function msg_pack(){
  380. $data['ip'] = remote_addr();
  381. $data['url'] = $this->system->base_url();
  382. $data['login_time'] = mktime();
  383. $data['certificate_id'] = $this->getCerti();
  384. $data['shopname'] = $this->system->getConf('system.shopname');
  385. $data['ac'] = $this->make_shopex_ac($data,'ShopEx_LOG');
  386. return $data;
  387. }
  388. function post_data($data){
  389. $url = SERVICE_HOST.'/class.license_log.php';
  390. $httpd=$this->system->network();
  391. $httpd->submit($url,$data);
  392. return $httpd->results;
  393. }
  394. function show_pack_data(){
  395. $data = array();
  396. $tmp=$this->db->selectrow("select count(product_id) as product_num from sdb_products as aProducts
  397. left join sdb_goods as aGoods on aProducts.goods_id=aGoods.goods_id where aProducts.goods_id=aGoods.goods_id and aGoods.disabled='false' and aProducts.disabled='false'");
  398. $data['goodnum'] = $tmp['product_num'];
  399. $sql = "select count(*) as categorynum from sdb_goods_type";
  400. $tmp = $this->db->selectrow($sql);
  401. $data['categorynum'] = $tmp['categorynum'];
  402. $sql = "select count(*) as membernum from sdb_members where disabled='false'";
  403. $tmp = $this->db->selectrow($sql);
  404. $data['membernum'] = $tmp['membernum'];
  405. $tmp=$this->db->selectrow("select count(order_id) as order_num,sum(total_amount) as order_total_count from sdb_orders where version_id=0 and ship_status=1 and (pay_status=1 or pay_status=2) and disabled='false'");
  406. $data['ordernum'] = $tmp['order_num'];
  407. $data['orderprice'] = $tmp['order_total_count'];
  408. return $data['goodnum'].'###'.$data['categorynum'].'###'.$data['ordernum'].'###'.$data['membernum'].'###'.$data['orderprice'];
  409. }
  410. function b2b_show_pack_data(){
  411. $data = array();
  412. $tmp=$this->db->selectrow("select count(DISTINCT aProducts.goods_id) as product_num from sdb_products as aProducts
  413. left join sdb_goods as aGoods on aProducts.goods_id=aGoods.goods_id where aProducts.goods_id=aGoods.goods_id and aGoods.disabled='false' and aProducts.disabled='false'");
  414. $data['goodnum'] = $tmp['product_num'];
  415. $sql = "select count(*) as categorynum from sdb_goods_type";
  416. $tmp = $this->db->selectrow($sql);
  417. $data['categorynum'] = $tmp['categorynum'];
  418. $sql = "select count(*) as distribution_membernum from sdb_members where certificate_id>0 and disabled='false'";
  419. $tmp = $this->db->selectrow($sql);
  420. $data['membernum']['distribution'] = $tmp['distribution_membernum'];
  421. $sql = "select count(*) as local_membernum from sdb_members where certificate_id=0 and disabled='false'";
  422. $tmp = $this->db->selectrow($sql);
  423. $data['membernum']['local'] = $tmp['local_membernum'];
  424. $tmp=$this->db->selectrow("select count(order_id) as distribution_order_num,sum(total_amount) as distribution_order_total_count from sdb_orders where version_id=0 and ship_status=1 and (pay_status=1 or pay_status=2) and is_remote='true' and disabled='false'");
  425. $data['ordernum']['distribution'] = $tmp['distribution_order_num'];
  426. $data['orderprice']['distribution'] = $tmp['distribution_order_total_count'];
  427. $tmp=$this->db->selectrow("select count(order_id) as local_order_num,sum(total_amount) as local_order_total_count from sdb_orders where version_id=0 and ship_status=1 and (pay_status=1 or pay_status=2) and is_remote='false' and disabled='false'");
  428. $data['ordernum']['local'] = $tmp['local_order_num'];
  429. $data['orderprice']['local'] = $tmp['local_order_total_count'];
  430. return $data;
  431. }
  432. function check_api(){
  433. ksort($_POST);
  434. $str = '';
  435. //????get?
  436. foreach($_POST as $key=>$value){
  437. if($key!='ac'){
  438. $str.=$value;
  439. }
  440. }
  441. if(md5($str) == $_POST['ac']){
  442. return true;
  443. }
  444. return false;
  445. }
  446. function show_channel(){
  447. $httpd = $this->system->network();
  448. $url = SERVICE_HOST.'/class.channel.php';
  449. $certificate_id=$this->getCerti();
  450. $ac = md5($certificate_id.'ShopEx_CHANNEL');
  451. $data= array('certificate_id'=>$certificate_id,
  452. 'ac'=>$ac
  453. );
  454. $httpd->submit($url,$data);
  455. $msg = $httpd->results;
  456. if(!(strpos($msg, 'true') === false)){
  457. $tmp=$this->explodeStr($msg);
  458. $this->set_channel_name($tmp[1]);
  459. $this->set_channel_url($tmp[2]);
  460. $this->set_channel_service($tmp[3]);
  461. $this->set_channel_is(true);
  462. }else{
  463. $this->set_channel_is(false);
  464. }
  465. }
  466. function getInfo(){
  467. set_time_limit(0);
  468. $this->Certi = $this->getCerti();
  469. $this->Token = $this->getToken();
  470. $this->Noteid = $this->getNoteid();
  471. $this->setFormal($state);
  472. if($this->Certi && $this->Token && $this->Noteid){
  473. $this->sendmsg();
  474. $this->show_channel();
  475. $this->setStr($str);
  476. $_r=$this->toLogin();
  477. }else{
  478. $this->delLicense();
  479. $_r=$this->toReg();
  480. $this->Certi = $this->getCerti();
  481. $this->Token = $this->getToken();
  482. $this->Noteid = $this->getNoteId();
  483. }
  484. //$str=$this->getUrl($_r);
  485. $str=$_r;
  486. $this->system->output($str);
  487. }
  488. function toLogin(){
  489. $loginToShopEx = $this->to_shopex_certificate('certi.login');
  490. $login_t = time();
  491. $this->system->setConf('certificate.login_t',$login_t,true);
  492. if($loginToShopEx['res'] == 'succ'){
  493. if( $loginToShopEx['info']['open'] != 'false' ){
  494. $str = $loginToShopEx['info']['service'][VERIFY_APP_ID]['cert_auth']['auth_strname'] . '[' . $loginToShopEx['info']['service'][VERIFY_APP_ID]['cert_auth']['auth_typename'] . ']';
  495. $license_info = array(
  496. 'certificate_id' => $this->getCerti(),
  497. 'token' => $this->getToken(),
  498. 'auth_str' => $loginToShopEx['info']['service'][VERIFY_APP_ID]['cert_auth']['auth_str'],
  499. 'auth_type' => $loginToShopEx['info']['service'][VERIFY_APP_ID]['cert_auth']['auth_type'],
  500. 'btime' => $loginToShopEx['info']['service'][VERIFY_APP_ID]['cert_auth']['service_time']['btime'],
  501. 'etime' => $loginToShopEx['info']['service'][VERIFY_APP_ID]['cert_auth']['service_time']['etime'],
  502. 'login_t' => $login_t,
  503. 'retry' => 0
  504. );
  505. }else{
  506. $license_info = array(
  507. 'certificate_id' => '',
  508. 'token' => '',
  509. 'auth_str' => '',
  510. 'auth_type' => '',
  511. 'btime' => '',
  512. 'etime' => '',
  513. 'login_t' => '',
  514. 'retry' => ''
  515. );
  516. $str = "[?????]";
  517. $this->setCerti("");
  518. $this->setToken("");
  519. $this->setNodeId("");
  520. }
  521. }else if($loginToShopEx['res'] == 'fail'){
  522. if( $loginToShopEx['msg'] == 'domain_error' ){
  523. $license_info = array(
  524. 'certificate_id' => '',
  525. 'token' => '',
  526. 'auth_str' => '',
  527. 'auth_type' => '',
  528. 'btime' => '',
  529. 'etime' => '',
  530. 'login_t' => '',
  531. 'retry' => ''
  532. );
  533. $str = "[?????]";
  534. $this->setCerti("");
  535. $this->setToken("");
  536. $this->setNodeId("");
  537. }else{
  538. $str = $loginToShopEx['info']['service'][VERIFY_APP_ID]['cert_auth']['auth_strname'] . '[' . $loginToShopEx['info']['service'][VERIFY_APP_ID]['cert_auth']['auth_typename'] . ']';
  539. $license_info = array(
  540. 'certificate_id' => $this->getCerti(),
  541. 'token' => $this->getToken(),
  542. 'auth_str' => 'free',
  543. 'auth_type' => 'no',
  544. 'btime' => NULL,
  545. 'etime' => NULL,
  546. 'login_t' => $login_t,
  547. 'retry' => 0
  548. );
  549. }
  550. }
  551. // else{
  552. // $str = "";
  553. // $license = $this->getLicenseFile();
  554. // $license_info = array(
  555. // 'certificate_id' => $license['certificate_id'],
  556. // 'token' => $license['token'],
  557. // 'auth_str' => $license['auth_str'],
  558. // 'auth_type' => $license['auth_type'],
  559. // 'btime' => $license['btime'],
  560. // 'etime' => $license['etime'],
  561. // 'login_t' => $login_t,
  562. // 'retry' => isset($license['retry'])?($license['retry']+1):1
  563. // );
  564. // }
  565. //??license????????????license????????????
  566. $this->setLicenseFile($license_info);
  567. return $str;
  568. }
  569. function toReg(){
  570. $regToShopEx = $this->to_shopex_certificate('certi.reg');
  571. if($regToShopEx['res'] == 'succ'){
  572. // $this->setCerti($regToShopEx['info']['certificate_id']);
  573. // $this->setToken($regToShopEx['info']['token']);
  574. // $this->setNodeId($regToShopEx['info']['node_id']);
  575. $_r=$this->toLogin();
  576. return $_r;
  577. }else{
  578. return $regToShopEx['info'];
  579. }
  580. }
  581. function getUrl($str){
  582. $this->certi_id= $this->getCerti();
  583. $sess_id =$this->get_sess();
  584. if(empty($this->certi_id)){
  585. $this->certi_id='error';
  586. }
  587. if(empty($sess_id)){
  588. $this->system->session->sess_id='error';
  589. }
  590. $confirmkey=$this->setEncode($sess_id,$this->certi_id);
  591. $url = '?sess_id='.urlencode($sess_id).'&certi_id='.urlencode($this->certi_id).'&version='.urlencode($this->getVersion()).'&confirmkey='.$confirmkey;
  592. $url = SERVICE_HOST.'/info.php'.$url.'&_key_=do';
  593. $prefix='<a href="'.$url.'" target="_blank" title="'.$this->certi_id.'">'.$str.'</a>';
  594. return $prefix;
  595. }
  596. function getVersion(){
  597. $version =$this->system->version();
  598. return $version['app'].'#'.$version['rev'];
  599. }
  600. /**
  601. * to send message to shopex log server
  602. */
  603. function sendmsg(){
  604. $data=$this->msg_pack();
  605. $date=$this->post_data($data);
  606. return true;
  607. }
  608. /**
  609. * ??license????
  610. * @param string $msg ????
  611. *
  612. * @return boolean true:????????????false:???????????
  613. */
  614. function checkLincense(&$msg){return true;
  615. $license_file = HOME_DIR . '/license';
  616. $time = time();
  617. $this->Certi = $this->getCerti();
  618. $this->Token = $this->getToken();
  619. $this->Noteid = $this->getNoteId();
  620. if(empty($this->Certi) || empty($this->Token) || empty($this->Noteid)){
  621. $this->delLicense();
  622. $this->toReg();
  623. $this->Certi = $this->getCerti();
  624. $this->Token = $this->getToken();
  625. $this->Noteid = $this->getNoteId();
  626. }
  627. if(empty($this->Certi) || empty($this->Token)){
  628. $msg = "???????????????!";
  629. return false;
  630. }
  631. if(!file_exists($license_file)){
  632. $this->toLogin(); //?????license??
  633. }
  634. $license = $this->getLicenseFile();
  635. //???????????
  636. $loginToShopEx = $this->to_shopex_certificate('certi.login');
  637. if($loginToShopEx['res'] == 'succ'){
  638. $auth_str = $loginToShopEx['info']['service'][VERIFY_APP_ID]['cert_auth']['auth_str'];
  639. $auth_type = $loginToShopEx['info']['service'][VERIFY_APP_ID]['cert_auth']['auth_type'];
  640. $btime = $loginToShopEx['info']['service'][VERIFY_APP_ID]['cert_auth']['service_time']['btime'];
  641. $etime = $loginToShopEx['info']['service'][VERIFY_APP_ID]['cert_auth']['service_time']['etime'];
  642. }else{
  643. $auth_str = NULL;
  644. $auth_type = NULL;
  645. $btime = NULL;
  646. $etime = NULL;
  647. }
  648. /*if(!empty($license) && is_array($license) && $license['login_t'] == $this->system->getConf('certificate.login_t')){*/
  649. if(!empty($license) && is_array($license)){ //??$license['login_t'] == $this->system->getConf('certificate.login_t')???getconf????
  650. //NOTICE:??license??????????retry?????license????????????????3?retry??????????????????????license?????????retry?1????????retry
  651. //?????license??????????
  652. if($loginToShopEx['res'] == 'succ'){
  653. if($auth_str == 'distribute'){
  654. if($time < $btime || $time > $etime){
  655. $msg = "??????????????????!";
  656. return false;
  657. }else{
  658. if($auth_type != 'no'){
  659. return true;
  660. }else{
  661. $msg = "???????????????!";
  662. return false;
  663. }
  664. }
  665. }else if($auth_str == 'free'){
  666. if($time < $btime || $time > $etime){
  667. $msg = "??????????????????!";
  668. }else{
  669. $msg = "???????????????!";
  670. }
  671. return false;
  672. }else{
  673. $msg = "???????????????!";
  674. return false;
  675. }
  676. }else if($loginToShopEx['res'] == 'fail'){
  677. $msg = "???????????????!";
  678. return false;
  679. }else{
  680. if($license['retry'] >= 3){
  681. $msg = "???????????????!";
  682. return false;
  683. }else{
  684. return true;
  685. }
  686. }
  687. }else{
  688. $msg = "??????!";
  689. return false;
  690. }
  691. }
  692. function checkIdentifier($certi_app,$account,$password,$version=NULL,$format=NULL,$isHash=false){
  693. $version = is_null($version)?'1.0':$version;
  694. $format = empty($format)?'json':$format;
  695. $post = array(
  696. 'certi_app' => $certi_app,
  697. 'identifier' => $account,
  698. 'password' => $isHash ? $password : md5($password.ACCOUNT_PASS_HASH),
  699. 'version' => $version,
  700. 'format' => $format
  701. );
  702. $post['certi_ac'] = $this->make_shopex_ac($post,ACCOUNT_TOKEN);
  703. return $this->read_shopex_accountserver($post);
  704. }
  705. /**
  706. * ?????license??
  707. *
  708. * @param array $license_info
  709. */
  710. function setLicenseFile($license_info){
  711. $license_file = HOME_DIR . '/license';
  712. include_once(CORE_DIR.'/lib/AES.php');
  713. $aes = new AES(true);// ?????????????????
  714. $key = STORE_KEY;// ??
  715. $keys = $aes->makeKey($key);
  716. $encode = serialize($license_info);
  717. $ct = $aes->encryptString($encode, $keys);
  718. file_put_contents($license_file,$ct);
  719. }
  720. /**
  721. * ?????license??
  722. *
  723. * @return array
  724. */
  725. function getLicenseFile(){
  726. $license_file = HOME_DIR . '/license';
  727. include_once(CORE_DIR.'/lib/AES.php');
  728. $aes = new AES(true);// ?????????????????
  729. $key = STORE_KEY;// ??
  730. $keys = $aes->makeKey($key);
  731. if(file_exists($license_file)){
  732. $license_info = file_get_contents($license_file);
  733. $license_info = $aes->decryptString($license_info, $keys);
  734. $license = unserialize($license_info);
  735. }else{
  736. $license = array();
  737. }
  738. return $license;
  739. }
  740. function setOmeNodeId($nodeid){
  741. $this->system->setConf('omeinfo.node_id',$nodeid,true);
  742. return $this->system->setConf('certificate.ome_node_id',$nodeid,true);
  743. }
  744. function getOmeNoteId(){
  745. if($this->system->getConf('certificate.ome_node_id')){
  746. return $this->system->getConf('certificate.ome_node_id');
  747. }elseif( $this->system->getConf('omeinfo.node_id') ){
  748. return $this->system->getConf('omeinfo.node_id');
  749. }else{
  750. return false;
  751. }
  752. }
  753. function set_taobao_login_status($status){
  754. $this->system->setConf('taobao.taobao_login_status',$status);
  755. }
  756. function get_taobao_login_status(){
  757. if($this->system->getConf('taobao.taobao_login_status')){
  758. return $this->system->getConf('taobao.taobao_login_status');
  759. }else{
  760. return false;
  761. }
  762. }
  763. }