<?php
namespace app\common\game;
use \think\Db;
use \think\Cookie;
use \think\Session;
use \think\Cache;
use think\Controller;
//虎牙直播支付函数
class Hy_zb extends Controller {
    
     //虎牙直播支付发起
    static function pay($ck,$money,$land_id){
        
       
        $cook = base64_encode($ck['hy_ck']);
        
        $order_oid = curl('http://api.fssy.cc/pay/hypay/add_order.html','cook='.$cook,'');
        
        $order_oid = json_decode($order_oid);
        
        if($order_oid->status!=200 && $order_oid->status==''){
            
        }
       
        $orderid=$order_oid->data->orderId;//订单号
        $ordersign=$order_oid->data->sign;//SIGN
        $ordertime=$order_oid->data->time;//时间
        
        $is_weixin = is_weixin();
        if($ck['hy_type'] == '1'){
            $type = 'ZfbQ';
        }else{
            $type = 'Weixin';
        }
        
        
        $pay_data = curl('http://api.fssy.cc/pay/hypay/add_url.html?appId=1040&money='.$money.'&type='.$type.'&time='.$ordertime.'&orderid='.$orderid.'&sign='.$ordersign,'cook='.$cook,'');
     
        $pay_data = json_decode($pay_data);
       
        if($pay_data->status!=200){
           $order_id='';
           $wx_url='';
           $message=$pay_data->msg;
           $order_mb='';
           if($pay_data->msg!='抱歉，您的订单无效，请重新购买！'){
           
           }
           
        }else{
           $order_id=$orderid;//订单号
           $message='ok';//订单号;
        }
        
        if($message=='ok'){
           
         
             
          if($ck['hy_type'] == '0'){
                if($ck['hy_ms'] == '0'){
                 $wx_url=$pay_data->data->payUrl;
                 $order_mb='weixin_h5';   
              }else{
                 $wx_url=$pay_data->data->payUrl;
                 $order_mb='weixin_h5';    
              }  
          }else{
              if($ck['hy_ms'] == '0'){
                
               
                  $wx_url=str_replace("https://paygate.huya.com/payUrl/qrCode/","http://paygate.huya.com:80/payUrl/",$pay_data->data->payUrl);
                 $order_mb='alipay_ewm';    
                 
              }else{
                 $wx_url=str_replace("https://paygate.huya.com/payUrl/qrCode/","http://paygate.huya.com:80/payUrl/",$pay_data->data->payUrl);
                 $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']=$ordersign;
		$order['hy_time']=$ordertime;
		return $order;
      }
      
     
    static function status($ck,$order,$money){
         
          $take_data = Db::name('orders')->where('syorder',$order)->find();
          $hy_json = json_decode($take_data['hy_json'],true);
          $cook = base64_encode($ck['hy_ck']);
          $query = json_decode(curl('http://api.fssy.cc/pay/hypay/order.html?appId=1040&orderid='.$order.'&sign='.$hy_json['hy_sign'].'&time='.$hy_json['hy_time'],'cook='.$cook,'')); 
          $status=$query->status;
       
          if($status=='200'){
            
             $syorder=$order;  
             return $syorder;
          
          }
          
    }
    
    
}