授权流程技术说明:
https://developers./doc/oplatform/Third-party_Platforms/Authorization_Process_Technical_Description.html
第三方平台的申请和上线流程:
https://developers./doc/oplatform/Third-party_Platforms/how_to_apply.html
在公众号第三方平台创建审核通过后,微信服务器会向其“授权事件接收URL”每隔 10 分钟推送一次 component_verify_ticket。
SDK 内部已实现缓存 component_veirfy_ticket,开发者无需另行处理该事件。
其余事件需要开发者自行处理。
注:需要在URL路由中写上触发代码,并且注册路由后需要等待微信服务器推送 component_verify_ticket,才有权限进行其他操作,否则报”Component verify ticket does not exists.”
2.路由配置
// 假设你的开放平台第三方平台设置的授权事件接收 URL 为: /accept (其他事件推送同样会推送到这个 URL)Route::any('accept', function () { // 关闭 CSRF// config里面的4个参数 都是开放平台里面的 拿过来就好了$config = ['app_id' => 'xxxxx','secret' => 'xxxx','token' => 'xxxx','aes_key' => 'xxxx'];$openPlatform = \EasyWeChat\Factory::openPlatform($config);return $openPlatform->server->serve(); // Done!});
3.控制器接口
//授权
public function auth(){$re=$this->openPlatform->getPreAuthorizationUrl('/index');echo "<div style='margin:0 auto;'><h2><a href='{$re}'>授权</a></h2></div>";die;}
//回调
public function index(){$server = $this->openPlatform-->server;$server->setMessageHandler(function($event) use ($openPlatform) {dd($event);// 事件类型常量定义在 \EasyWeChat\OpenPlatform\Guard 类里switch ($event->InfoType) {case Guard::EVENT_AUTHORIZED: // 授权成功$authorizationInfo = $openPlatform->getAuthorizationInfo($event->AuthorizationCode);//此处省略。。。。。。}});}
注意:步骤2中的 路由配置提到线上10分钟之后 访问: /accept 点击页面中的授权 即可得到如下页面