微信开发

  1. 作者QQ:67065435 QQ群:821635552

  2. 本站内容全部为作者原创,转载请注明出处!

由于微信开发文档阅读时比较混乱,现整理如下: 部分细节本处未整理,比如access_token存在有效期、获取新access_token后旧access_token依然有5分钟有效期等...

公众平台

  1. 开发测试工具

  2. 先获取: appid、appsecret

  3. 获取access_token

  4. 先获取:access_token

  5. 发送客服消息

  6. 先调整: 开发→基本配置

  7. 接收用户消息
  8. 接收事件推送
  9. 被动回复消息

  10. 先绑定: 微信开放平台(如果不需要Unionid,非必须)

  11. 网页授权
  12. Unionid机制

  13. 批量获取用户信息

  14. openid批量获取
  15. openid获取用户信息

  16. 消息加解密核心代码

    <?php
    function msgDecrypt($encrypt, $encode_key)
    {
        //处理$encode_key
        $encode_key = base64_decode("{$encode_key}=");
        $substr_key = substr($encode_key, 0, 16);
        //解密消息
        $decrypt = base64_decode($encrypt);
        $decrypt = openssl_decrypt($decrypt, 'AES-256-CBC', $encode_key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $substr_key);
        $decrypt = substr($decrypt, 0, (strlen($decrypt) - ord(substr($decrypt, -1))));
        $decrypt = substr($decrypt, 16, strlen($decrypt));
        $lens = unpack("N", substr($decrypt, 0, 4));
        $lenx = $lens[1];
        $decrypt = substr($decrypt, 4, $lenx);
        $decrypt = simplexml_load_string($decrypt, 'SimpleXMLElement', LIBXML_NOCDATA);
        $result = json_decode(json_encode($decrypt, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), true);
        return $result;
    }
    
    function msgEncrypt($xml, $encode_key)
    {
        //处理$encode_key
        $encode_key = base64_decode("{$encode_key}=");
        $substr_key = substr($encode_key, 0, 16);
        //加密消息
        $str_16 = '';
        $char_list = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        for ($i = 0; $i < 16; $i++) {
            $str_16 .= $char_list[mt_rand(0, strlen($char_list) - 1)];
        }
        $xml = $str_16 . pack('N', strlen($xml)) . $xml . $this->config['app_id'];
        $block_size = 32;
        $xml_len = strlen($xml);
        $append_len = $block_size - ($xml_len % $block_size);
        $append_chr = chr($append_len);
        $end_str = '';
        for ($i = 0; $i < $append_len; $i++) {
            $end_str .= $append_chr;
        }
        $encrypt = $xml . $end_str;
        $encrypt = openssl_encrypt($encrypt, 'AES-256-CBC', $encode_key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $substr_key);
        $encrypt = base64_encode($encrypt);
        return $encrypt;
    }
    
Copyright © 豆包嘿嘿~ 2012-∞ 冀ICP备17033181号 all right reserved,powered by Gitbook修订: 12-12-31 12:00

results matching ""

    No results matching ""