| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 | <?php defined('BASEPATH') OR exit('No direct script access allowed');class Track extends Start_Controller {    private $sid;    private $baseurl="https://api.sandbox.paypal.com";	public function __construct(){		parent::__construct();		$this->load->library('session');        $this->load->_model('Model_fullorder','fullorder');		$this->load->_model('Model_fullordertt','fullordertt');        $this->load->_model('Model_fullorder_smt','fullordersmt');        $this->load->_model('Model_express','express');        $this->load->_model('Model_shop','shop');        $this->load->library('parser');//		$this->load->library('dispute_collect');        if(isset($_SESSION['api']))        {            $user = $this->user->get_api($_SESSION['api']);            $fgshop = [];            $user = explode('|',trim($user['shop'],'|'));            foreach ($user as $value)            {                if($value<=6){                    $fgshop[]=$value;                }            }        }        $sid=$this->input->get('sid');        if(!$sid||!in_array($sid,$fgshop)){            $sid=$fgshop[0];        }        $this->sid=$sid;    }	//定义方法的调用规则 获取URI第二段值    public function _remap($arg,$arg_array)    {		if($arg == 'detail')//添加        {             $this->_detail($arg_array);        }else		{			 $this->_index($arg_array);		}    }    public function  _index(){        $start_time=strtotime(date('Y-m-d',time()-24*3600*2));        $end_time=strtotime(date('Y-m-d',time()));        $dlz = $this->fullorder->paypal($start_time,$end_time);        $smt = $this->fullordersmt->paypal($start_time,$end_time);        $data = array_merge($dlz,$smt);                // $this->setTrack("tt",$data[112]);        $this->transaction("tt",$data[112]["paypal"]);        p($data);        $shop=$this->shop->read($data[38]['shop']);        // $this->creatOrder();        // $shop = $this->shop->read(店铺ID)                // $this->load->library('dispute_collect',['dp'=>$shop['shopname']]);                        $this->load->library('dispute_collect',['dp'=>'test']);        $list=$this->dispute_collect->getDisputes();        $this->data['list']=$list;        $this->_Template('dispute_list',$this->data);    }    private function setTrack($dp,$order){        $express=$this->express->read($order['express']);        $iscode=$express['iscode'];        $transaction_id=$order['paypal'];        $tracking_number=$order['waybill'];        if(!$iscode||!$transaction_id){            return false;        }        $url = $this->baseurl.'/v1/shipping/trackers-batch';        $header[] = 'Content-Type: application/json';        $header[] = 'Authorization: Bearer '.$this->getToken($dp);        $trackers=        [            [                'transaction_id'=>"1VV994313G159761B",                'tracking_number'=>"399475881888",                'status'=>'SHIPPED',                'carrier'=>$iscode,            ]        ];        $param=['trackers'=>$trackers];        $info = $this->_curl($param,$url,3000,'POST',"json",$header);        $info = json_decode($info,true);        p($info);    }    public function creatOrder(){        $url = $this->baseurl.'/v2/checkout/orders';        $header[] = 'Content-Type: application/json';        $dp="aaa";        $header[] = 'Authorization: Bearer '.$this->getToken($dp);        $param=[            'intent'=>"CAPTURE",            "purchase_units"=>[                [                    "amount"=>[                        "currency_code"=>"USD",                        "value"=>"100.00",                    ]                ]                            ],        ];        $info = $this->_curl($param,$url,3000,'POST',"json",$header);        $info = json_decode($info,true);        p($info);    }    private function transaction($dp,$transaction_id){        $url = $this->baseurl.'/v1/reporting/transactions?';        $header[] = 'Content-Type: application/json';        $header[] = 'Authorization: Bearer '.$this->getToken($dp);        $start_date=date("Y-m-d\TH:i:sO",time()-24*3600*30);        $end_date=date("Y-m-d\TH:i:sO",time());        $param=[            'transaction_id'=>$transaction_id,            'start_date'=>$start_date,            'end_date'=>$end_date,        ];        $data = http_build_query($param);        $url=$url.$data;        $info = $this->_curl([],$url,3000,'GET',"http_build_query",$header);        $info = json_decode($info,true);        return $info;    }    public function _detail(){        $shop=$this->shop->find('`id` ='.$this->sid);        $id=$this->input->get('id');        $this->load->library('ci_dispute',['dp'=>$shop['shopname']]);        $info=$this->ci_dispute->info($id);        $this->data['info']=$info;        $this->_Template('dispute_info',$this->data);    }    private  function getToken($dp)    {        $access_arr=[];        $url = $this->baseurl.'/v1/oauth2/token';        $header[] = 'Content-Type: application/json';        $header[] = 'Accept-Language: en_US';        $header[] = 'Accept: */*';        $data = array('grant_type' => 'client_credentials');        $method = 'POST';        $hf_path = $_SERVER["DOCUMENT_ROOT"] . '/data/hf_access_token.txt';        $hf_access_token = '';        if(file_exists($hf_path))        {            $file_read = fopen($hf_path, 'r');            $access_str = fgets($file_read);            fclose($file_read);            $access_arr = unserialize($access_str);            if(isset($access_arr[$dp])&&is_array($access_arr[$dp])){                $dp_access_arr=$access_arr[$dp];                if (time() < intval($dp_access_arr['expires_at']))                {                    $hf_access_token = isset($dp_access_arr['access_token']) ? $dp_access_arr['access_token'] : '';                }            }        }        if(!$hf_access_token)        {            // $config=$this->getDpConfig();            $config=[                'account'=>'paypal-facilitator@supernovahair.com',                'client_id'=>'Ae5ZECTwT-JY-GrHW2-XW234yJ4tYT-7RAt3s1mY8GtW1rX470Kr8weXkCH3GMaO-V7mnmnCTsxFvsiy',                'secret'=>'EOiZjIwRaiK3pvbJgMURKcGy6ULt5YCGLkqN7WngwG-r34brYrfVwS6ECI8cig7l8lOObvF-ukeZxB-3',            ];            $file = fopen($hf_path, 'w');            $hf_account = $config['account'];            $client_id = $config['client_id'];            $secret_id = $config['secret'];            $userpwd = $client_id . ':' . $secret_id;            $info = $this->_curl($data,$url,3000,$method,true,$header,$userpwd);            $result = json_decode($info,true);//            $access_new = (time() + $result['expires_in']) . ':' . $result['access_token'];            $access_arr[$dp]=[                'expires_at'=>time() + $result['expires_in'],                'access_token'=>$result['access_token'],            ];            fwrite($file, serialize($access_arr));            fclose($file);            $hf_access_token = $result['access_token'];        }        return $hf_access_token;    }    private function _curl($data,$url,$timeout=300,$httptype="POST",$date_type=false,$header=array(),$userpwd='')    {        if ($date_type == 'http_build_query')        {            $data = http_build_query($data);        }        else if ($date_type == 'json')        {            $data = json_encode($data);        }        $ch = curl_init();        curl_setopt($ch, CURLOPT_URL, $url);        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);        curl_setopt($ch, CURLOPT_HEADER, false);        switch ($httptype)        {            case "GET":                curl_setopt($ch, CURLOPT_HTTPGET, true);                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");                break;            case "POST":                curl_setopt($ch, CURLOPT_POST, true);                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                break;            case "PUT":                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");                break;            case "DELETE":                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");                break;        }        $isSecure = strpos($url, "https://");        if ($isSecure === 0)        {            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);        }        if(!empty($header))        {            curl_setopt($ch, CURLOPT_SSLVERSION , 6); //NEW ADDITION            curl_setopt($ch,CURLOPT_HTTPHEADER,$header);        }        if(!empty($userpwd))        {            curl_setopt($ch,CURLOPT_USERPWD,$userpwd);        }        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);        $result = curl_exec($ch);        curl_close($ch);        return $result;    }}
 |