public function __construct()
 {
     vendor("wechat");
     $wechat = new wechat();
     $wechat->valid();
     $wechat->createMenu();
 }
示例#2
0
<?php

include_once '../includePackage.php';
include_once $GLOBALS['mypath'] . '/wechat/interfaceHandler.php';
include_once $GLOBALS['mypath'] . '/wechat/wechat.php';
include_once $GLOBALS['mypath'] . '/wechat/serveManager.php';
include_once 'reply.php';
//mylog('reach');
$weixin = new wechat(WEIXIN_ID);
$myHandler = new interfaceHandler(WEIXIN_ID);
$weixin->valid();
$msg = $weixin->receiverFilter();
$random = rand(1000, 9999);
//mylog(getArrayInf($msg));
if (in_array($msg['MsgType'], array('text', 'voice', 'img'))) {
    //    mylog('inarray');
    $mode = getWechatMode($msg['from']);
    //    mylog($mode);
    switch ($mode) {
        case 'normal':
            normalReply($weixin, $msg);
            break;
        case 'kf':
            $weixin->toKFMsg();
            sendKFMessage($msg['from'], '您好,有什么可以帮助您?');
            break;
    }
}
if ($msg['MsgType'] == 'event') {
    include_once 'event.php';
    if (in_array($msg['Event'], array('VIEW', 'kf_create_session', 'kf_close_session'))) {
示例#3
0
<?php

header("Content-type:text/html;charset=utf-8");
require_once 'comm.php';
define("TOKEN", "goalfriend");
$wechat = new wechat();
if (isset($_GET['echostr'])) {
    $wechat->valid();
} else {
    $wechat->getMessage();
}
class wechat
{
    public function valid()
    {
        $echoStr = $_GET["echostr"];
        if ($this->checkSignature()) {
            echo $echoStr;
            exit;
        }
    }
    public function getMessage()
    {
        $object = $GLOBALS["HTTP_RAW_POST_DATA"];
        $object = simplexml_load_string($object, 'SimpleXMLElement', LIBXML_NOCDATA);
        $RX_TYPE = trim($object->MsgType);
        //获取消息类型
        switch ($RX_TYPE) {
            case "event":
                $result = $this->receiveEvent($object);
                break;