zoukankan      html  css  js  c++  java
  • 微信公众号-加解密数据demo坑

    demo里面的MsgSignature作为url参数一部分了,demo也不更新下 坑爹的微信!

    解密信息部分

    include_once "wxBizMsgCrypt.php";
    
    $encodingAesKey = "spl6dEUAwsGWXrN9SkAfkMQ684b5d";//cuode
    $token          = "quhuodong";//cuode
    $appId          = "wxa5c3224";//cuode
    
    $timestamp = $_GET['timestamp'];
    $nonce     = $_GET['nonce'];
    $msg_sign  = $_GET['msg_signature'];
    
    $xml_tree = new DOMDocument();
    $xml_tree->loadXML(file_get_contents("php://input"));
    $array_e = $xml_tree->getElementsByTagName('Encrypt');
    $encrypt = $array_e->item(0)->nodeValue;
    
    $format   = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%s]]></Encrypt></xml>";
    $from_xml = sprintf($format, $encrypt);
    
    // 第三方收到公众号平台发送的消息
    $msg     = '';
    $pc      = new WXBizMsgCrypt($token, $encodingAesKey, $appId);
    $errCode = $pc->decryptMsg($msg_sign, $timestamp, $nonce, $from_xml, $msg);
    if ($errCode == 0) {
    	print("解密后: " . $msg . "
    ");
    } else {
    	print($errCode . "
    ");
    }
    

      

    修改一下:利用simplexml_load_string解析xml

    $xml     = simplexml_load_string(file_get_contents('../reqest20150506032946'));
    $encrypt = $xml->Encrypt;
    

      

  • 相关阅读:
    javascript中的预编译问题
    五环
    两列布局
    定位以及z-index
    [vijos1234]口袋的天空<最小生成树>
    [讲解]prim算法<最小生成树>
    [noip模拟]B<构造>
    [JZOJ5343]健美猫<模拟>
    [noip模拟]心<并查集>
    [noip模拟]种花<快速幂+结论>
  • 原文地址:https://www.cnblogs.com/jdhu/p/4481442.html
Copyright © 2011-2022 走看看