<p>无法与<em>PHP</em>一起工作。<br/>根据<a href="https://docs.python.org/3/library/zlib.html#zlib.crc32" rel="nofollow noreferrer">[Python 3]: zlib.<strong>crc32</strong>(<em>data[, value]</em>)</a>(<strong>强调</strong>是我的):</p>
<blockquote>
<p>Computes a CRC (Cyclic Redundancy Check) checksum of <em>data</em>. The result is an <strong>unsigned 32-bit integer</strong>.</p>
</blockquote>
<p>你在混淆:</p>
<ul>
<li>它的值-也可以看作长度为4的ASCII</em>字符串</li>
<li>其值的文本表示形式(in<strong>base<em>16</em></strong>),它是一个长度为8的字符串</li>
</ul>
<blockquote>
<pre class="lang-py prettyprint-override"><code>>>> crc = 0x2B3257EE # The value returned by zlib.crc32 for your text
>>> type(crc), crc
(<class 'int'>, 724719598)
>>>
>>> [chr((crc >> shift_bits) & 0xFF) for shift_bits in [0, 8, 16, 24]]
['î', 'W', '2', '+']
</code></pre>
</blockquote>
<p><strong>注意事项</strong>:</p>
<ul>
<li>一种方法是将数字的4个字节转换成<em>字符</em></li>
<li>要从<em>uint32</em>值中获取一个字节,必须将<em>uint32</em>按值(<strong><em>[3,2,1,0]</em></em>)乘以<strong><em>8</em></strong>的<em>字节</em>的顺序向右移动(<a href="https://wiki.python.org/moin/BitwiseOperators" rel="nofollow noreferrer">[Python.Wiki]: BitwiseOperators</a>)
<ul>
<li>另外,为了去除不需要的字节(除最右边的字节以外的任何字节),结果值也是<em>和</em>ed,并使用<em>0xFF</em>(<em>255</em>)</li>
</ul></li>
<li>由于<em>little endian</em>ness,字节按相反的顺序(从右到左)转换为<em>char</em>s</li>
<li>1<sup>st</sup><em>char</em>(<code>'î'</code>)看起来不同,但只是一个表示问题(在我的控制台<em>vs</em>您的控制台中)</li>
</ul>
<p>将其集成到代码中,您需要修改<em>crc32b</em>函数(并删除对<em>hashD</em>的任何进一步处理)以:</p>
<pre class="lang-py prettyprint-override"><code>def crc32b(x):
crc = zlib.crc32(x)
return "".join([chr((crc >> shift_bits) & 0xFF) for shift_bits in [0, 8, 16, 24]])
</code></pre>
<p>有关此一般主题的详细信息,请检查<a href="https://stackoverflow.com/questions/37990060/python-struct-pack-behavior/38003729#38003729">[SO]: Python struct.pack() behavior (@CristiFati's answer)</a>。在</p>
<p><strong><em>@EDIT0</em></strong>:</p>
<p>添加从<em>十六进制</em>表示形式开始的版本:</p>
<blockquote>
<pre class="lang-py prettyprint-override"><code>>>> crc = 0x2B3257EE
>>> crc_hex = "{:08X}".format(crc)
>>> crc_hex
'2B3257EE'
>>>
>>> list(reversed([chr(int(crc_hex[2 * i] + crc_hex[2 * i + 1], 16)) for i in range(len(crc_hex) // 2)]))
['î', 'W', '2', '+']
</code></pre>
</blockquote>
<ul>
<li>从我的<em>PoV</em>来看,这更难看,而且效率也很低(许多来回转换),但无论如何都要发布,因为有些人在位操作上有困难</li>
<li>关键点是一次处理2<em>hex</em><em>char</em>s,只有在转换后才能反转</li>
</ul>