代码拉取完成,页面将自动刷新
<?php
header("Content-type:text/html;charset=utf-8");
require_once '../vendor/autoload.php';
/**
* Created by PhpStorm
* @Date: 2017/7/13
* @Time: 10:59
* @Author: eRic
* @Email: [email protected]
* @File: notify_url.php
*/
// 第三方发送消息给公众平台
include_once "../application/third_party/Dsanfang-php-msg/wxBizMsgCrypt.php";
use EasyWeChat\Foundation\Application;
use EasyWeChat\Message\Text;
use EasyWeChat\Staff\Staff;
$options = [
'mini_program' => [
'app_id' => 'wx303239e774ece00c',
'secret' => 'b346a5a6c7633c4518b126ec8ec0ef9a',
// token 和 aes_key 开启消息推送后可见
'token' => 'ZuODgDbE0yn2iZ5cr5gEddkK',
'aes_key' => 'BxC7mexFZuODgDbE0yn2iZ5cr5gEddkKvHxSqzwyeYG'
],
];
$encrypt2_data = file_get_contents ( 'php://input' );
error_log(print_r(array("encrypt2_data" => $encrypt2_data),true),3,'log.txt');
$evtk = '';
$app = new Application($options);
$staff = $app->staff; // 客服管理
$message = new Text(['content' => 'Hello world!']);
$openId = "oYaHv0L1F8IwfZ_bHyTmo08Rqpns";
$result = $staff->message($message)->to($openId)->send();
error_log(print_r(array("消息" => $result),true),3,'log.txt');
echo "success";
exit;
/*$server = $app->server;
$server->setMessageHandler(function($message){
// 注意,这里的 $message 不仅仅是用户发来的消息,也可能是事件
// 当 $message->MsgType 为 event 时为事件
if ($message->MsgType == 'event') {
$evtk = $message->Event;
}
});*/
exit;
$encodingAesKey = "BxC7mexFZuODgDbE0yn2iZ5cr5gEddkKvHxSqzwyeYG";
$token = "ZuODgDbE0yn2iZ5cr5gEddkK";
$timeStamp = time();
$nonce = "2343".time();
$appId = "wx303239e774ece00c";
$text = "<xml><ToUserName><![CDATA[oia2Tj我是中文jewbmiOUlr6X-1crbLOvLw]]></ToUserName><FromUserName><![CDATA[gh_7f083739789a]]></FromUserName><CreateTime>1407743423</CreateTime><MsgType><![CDATA[video]]></MsgType><Video><MediaId><![CDATA[eYJ1MbwPRJtOvIEabaxHs7TX2D-HV71s79GUxqdUkjm6Gs2Ed1KF3ulAOA9H1xG0]]></MediaId><Title><![CDATA[testCallBackReplyVideo]]></Title><Description><![CDATA[testCallBackReplyVideo]]></Description></Video></xml>";
$pc = new WXBizMsgCrypt($token, $encodingAesKey, $appId);
$encryptMsg = '';
$errCode = $pc->encryptMsg($text, $timeStamp, $nonce, $encryptMsg);
if ($errCode == 0) {
//print("加密后: " . $encryptMsg . "\n");
} else {
//print($errCode . "\n");
}
$xml_tree = new DOMDocument();
$xml_tree->loadXML($encryptMsg);
$array_e = $xml_tree->getElementsByTagName('Encrypt');
$array_s = $xml_tree->getElementsByTagName('MsgSignature');
$encrypt = $array_e->item(0)->nodeValue;
$msg_sign = $array_s->item(0)->nodeValue;
$format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%s]]></Encrypt></xml>";
$from_xml = sprintf($format, $encrypt);
// 第三方收到公众号平台发送的消息
//$msg = "123456";
$errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $from_xml, $msg);
if ($errCode == 0) {
//print("解密后: " . $msg . "\n");
} else {
//print($errCode . "\n");
}
$_REQUEST['msg'] = $msg;
$_REQUEST['errCode'] = $errCode;
$_REQUEST['evtk'] = $evtk;
$_REQUEST['encryptMsg'] =$encryptMsg;
error_log(print_r($_REQUEST,true),3,'log.txt');
//echo "123";
echo "success";
?>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。