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;
    

      

  • 相关阅读:
    docker构建镜像
    SpringBoot 配置的加载
    Gradle实战(02)--Gradle Build的创建
    Gradle实战(01)--介绍与安装
    统计最常用10个命令的脚本
    jackson序列化与反序列化的应用实践
    go http请求流程分析
    java线程的3种实现方式及线程池
    git多账号使用
    java多版本管理
  • 原文地址:https://www.cnblogs.com/jdhu/p/4481442.html
Copyright © 2011-2022 走看看