首页 / PHP / 微信消息体加密php版
微信消息体加密php版
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了微信消息体加密php版,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2877字,纯文字阅读大概需要5分钟。
内容图文
![微信消息体加密php版](/upload/InfoBanner/zyjiaocheng/201/e33bd2ea52974a49a06a63180f7ea3c2.jpg)
responseMsg();class wechatCallbackapiTest{ public function valid() { $echoStr = $_GET["echostr"]; //valid signature , option if($this->checkSignature()){ echo $echoStr; exit; } } public function responseMsg() { include_once "wxBizMsgCrypt.php";$encodingAesKey = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG";$token = TOKEN;$timestamp = $_GET["timestamp"];$nonce = $_GET["nonce"];$appId = "wx47224801062443cc";$msg_sign = $_GET["msg_signature"];//解密$pc = new WXBizMsgCrypt($token, $encodingAesKey, $appId); //get post data, May be due to the different environments $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; $msg = '';$errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $postStr, $msg);if ($errCode == 0) { $postStr=$msg; if (!empty($postStr)){ /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection, the best way is to check the validity of xml by yourself */ libxml_disable_entity_loader(true); $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $keyword = trim($postObj->Content); $time = time(); $textTpl = ""; if(!empty( $keyword )) { $msgType = "text"; $contentStr = "Welcome to wechat world!"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); //加密 $encryptMsg = '';$errCode = $pc->encryptMsg($resultStr, $timeStamp, $nonce, $encryptMsg); if ($errCode == 0) { echo $encryptMsg ; } else { print($errCode . "\n"); } }else{ echo "Input something..."; } }else { echo ""; exit; } } else { print($errCode . "\n");} //extract post data } private function checkSignature() { // you must define TOKEN by yourself if (!defined("TOKEN")) { throw new Exception('TOKEN is not defined!'); } $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = TOKEN; $tmpArr = array($token, $timestamp, $nonce); // use SORT_STRING rule sort($tmpArr, SORT_STRING); $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); if( $tmpStr == $signature ){ return true; }else{ return false; } }}?> %s 0
内容总结
以上是互联网集市为您收集整理的微信消息体加密php版全部内容,希望文章能够帮你解决微信消息体加密php版所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。