小程序转发客服消息使用easychat

需求:

收到小程序卡片时,发送公众号二维码让其绑定,收到其他信息转发到网页客服系统

实现

收到消息,响应时回复一段xml如下,


    
    
    1399197672
    

ps

1其中 FromUserName 为小程序原始id,

2经实际测试消息推送配置里数据格式选xml才可以

代码

messageApp = $wechat->app;
        //微信首次接入验证
        if (!empty($_GET['echostr']) && $wechat->checkSignature()) {
            header('content-type:text');
            echo $_GET['echostr'];
            exit;
        }

    }


    public function index(Request $request)
    {
        $this->messageApp->server->push(function ($message) {

//
            $handler = new MessageHandler($message);
            switch ($message['MsgType']) {
                case 'miniprogrampage':
                    return $handler->miniProgramPageEvent();
                    break;
                default:
                    return $handler->transferEvent();
                    break;
            }
        });

        $response = $this->messageApp->server->serve();
        $response->send();
        //return $response;

    }
   
}


/**转发客服消息
     * @return Raw
     */
    public function transferEvent()
    {
        $openid = $this->message['FromUserName'];
        $appId = $this->message['ToUserName'];
        $createTine = $this->message['CreateTime'];
        $xml = "$createTine";
        $message = new Raw($xml);
        Log::write('mm:' . json_encode($message));
        return $message;
    }

 

你可能感兴趣的:(小程序,php,微信公众号)