<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/8 0008
 * Time: 18:16
 */
//$b = [5,10,20,50,100];
//array_push($b, 23);
//asort($b);
//var_dump($b);
//$a = array_search(23, $b);
//var_dump($a);

//$sign = 'eyJvcmRlcklkIjoiR1BBLjMzMDMtNzk2NS01Mjg5LTI5MTk5IiwicGFja2FnZU5hbWUiOiJjb20uc3VwZXJhbnQuc3VwZXJwb2tlci50aCIsInByb2R1Y3RJZCI6ImNvbS5zdXBlcnBva2VyLmNoaXBzMzQwayIsInB1cmNoYXNlVGltZSI6MTUyMTE5NDYyNzQzMCwicHVyY2hhc2VTdGF0ZSI6MCwiZGV2ZWxvcGVyUGF5bG9hZCI6IjIwMTgwMzE2MTcwMzAzMTg2NzAxNTU0OTU2NTUiLCJwdXJjaGFzZVRva2VuIjoia2xlcGFjY2lvZWFraG1iamFubnBoZWxtLkFPLUoxT3dORlBUdzc2akw5QjIyLUFxWV9VX3NpVUc2LXBORU5UQ1NKZFBpSDJtdllWRktjVlNGMWJZcGhLTGlMZExyeDNVeV9jT2ZMc0RSZDFzVDczenFSQkJVbHkwcWd3dVFwZDdSNWRaYjREU0pwQTVDc3hSb3NVVk4tZlRZTzFJY1pYR1NDeGV6aVFIcVpqSWNldUk0bXpMMTZZS0ItUSJ9';
//$signedData = base64_decode($sign);
//var_dump($signedData);exit;
//$ret = preg_match("/php/i", "PHP is the web scripting language of choice.");
//var_dump($ret);exit;

echo date('Ymd',time());die;
echo date('w',time());die;

$str  = 'bettype:16 val:20000';
$str = str_replace('bettype:', '', $str);
$arr = explode(' ', $str);
var_dump($arr);exit;

echo md5('123456');exit;
$str = '371325525851201806';
$redcards = substr($str, 8);
echo $redcards;exit;

$arr = str_split("19841321", 2) ;
var_dump($arr);exit;

$match = strpos('abc1233444', 'acb');
echo $match;exit;


//$str = 'Md5EEF1AD1A-9AA0.40D1-926d!11618fbbd7c5!';
$str = '31FBB0E30A044CDB7CDA3C2CE8E038C9|20180620104242526926|20180620094233161032157555051|1|10|100|德州扑克||20180620104252|超级德州扑克(SuperPoker)|EEF1AD1A-9AA0.40D1-926d!11618fbbd7c5!';
echo md5($str);exit;


$url = 'http://sdk.kpzs.com/Api/CheckUserValidate?channelkey=kaopu&appid=10592001&devicetype=android&imei=867779039055836&openid=31fbb0e30a044cdb7cda3c2ce8e038c9&r=0&tag=10592&tagid=da7ce4c6-621a-47bf-9d77-52071ba016ae&timespans=1529390465';
$match = parse_url($url);
var_dump($match);exit;

$str = "aa.kpzs.com3";
$reg  = "/.kpzs.com$/";
$ret= preg_match($reg, $str);
var_dump($ret);
exit;



$signedData = '{"orderId":"GPA.3331-2656-2192-49126","packageName":"com.superant.superpoker.th","productId":"com.superpoker.chips340k","purchaseTime":1521188687580,"purchaseState":0,"developerPayload":"2018031615242018670152519998","purchaseToken":"fkpopdgmicdahcfigimkgkhc.AO-J1OzkOd3Cw9WhvrPZwK-aNcI4mCuRQItilhWvvjtzRAeOuZaLoaaiMvQfOdRUMJRILG6FYttDiwcaPu2YGSZzd5NF8PPdB5v0DjmUpGzvg7D9G9qezwk57VCC7V0r67DLd74reobxBmCL59NCnyDLShVXPtCKfQ"}';
$ret = base64_encode($signedData);
var_dump($ret);exit;




//测试圣诞加密
$arr = [11,10,9,8,7,6,5,4,3,2,1];
$sliceArr = array_slice($arr, 0, 10);
var_dump($sliceArr);exit;
var_dump($arr);exit;

$json = '{"matchname":"u0e01u0e32u0e23u0e41u0e02u0e48u0e07u0e0bu0e39u0e40u0e1bu0e2du0e23u0e4cu0e1fu0e23u0e35 5u0e04u0e19","matchname_zh":"u6b22u4e50u514du8d395u4ebau8d5b","matchname_tw":"u6b61u6a02u514du8cbb5u4ebau8cfd","matchname_en":"HappyFree5"}';
$arr = json_decode($json, 1);
var_dump($arr);exit;

echo strtotime('-1 day 00:00:00');exit;
$arr = [""];
echo empty($arr) ? 1 : 0;exit;

echo rand(1, 5);exit;

echo chr(ord('A')+1);
echo md5('2630210010ErtLPB^P%u9X^iMM');exit; //31e6e55745b3ab4e6a41ad58522d6fbf  {"uid":12595,"props":10,"chips":100,"key":"821ae7f0615fd3c864a938f60b34b855","times":3}

//创建唯一订单号
echo uniqid()."\n";
echo substr(uniqid(), 7, 6);exit;
function build_order_no()
{
    return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}


var_dump(getDays(strtotime('2017-12-1 23:59:59'), strtotime('2017-12-3 0:0:0'))) ;exit;

function getDays($second1, $second2)
{
    if ($second1 < $second2) {
        $tmp = $second2;
        $second2 = $second1;
        $second1 = $tmp;
    }
    $days = ($second1 - $second2) / 86400;
    $dayList = array();
    for ($i=0; $i <= $days ; $i++) {
        $dayList[] = date('Ymd', $second2 + 86400*$i);
    }
    return $dayList;
}


$prize_arr = array(
    '0' => array('id'=>1,'prize'=>'平板电脑','v'=>1),
    '1' => array('id'=>2,'prize'=>'数码相机','v'=>5),
    '2' => array('id'=>3,'prize'=>'音箱设备','v'=>11),
    '3' => array('id'=>4,'prize'=>'4G优盘','v'=>11),
    '4' => array('id'=>5,'prize'=>'10Q币','v'=>22),
    '5' => array('id'=>6,'prize'=>'下次没准就能中哦','v'=>50),
);

foreach ($prize_arr as $key => $val) {
    $arr[$val['id']] = $val['v'];
}

$rid = get_rand($arr); //根据概率获取奖项id
$res['yes'] = $prize_arr[$rid-1]['prize']; //中奖项
//unset($prize_arr[$rid-1]); //将中奖项从数组中剔除，剩下未中奖项
//shuffle($prize_arr); //打乱数组顺序
//for($i=0;$i<count($prize_arr);$i++){
//    $pr[] = $prize_arr[$i]['prize'];
//}
//$res['no'] = $pr;   // 除了中奖外的其他数据
echo json_encode($res);




function get_rand($proArr) {
    $result = '';
    //概率数组的总概率精度
    $proSum = array_sum($proArr);
    //概率数组循环
    foreach ($proArr as $key => $proCur) {
        $randNum = mt_rand(1, $proSum);
        if ($randNum <= $proCur) {
            $result = $key;
            break;
        } else {
            $proSum -= $proCur;
        }
    }
    unset ($proArr);
    return $result;
}



