| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 | <?php defined('BASEPATH') OR exit('No direct script access allowed');class Paypal extends Start_Controller {	public function __construct(){		parent::__construct();		$this->load->library('session');	}	//定义方法的调用规则 获取URI第二段值    public function _remap($arg,$arg_array)    {		if($arg == 'token')        {			$this->_token();        }		else		{			$this->_index($arg_array);		}    }	public function _index($arg_array)	{		$url = 'https://api.sandbox.paypal.com/v1/customer/disputes/';		$header[] = 'Content-Type: application/json';        $header[] = 'Accept-Language: en_US';        $header[] = 'Accept: */*';        $method = 'POST';        $hf_account = 'paypal-facilitator@supernovahair.com';        $client_id = 'Ae5ZECTwT-JY-GrHW2-XW234yJ4tYT-7RAt3s1mY8GtW1rX470Kr8weXkCH3GMaO-V7mnmnCTsxFvsiy';        $secret_id = 'EOiZjIwRaiK3pvbJgMURKcGy6ULt5YCGLkqN7WngwG-r34brYrfVwS6ECI8cig7l8lOObvF-ukeZxB-3';		$data = array('grant_type' => 'client_credentials');		$data['start_time'] = date('Y-m-d',time()-20*24*3600);		$data['page'] = $arg_array[0];		$data['page_size'] = 50;		$data['next_page_token'] = $this->_token();		$data['dispute_state'] = 'OPEN_INQUIRIES';        $userpwd = $client_id . ':' . $secret_id;        $info = $this->_curl($data,$url,3000,$method,true,$header,$userpwd);		echo "<pre>";		print_r($info);    }		public function _token()	{		$url = 'https://api.sandbox.paypal.com/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 = explode(':', $access_str);            if (time() < intval($access_arr[0])) 			{				$hf_access_token = isset($access_arr[1]) ? $access_arr[1] : '';            }        }        if(!$hf_access_token)		{            $file = fopen($hf_path, 'w');            $hf_account = 'paypal-facilitator@supernovahair.com';            $client_id = 'Ae5ZECTwT-JY-GrHW2-XW234yJ4tYT-7RAt3s1mY8GtW1rX470Kr8weXkCH3GMaO-V7mnmnCTsxFvsiy';            $secret_id = 'EOiZjIwRaiK3pvbJgMURKcGy6ULt5YCGLkqN7WngwG-r34brYrfVwS6ECI8cig7l8lOObvF-ukeZxB-3';            $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'];            fwrite($file, $access_new);            fclose($file);			$hf_access_token = $result['access_token'];		}		return $hf_access_token;    }		public 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;    }}
 |