<?php

namespace app\common\game;
use \think\Db;
use \think\Cookie;
use \think\Session;
use \think\Cache;
use think\Controller;

class Dy_db extends Controller {
    
     //抖音支付发起
    static function pay($ck,$money,$land_id){
    
         $money_index=$money*100;
         
         $is_weixin = is_weixin();
         $randip = randIP();//随机IP
         if($ck['dy_ms']=='0'){
            $is_phone = '1';
            $user_agent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1';
            $header = array(
		      'User-Agent:'.$user_agent,
		      'X-FORWARDED-FOR:'.$randip,
		      'CLIENT-IP:'.$randip
		    );
            $webcast = curl('https://webcast.amemv.com/webcast/wallet_api/diamond_buy_external_safe/?diamond_id=666666&source=5&way=0&aid=1128&short_id='.$ck['dy_ck'].'&open_id=&fp=verify_kjoli20k_2EsWkfOW_ehBc_4Tbe_BFg4_42TBmSBM8HTN&platform=android&customized_price='.$money_index.'&extra=%7B%22domin_type%22:0%7D&_signature=_02B4Z6wo00101P939DwAAIBDb9lYYUDUM7j.Z.CAAGAra6','',$ck['d_ck'],$header,'',1);
            
            //exit($webcast);
         }else{
            $is_phone = '0';
            $user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36';
            $header = array(
		      'User-Agent:'.$user_agent,
		      'X-FORWARDED-FOR:'.$randip,
		      'CLIENT-IP:'.$randip
		    );
		    $webcast = curl('https://webcast.amemv.com/webcast/wallet_api/diamond_buy_external_safe/?diamond_id=666666&source=8&way=0&aid=1128&short_id='.$ck['dy_ck'].'&open_id=&fp=verify_kjoli20k_2EsWkfOW_ehBc_4Tbe_BFg4_42TBmSBM8HTN&platform=android&customized_price='.$money_index.'&extra=%7B%22domin_type%22:0%7D&_signature=_02B4Z6wo00101P939DwAAIBDb9lYYUDUM7j.Z.CAAGAra6','',$ck['d_ck'],$header,'',1);
         }
         
        
    
         $post = array(
             'cook1' => base64_encode($ck['dy_ck']),
             'cook2' => base64_encode($ck['d_ck']), 
             'pay_type' => $ck['dy_type'],
             'money_index' => $money_index,
             'is_phone' => $is_phone,
             'data' => base64_encode($webcast)
         );
             
         $data_4 =json_decode(curl("http://api.fssy.cc/pay/dypay/pay",http_build_query($post),''));
         
      
         
         
         if($data_4->ret != '-1'){
            $message = 'ok';
         }else{
            $message = $data_4->msg;
         }
         //开始判断是微信内还是微信外
         
         
         if($ck['dy_type']!='1'){
             if ($is_phone == '1') {
                
                 $wx_url = getSubstr($data_4->html,'var url="','";');
                 $order_mb='weixin';
                
             }else{
                 $wx_url = $data_4->url;
                 $order_mb='h5'; 
             }
           }else{
             if ($is_phone == '1') {
                 $wx_url = $data_4->url;
                 $order_mb='alipay_h5'; 
             }else{
                 $wx_url = $data_4->url;
                 $order_mb='alipay_ewm';
             }
         }
          
     
         $order['order_id']=$data_4->order_id;
	     $order['order_url']=$wx_url;
	     $order['order_message']=$message;
	     $order['alipay_url']='';
	     $order['order_mb']= $order_mb;
	     $order['hy_sign']=$data_4->dy_sign;
	     $order['hy_time']=$data_4->dy_time;
	     return $order;
      
        
    }
    
    public function status($ck,$order,$money){
          $take_data = Db::name('orders')->where('syorder',$order)->find();
          $hy_json = json_decode($take_data['hy_json'],true);
        
          $post = array(
              'dy_time' => $hy_json['hy_time'],
              'dy_sign' => $hy_json['hy_sign'],
              'order' => $order
           );
           $status = curl('http://api.fssy.cc/pay/dypay/order',http_build_query($post),''); 
          if($status=='SUCCESS'){
             $syorder=$order;  
             return $syorder;
          
          }
          
    }
    
}
