企微短剧业务系统

WxadCallbackController.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Log;
  4. use App\Models\TencentAdAuth;
  5. use App\Service\HttpService;
  6. use Illuminate\Http\Request;
  7. use App\Http\Controllers\Controller;
  8. class WxadCallbackController extends Controller
  9. {
  10. /**
  11. * 腾讯广告授权回调
  12. * @param Request $request
  13. * @return string
  14. */
  15. public function recive(Request $request)
  16. {
  17. $params = $request->all();
  18. //将所有接收到的参数记录下来
  19. Log::logInfo(json_encode($params), [], 'callBack');
  20. $authCode = $params['authorization_code'] ?? null;
  21. $group_id = $params['state'] ?? null;
  22. if (empty($authCode) || empty($group_id)) {
  23. return 'auth_code 和 用户组ID 不能为空';
  24. }
  25. $wxadConfig = config('wxad');
  26. $params['grant_type'] = 'authorization_code';
  27. $params['client_id'] = $wxadConfig['client_id'];
  28. $params['client_secret'] = $wxadConfig['client_secret'];
  29. $params['redirect_uri'] = $wxadConfig['redirect_uri'];
  30. $routeUrl = 'https://api.e.qq.com/oauth/token?'.http_build_query($params);
  31. $result = HttpService::httpGet($routeUrl);
  32. $result = json_decode($result, true);
  33. if(0 == $result['code']) {
  34. Log::logInfo(json_encode($result), $params, 'token-success');
  35. // header('Location:http://addata.kuxuan-inc.com/admin/index');
  36. $res = TencentAdAuth::inserOrUpdate($result['data'], $group_id);
  37. if ($res) return '授权成功';
  38. }
  39. Log::logError(json_encode($result), $params, 'token-error');
  40. return '授权失败';
  41. }
  42. }