ghController.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. // $BuildUrl = 'http://cldgh.com';
  27. //$url = $BuildUrl. '/auth/token?staffGH='. urlencode($_COOKIE ['staffGH']);
  28. $url = $BuildUrl. '/auth/token';
  29. $data=array("staffGH"=>$_COOKIE ['staffGH']);
  30. //echo $url;
  31. //echo $this->curl_request($url,$data);
  32. $result = json_decode($this->curl_request($url,$data), true);
  33. $result['staff']=$_COOKIE ['staff'];
  34. echo json_encode($result);
  35. //print_r($result);
  36. }
  37. /**
  38. * curl 获取接口数据,data为空时为GET方法,有值则为POST方法
  39. *
  40. * @param $url
  41. * @param string $data
  42. * @return mixed|string
  43. */
  44. function curl_request($url, $data = '') {
  45. $curl = curl_init();
  46. curl_setopt($curl, CURLOPT_URL, $url);
  47. curl_setopt($curl, CURLOPT_HEADER, 0);
  48. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  49. if($data) {
  50. curl_setopt($curl, CURLOPT_POST, 1);
  51. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  52. }
  53. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  54. $data = curl_exec($curl);
  55. curl_close($curl);
  56. return $data;
  57. }
  58. /**
  59. * 获取get或者POST值
  60. * @param string $name 属性名称
  61. * @return fixed 值
  62. */
  63. private function get_args($name) {
  64. if (isset ( $_GET [$name] )) {
  65. if (is_array ( $_GET [$name] ))
  66. return $_GET [$name];
  67. else {
  68. return addslashes ( $_GET [$name] );
  69. //return $_GET [$name] ;
  70. }
  71. } elseif (isset ( $_POST [$name] )) {
  72. if (is_array ( $_POST [$name] ))
  73. return $_POST [$name];
  74. else {
  75. return addslashes ( $_POST [$name] );
  76. //return $_POST [$name];
  77. }
  78. } else
  79. return false;
  80. }
  81. }
  82. ?>