微信第三方开发:处理消息和事件页面发送文字信息

来源:互联网 发布:淘宝摄影棚灯光布置 编辑:程序博客网 时间:2024/04/30 05:15
<span style="font-size:18px;">include_once "../lib/wxBizMsgCrypt.php";$wxData = include_once "../lib/wxConfig.php";// 第三方发送消息给公众平台$encodingAesKey = $wxData['SecretKey'];$token = $wxData['Token'];$appId = $wxData['AppId'];$appSecret = $wxData['AppSecret'];$timeStamp = empty ( $_GET ['timestamp'] ) ? '' : trim ( $_GET ['timestamp'] );  $nonce = empty ( $_GET ['nonce'] ) ? '' : trim ( $_GET ['nonce'] );  $msg_sign = empty ( $_GET ['msg_signature'] ) ? "" : trim ( $_GET ['msg_signature'] ); $encrypt_type = empty ( $_GET ['encrypt_type'] ) ? "" : trim ( $_GET ['encrypt_type'] ); $encryptMsg = file_get_contents ( 'php://input' );  $pc = new WXBizMsgCrypt ( $token, $encodingAesKey, $appId ); include_once "../lib/wxHelper.php";$helper = new wxHelper();$msg = "";$errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $encryptMsg, $msg);if ($errCode == 0) {    $helper->set_php_file("../lib/static/component_verify_ticket_un.php", $msg);    $data = $helper->xmlToArr ( $msg );    $fromUsername = $data['FromUserName'];    $toUsername = $data['ToUserName'];    $keyword = trim($data['Content']);    $time = time();    $textTpl = "<xml>                <ToUserName><![CDATA[%s]]></ToUserName>                <FromUserName><![CDATA[%s]]></FromUserName>                <CreateTime>%s</CreateTime>                <MsgType><![CDATA[%s]]></MsgType>                <Content><![CDATA[%s]]></Content>                <FuncFlag>0</FuncFlag>                </xml>";     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 {            echo $errCode;        }    }else{        echo "Input something...";    }  }else{    echo "not success";}</span>

0 0
原创粉丝点击