企微短剧业务系统

Controller.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Error;
  4. use Illuminate\Foundation\Bus\DispatchesJobs;
  5. use Illuminate\Routing\Controller as BaseController;
  6. use Illuminate\Foundation\Validation\ValidatesRequests;
  7. use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
  8. class Controller extends BaseController
  9. {
  10. public $suiteId;
  11. public $appTemplateId;
  12. public $corpid;
  13. public $suiteSecret;
  14. /*
  15. * 初始化
  16. * */
  17. public function __construct()
  18. {
  19. $component = config('qyWechat.suite_info');
  20. $this->suiteId = $component['suite_id'];
  21. $this->appTemplateId = $component['app_template_id'];
  22. $this->corpid = $component['corpid'];
  23. $this->suiteSecret = $component['suite_secret'];
  24. $this->appTemplateSecret = $component['app_template_secret'];
  25. }
  26. use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
  27. public static function returnValue($data = [], $errorNo = 0, $errorSuffix = '') {
  28. return [
  29. "rst" => $data,
  30. "errno" => $errorNo . '',
  31. "err" => empty($errorSuffix) ? Error::getError($errorNo) : $errorSuffix,
  32. "timestamp" => intval(microtime(true)) . '',
  33. // 客户端代码版本号,用于客户端自动加载新提交的代码
  34. 'v' => (string) get_client_code_version(),
  35. "auno" => '0'
  36. ];
  37. }
  38. /**
  39. * 统一分页响应格式
  40. * @param $data
  41. * @param $total
  42. * @param $pageSize
  43. * @param int $page
  44. * @param null $extra
  45. * @return array
  46. */
  47. public static function returnPageValue($data, $total, $pageSize, $page, $extra = null)
  48. {
  49. $pages = $pageSize > 0 ? ceil($total / $pageSize) : 0;
  50. $result = [
  51. 'data' => $data,
  52. 'pageInfo' => [
  53. 'total' => $total,
  54. 'pages' => $pages,
  55. 'size' => $pageSize,
  56. 'page' => $page
  57. ]
  58. ];
  59. if( $extra !== null){
  60. $result['extra'] = $extra;
  61. }
  62. return self::returnValue($result);
  63. }
  64. }