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;
    

      

  • 相关阅读:
    赴美工作常识(Part 4
    赴美工作常识(Part 3
    50 年前的黑客黑什么?
    孩子王?有孩子气才能为王?
    赴美工作常识(Part 2
    UE4 Keynote 1
    Go Programming Language 3
    Go Programming Language 2
    Go Programming Language
    Lua语法要点2
  • 原文地址:https://www.cnblogs.com/jdhu/p/4481442.html
Copyright © 2011-2022 走看看