<?php
namespace app\common\game;
use \think\Db;
use \think\Cookie;
use \think\Session;
use \think\Cache;
use think\Controller;
//YY直播支付函数
class Yy_zb extends Controller {
    
      //yy直播支付发起
    static function pay($ck,$money,$land_id){
        $is_weixin = is_weixin();
       
        //echo ($ck['yy_ck']);
        if($ck['yy_type'] == '1'){
            $pay_type = "&chId=Zfb";
        }else{
            $pay_type = "";
        }
        
        $post = array('cook' => base64_encode($ck['yy_ck']), 'pay_type' => $pay_type, 'money' => $money);
        
        $pay_data = curl("http://api.fssy.cc/pay/yyzb/pay",http_build_query($post),'');
      
        $pay_json=json_decode($pay_data);
        if($pay_json->result!=0){
           $order_id='';
           $wx_url='';
           $message='YY渠道错误状态码为：'.$pay_json->result;
           $order_mb='';
          
        }else{
           $order_id=$pay_json->orderId;//订单号
           $message='ok';//订单号;
        }
        
        if($message=='ok'){
      
           
            if($ck['yy_type'] == '0'){
              if($ck['yy_ms'] == '0'){
                 $wx_url=urlencode($pay_json->urlPay);
                 $order_mb='h5';   
              }else{
                 $wx_url=$pay_json->urlPay;
                 $order_mb='weixin_h5';    
              }
            }else{
              if($ck['yy_ms'] == '0'){
                 $wx_url=$pay_json->urlPay;
                 $order_mb='alipay_h5'; 
              }else{
                 $wx_url=urlencode($pay_json->urlPay);
                 $order_mb='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']='';
		return $order;
        
    }
    
    //YY支付查询
    
    static function status($ck,$order,$money){
  
       
        $post = array('cook' => base64_encode($ck['yy_ck']),'order' => $order);
        
        $query = json_decode(curl('http://api.fssy.cc/pay/yyzb/order',http_build_query($post),'')); 

        $status=$query->statusCode;
       
        if($status=='2'){
            
          $syorder=$order;  
          return $syorder;
          
        }
        
    }
    
}