Ruby 微信开发中消息加解密的实现

bmmz · August 08, 2016 · Last by ruby_sky replied at August 08, 2016 · 3238 hits

微信消息有加密模式。格式如下

new_msg=
<xml> 
    <ToUserName><![CDATA[toUser]]</ToUserName>
       <Encrypt><![CDATA[msg_encrypt]]</Encrypt>
</xml>

其中,msg_encrypt = Base64_Encode( AES_Encrypt[ random(16B) + msg_len(4B) + msg + $AppId] )

AES 加密的 buf 由 16 个字节的随机字符串、4 个字节的 msg_len(网络字节序)、msg 和$AppId 组成,其中 msg_len 为 msg 的长度,$AppId 为公众帐号的 AppId

AESKey =Base64_Decode(EncodingAESKey + “=”),32 个字节 其中 AES_Encrypt 这个函数在 ruby 中有没有现成的实现函数。请各位开发过微信相关功能的不吝赐教。

You need to Sign in before reply, if you don't have an account, please Sign up first.