ghController.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ghController extends DooController {
  6. public $staff;
  7. function __construct() {
  8. if (isset ( $_COOKIE ["staff"] )) {
  9. if (! empty ( $_COOKIE ["staff"] )) {
  10. Doo::loadModel ( 'staff' );
  11. $staff = new staff ();
  12. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  13. return "";
  14. }
  15. }
  16. Doo::loadCore ( 'uri/DooUriRouter' );
  17. $router = new DooUriRouter ();
  18. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  19. if ($routeRs ['1'] != "login") {
  20. header ( 'Content-Type:text/html;charset=utf-8' );
  21. @header ( "Location: /login" );
  22. }
  23. }
  24. function authToken(){
  25. $BuildUrl = 'http://gh.cld.smartcost.com.cn';
  26. //$url = $BuildUrl. '/auth/token?staffGH='. urlencode($_COOKIE ['staffGH']);
  27. $url = $BuildUrl. '/auth/token';
  28. $data=array("staffGH"=>$_COOKIE ['staffGH']);
  29. //echo $url;
  30. //echo $this->curl_request($url,$data);
  31. $result = json_decode($this->curl_request($url,$data), true);
  32. $result['staff']=$_COOKIE ['staff'];
  33. echo json_encode($result);
  34. //print_r($result);
  35. }
  36. /**
  37. * curl 获取接口数据,data为空时为GET方法,有值则为POST方法
  38. *
  39. * @param $url
  40. * @param string $data
  41. * @return mixed|string
  42. */
  43. function curl_request($url, $data = '') {
  44. $curl = curl_init();
  45. curl_setopt($curl, CURLOPT_URL, $url);
  46. curl_setopt($curl, CURLOPT_HEADER, 0);
  47. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  48. if($data) {
  49. curl_setopt($curl, CURLOPT_POST, 1);
  50. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  51. }
  52. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  53. $data = curl_exec($curl);
  54. curl_close($curl);
  55. return $data;
  56. }
  57. /**
  58. * 获取get或者POST值
  59. * @param string $name 属性名称
  60. * @return fixed 值
  61. */
  62. private function get_args($name) {
  63. if (isset ( $_GET [$name] )) {
  64. if (is_array ( $_GET [$name] ))
  65. return $_GET [$name];
  66. else {
  67. return addslashes ( $_GET [$name] );
  68. //return $_GET [$name] ;
  69. }
  70. } elseif (isset ( $_POST [$name] )) {
  71. if (is_array ( $_POST [$name] ))
  72. return $_POST [$name];
  73. else {
  74. return addslashes ( $_POST [$name] );
  75. //return $_POST [$name];
  76. }
  77. } else
  78. return false;
  79. }
  80. }
  81. ?>