| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace app\v1\controller\advert;
- use app\v1\logic\advert\MediaListLogic;
- use app\v1\validate\advert\MediaListValidate;
- use plugin\saiadmin\basic\BaseController;
- use support\Request;
- use support\Response;
- /**
- * 媒体开发者账号-应用授权回调地址
- */
- class MediaOAuthController extends BaseController
- {
- /**
- * 构造函数
- */
- public function __construct()
- {
- $this->logic = new MediaListLogic();
- parent::__construct();
- }
- /**
- * https://api.com/MediaOAuth/callback/{channel}
- * state={cmid:1}
- * cmid 是广告app的表id
- */
- public function callback(Request $request, string $channel): Response
- {
- $callback = $request->get();
- $channel = ucfirst($channel); // 如 "toutiao" → "Toutiao""
- $channelClass = "app\\adapter\\{$channel}Adapter"; // 适配器类名
- $oathInfo = (new $channelClass)->OAuth($callback);
- // 写授权结果
- (new $channelClass)->writeOAuthResult($oathInfo);
- // 写入广告账户列表
- (new $channelClass)->getSubAccounts($oathInfo);
- // 刷新token
- (new $channelClass)->refreshToken($oathInfo);
- return $this->success();
- }
- }
|