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