keys( $prefix. '*'); $new=[]; foreach ($arr as $v) { $new[]= Str::replaceFirst( redis_prefix(),'',$v ); } $redis->del($new); } function sc($data){ echo "
";
    print_r($data);
    echo "";
}
/**
 * 获取微秒等级的时间戳
 *
 * @return float
 */
function getMillisecond()
{
    list($t1, $t2) = explode(' ', microtime());
    return (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
}
if (! function_exists('getIp')) {
    function getIp() {
        if(getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
            $ip = getenv("HTTP_CLIENT_IP");
        elseif(getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
            $ip = getenv("HTTP_X_FORWARDED_FOR");
        elseif(getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
            $ip = getenv("REMOTE_ADDR");
        elseif(isset ($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
            $ip = $_SERVER['REMOTE_ADDR'];
        else
            $ip = "unknown";
        return ($ip);
    }
}
/**
 * @param $url
 * @param string $method
 * @param array $postData
 * @param int $timeOut
 * @param array $header
 * @return mixed|null|string
 */
function getHttpContent($url, $method = 'POST', $postData, $timeOut = 30, $header = [])
{
    $data = '';
    if (!empty($url)) {
        try {
            $ch = curl_init();
            if (substr($url, 0, 5) == 'https') {
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            }
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut); //30秒超时
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            if ($header) {
                curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
            }
            if (strtoupper($method) == 'POST') {
                $curlPost = is_array($postData) ? http_build_query($postData) : $postData;
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
            } elseif (strtoupper($method) == 'GET') {
                if (!empty($postData)) {
                    $url = $url . (strpos($url, '?') ? '&' : '?') . http_build_query($postData);
                }
            }
            curl_setopt($ch, CURLOPT_URL, $url);
            $data = curl_exec($ch);
            curl_close($ch);
        } catch (Exception $e) {
            $data = null;
        }
    }
    return $data;
}
/**
 * POST请求到URL并接收应答数据。
 */
function send_post($url, $post_data)
{
    $options = array(
        'http' => array(
            'method' => 'POST',
            'header' => 'Content-type:application/json',
            'content' => $post_data,
            'timeout' => 60 // 超时时间(单位:s)
        )
    );
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    return $result;
}
//写日志
function write_log($filename,$data){
    if(!is_string($data)){
        $data = json_encode($data);
    }
    $data = '['.date("Y-m-d H:i:s",time()).'] : '. $data;
    file_put_contents($filename,$data.PHP_EOL, FILE_APPEND);
}
//生成签名
function makeSign($params,$appkey,$sign_type=1){
    ksort($params);
    unset($params['sign']);
    $str = '';
    foreach($params as $key=>$val){
        if(is_array($val)){
            continue;
        }
        if($sign_type == 1 || !$sign_type){
            if(strlen($val) > 0){
                $str.= trim($val);
            }
        }else{
            if(strlen($val) > 0){
                $str.= trim($key).'='.trim($val);
            }
        }
    }
    $hash_hmac = hash_hmac('sha256', $str, $appkey, true);
    return urlencode(base64_encode($hash_hmac));
}
//生成订单号
function buildOrderId($bid)
{
    list($t1, $t2) = explode(' ', microtime());
    $orderId = sprintf('%.0f%03d', (floatval($t1) + floatval($t2)) * 1000, mt_rand(0, 999));
    return $orderId.rand(10,99) . substr(sprintf("%04d", $bid), -4);
}
//生成12位订单号
function build12OrderId($bid)
{
    return  substr(time().rand(10,99).substr(sprintf("%04d", $bid), -3),-12);
}
//生成token
function buildToken($bid){
    $str = md5(uniqid(md5(microtime(true)),true));
    $token = sha1($str.$bid);
    return $token;
}
//加密
function encryptToken($str){
    $passwd = config('Pay')['encryptStr'];
    $result = openssl_encrypt($str, 'DES-ECB', $passwd, 0);
    return $result;
}
//解密
function decryptToken($str){
    $passwd = config('Pay')['encryptStr'];
    $result = openssl_decrypt($str, 'DES-ECB', $passwd, 0);
    return $result;
}
function transPn($link,$pn){
    $arr = explode('&',$link);
    if(!empty($arr)){
        foreach($arr as $key=>$val){
            if(preg_match("/^pn=*/",$val)){
                $arr[$key] = 'pn='.$pn;
            }
        }
        $link = implode('&',$arr);
    }
    return $link;
}
function confusionPhone($phone){
    $confusionStr = rand(10,99);
    $tmpStr = substr($phone,0,strlen($phone) - 2);
    $confusionPhone = $tmpStr.$confusionStr;
    return $confusionPhone;
}
function confusionEmail($email){
    $arr1 = range( 'a', 'z' );
    $arr2 = range(1,9);
    $arr = array_merge($arr1,$arr2);
    $str = $arr[rand(0,count($arr) - 1)].$arr[rand(0,count($arr) - 1)];
    $tmpStr = substr($email,(strlen($email) - 2) * -1);
    $confusionEmail = $str.$tmpStr;
    return $confusionEmail;
}
function setOrderNo(){
    $order_no = date('Ymd').time();
    return $order_no;
}