<?php
namespace app\common\game;
use \think\Db;
use \think\Cookie;
use \think\Session;
use \think\Cache;
use think\Controller;
//YY直播新支付渠道
class Yy_news extends Controller {
    
      //yy直播支付发起
    static function pay($ck,$money,$land_id){
        $is_weixin = is_weixin();
       
       
        if($ck['yy_type'] == '1'){
            $pay_type = "super_alipay";
        }else{
            $pay_type = "webzf_weixin";
        }
        
        $post = array('cook' => base64_encode($ck['yy_ck']), 'pay_type' => $pay_type, 'money' => $money);
       
        $pay_data = curl("http://api.fssy.cc/yynews/pay",http_build_query($post),'');
//var_dump($pay_data); 
      
        $pay_json=json_decode($pay_data);
        if($pay_json->status!=0){
           $order_id='';
           $wx_url='';
           $message='YY新渠道错误';
           $order_mb='';
        }else{
           $order_id=$pay_json->order_id;//订单号
           $message='ok';//订单号;
        }

	if($message=='ok'){
		if($is_weixin==1){
			if($ck['yy_type'] == '0'){
				$wx_url=$pay_json->image;
				$order_mb='yy_weixin_ewm';
			}else{
				$wx_url=$pay_json->image;
				$order_mb='yy_alipay_ewm'; 
			}
		}else{
			if($ck['yy_type'] == '0'){
				$wx_url=$pay_json->image;
				$order_mb='yy_weixin_ewm'; 
			}else{
				$wx_url=$pay_json->image;
				$order_mb='yy_alipay_ewm'; 
			}
		}
	}
   
        $order['order_id']=$order_id;
		$order['order_url']=$wx_url;
		$order['order_message']=$message;
		$order['alipay_url']='';
		$order['order_mb']=$order_mb;
		$order['hy_sign']='';
		$order['hy_time']='';
		$order['yy_news_no_url']=$pay_json->url_no;
		return $order;
        
    }
    
    //YY支付查询
    
    static function status($ck,$order,$money){
  
       
        $data = Db::name('orders')->where('syorder',$order)->find();
        
        $yy_json = json_decode($data['order_url'],true);
        
        $status = curl($yy_json['yy_news_no_url'],'',''); 

       
       
        if($status=='SUCCESS'){
            
          $syorder=$order;  
          return $syorder;
          
        }else if($status=='TIMEOUT'){
          $syorder=-2;  
          return $syorder;  
        }
        
    }
    
}