think-wxminihelper icon indicating copy to clipboard operation
think-wxminihelper copied to clipboard

Notice: Can not open /dev/urandom.

Open mfkwvf opened this issue 7 years ago • 6 comments

请问怎么解决,我是linux服务器

mfkwvf avatar May 27 '17 04:05 mfkwvf

不同厂商的服务器获取随机数的方法不同吧,我用的是centos系统就是这个

wulongtao avatar Jun 25 '17 12:06 wulongtao

我也是centos 但是报错

mfkwvf avatar Jun 26 '17 02:06 mfkwvf

存的是sessionKey+openId 我怎么通过3rdsession获取到openId啊

casablanca92 avatar Oct 27 '17 01:10 casablanca92

You can use CSPRNG functions instead in php7 or higher versions to generate random numbers. It will use getrandom(2) or /dev/urandom on Linux. See https://secure.php.net/manual/zh/function.random-bytes.php

AnyMoe avatar Oct 29 '17 05:10 AnyMoe

微信官方的签名算法改变了,https://mp.weixin.qq.com/debug/wxadoc/dev/api/signature.html,到这里下载示例,将WXBizDataCrypt类和ErrorCode类覆盖到这个项目的类中就解决了问题。希望作者有空去修改一下。

xujinhui2015 avatar Nov 02 '17 07:11 xujinhui2015

Replace with

function RandomToken($length = 32){
    if(!isset($length) || intval($length) <= 8 ){
      $length = 32;
    }
    if (function_exists('random_bytes')) {
        return bin2hex(random_bytes($length));
    }
    if (function_exists('openssl_random_pseudo_bytes')) {
        return bin2hex(openssl_random_pseudo_bytes($length));
    }
    if (function_exists('mcrypt_create_iv')) {
        return bin2hex(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM));
    } 
}

AnyMoe avatar Dec 15 '17 15:12 AnyMoe