1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Http\Controllers\Admin;
- use App\Log;
- use App\Models\TencentAdAuth;
- use App\Service\HttpService;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- class WxadCallbackController extends Controller
- {
- /**
- * 腾讯广告授权回调
- * @param Request $request
- * @return string
- */
- public function recive(Request $request)
- {
- $params = $request->all();
- //将所有接收到的参数记录下来
- Log::logInfo(json_encode($params), [], 'callBack');
- $authCode = $params['authorization_code'] ?? null;
- $group_id = $params['state'] ?? null;
- if (empty($authCode) || empty($group_id)) {
- return 'auth_code 和 用户组ID 不能为空';
- }
- $wxadConfig = config('wxad');
- $params['grant_type'] = 'authorization_code';
- $params['client_id'] = $wxadConfig['client_id'];
- $params['client_secret'] = $wxadConfig['client_secret'];
- $params['redirect_uri'] = $wxadConfig['redirect_uri'];
- $routeUrl = 'https://api.e.qq.com/oauth/token?'.http_build_query($params);
- $result = HttpService::httpGet($routeUrl);
- $result = json_decode($result, true);
- if(0 == $result['code']) {
- Log::logInfo(json_encode($result), $params, 'token-success');
- // header('Location:http://addata.kuxuan-inc.com/admin/index');
- $res = TencentAdAuth::inserOrUpdate($result['data'], $group_id);
- if ($res) return '授权成功';
- }
- Log::logError(json_encode($result), $params, 'token-error');
- return '授权失败';
- }
- }
|