$openPlatform = Factory::openPlatform($config);
$server = $openPlatform->server;
$message = $server->getMessage();
switch ($message['InfoType']) {
case Guard::EVENT_AUTHORIZED:
// 处理授权成功事件
$server->push(function ($message) {
// ...
}, Guard::EVENT_AUTHORIZED);
break;
case Guard::EVENT_UPDATE_AUTHORIZED:
// 处理授权更新事件
$server->push(function ($message) {
// ...
}, Guard::EVENT_UPDATE_AUTHORIZED);
break;
case Guard::EVENT_UNAUTHORIZED:
// 处理授权取消事件
$server->push(function ($message) {
// ...
}, Guard::EVENT_UNAUTHORIZED);
break;
}
$server->serve()->send(); 2. 第三方平台上线前的检查代码 // 1.准备所有需要配置的东西
$openPlatform = Factory::openPlatform($config);
$server = $openPlatform->server;
$msg = $server->getMessage();
// 2.获取公众号信息所需要的信息
$gh_id = $msg['ToUserName'];
$openid = $msg['FromUserName'];
$app = Db::name('op_app')->where('username', $gh_id)->find();
// 3.通过接口把公众号的所有信息搞下来
$authinfo = $openPlatform->getAuthorizer($app['appid'])['authorization_info'];
$authappid = $authinfo['authorizer_appid'];
$authtoken = $authinfo['authorizer_refresh_token'];
// 第三方测试用的
switch ($msg['MsgType']) {
case 'event':
$cuservice = $openPlatform->officialAccount($authappid, $authtoken)->customer_service;
$cuservice->message($msg['Event'] . 'from_callback')
->from($gh_id)
->to($openid)
->send();
case 'text':
$cuservice = $openPlatform->officialAccount($authappid, $authtoken)->customer_service;
$word = $msg['Content'];
if ($word == 'TESTCOMPONENT_MSG_TYPE_TEXT') {
$cuservice->message($word . '_callback')
->from($gh_id)
->to($openid)
->send();
} elseif (strpos($word, 'QUERY_AUTH_CODE') == 0) {
echo '';
$code = substr($word, 16);
$authorizerInfo = $openPlatform->handleAuthorize($code)['authorization_info'];
$cuservice = $openPlatform->officialAccount($authorizerInfo['authorizer_appid'], $authorizerInfo['authorizer_refresh_token']);
$cuservice->customer_service->message($code . "_from_api")
->from($gh_id)
->to($openid)
->send();
}
}
ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。