<?php
namespace app\common\game;
use \think\Db;
use \think\Cookie;
use \think\Session;
use \think\Cache;
use think\Controller;
//QQ华夏银元宝支付函数
class Qqhx_yyb extends Controller {
    
    static function pay($ck, $money, $land_id)
    {
        $c = 'ck' . $money;
        $is_weixin = is_weixin();
        if ($ck[$c] == '') {
            $order_id = '';
            $wx_url = '';
            $message = '金额CK异常,请检查CK或联系客服';
        } else {
            if (isMobile()) {
                //手机模式
                if ($is_weixin == 2) {
                    //微信内
                    $pay_type = 1;
                } else {
                    $pay_type = 3;
                }
            } else {
                $pay_type = 1;
            }
            
            $post = array('cook' => base64_encode($ck[$c]), 'type' => $pay_type, 'appid' => 1450000252, 'money' => $money, 'pro' => 100);
            $save_data = curl('http://api.fssy.cc/pay/qqge/pay', http_build_query($post), '', '');
            $wx_json = json_decode($save_data);
            $order_id = $wx_json->info->portal_serial_no;
            //订单号
            if ($wx_json->ret != 0) {
                $order_id = '';
                $wx_url = '';
                $order_mb = '';
                $message = $wx_json->msg;
            } else {
                $message = 'ok';
            }
        }
        if (isMobile()) {
            if ($is_weixin == 1) {
                $url = $wx_json->wx_info->wx_sign . '&redirect_url=https%3A%2F%2Fpay.qq.com%2Fh5%2Fwechat_h5_redirect_url.shtml';
                //获取支付链接
                $wx_code = curl($url, '', '', $header, 'https://pay.qq.com/h5/index.shtml?m=buy');
                $wx_url = getSubstr($wx_code, 'var url="', '";');
                $order_mb = 'weixin';
            } else {
                $wx_url = $wx_json->wx_info->wx_sign;
                $order_mb = 'weixin_h5';
            }
        } else {
            $wx_url = $wx_json->wx_info->wx_sign;
            $order_mb = 'h5';
        }
        $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;
    }
   
    static function status($ck, $order, $money)
    {
       
        $c = 'ck' . $money;
        $post = array('cook' => base64_encode($ck[$c]), 'appid' => 1450000252, 'order' => $order);
        $query = curl('http://api.fssy.cc/pay/qqge/order', http_build_query($post), '', '');
        echo $query;
        $query = json_decode($query, true);
        $order = '';
        if($query){
        $status = $query['msg'];
        $data = obj_array($query['WaterList']);
        if ($status == 'ok') {
            if(isset($data[0]['SerialNo'])){
                 $syorder = $data[0]['SerialNo'];
            }else{
                 $syorder = '';
            }
            return $syorder;
        }
        }
    }
    
}