1. 程式人生 > >curl 呼叫介面

curl 呼叫介面

$curlPost = array(
	'unid'  	 => isset($data['unid'])?$data['unid']:'',
	'term_suiji' => isset($data['suiji'])?$data['suiji']:'',
	'wxorder_id' => 'SYKX'.date('YmdHis').rand(10000,99999),
	'pay_money'  => '0',
	'pay_date'   => date('Y-m-d H:i:s'),
);
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL,$GLOBALS['yurl'].'?service=App.Term.BuyTerm');
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $data = curl_exec($ch);//執行curl
        curl_close($ch);  
        $data = json_decode($data,true);
        // echo '<pre>';
     if($data['ret'] == 200){
        	$this->Session->setFlash("成功");
     }else{
         $this->Session->setFlash("失敗:".$data['msg']);
     }
     echo "<script> var index = parent.layer.getFrameIndex(window.name);
         parent.layer.close(index);
         parent.location.href='../Buy/Index';
         </script>";	
         // window.parent.location.reload(); //重新整理父頁面
     exit();