You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

98 lines
2.8 KiB

  1. <?php
  2. /**
  3. *
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm InterfaceUtil.php
  13. * Create By 2017/6/20 9:29 $
  14. */
  15. namespace common\util;
  16. class InterfaceUtil
  17. {
  18. /**
  19. * Des:获取参数
  20. * Name: getPost
  21. * @return array
  22. * @author 倪宗锋
  23. */
  24. public static function post()
  25. {
  26. $code = \Yii::$app->request->post('code', '');//加密字符串
  27. $time = \Yii::$app->request->post('time', '');//时间戳
  28. $codeStr = Util::authCode($code);
  29. parse_str($codeStr, $param);//将code转换成数组
  30. if (empty($param['time']) || $time != $param['time']) {
  31. return Util::returnArrEr('illegal request!');
  32. }
  33. if (intval($time + 60) < time()) {
  34. return Util::returnArrEr('time out!');
  35. }
  36. return Util::returnArrSu('', $param);
  37. }
  38. /**
  39. * Des:获取get参数
  40. * Name: get
  41. * @return array
  42. * @author 倪宗锋
  43. */
  44. public static function get()
  45. {
  46. $code = \Yii::$app->request->get('code', '');//加密字符串
  47. $time = \Yii::$app->request->get('time', '');//时间戳
  48. $codeStr = Util::authCode($code);
  49. parse_str($codeStr, $param);//将code转换成数组
  50. if ($time != $param['time']) {
  51. return Util::returnArrEr('illegal request!');
  52. }
  53. if (intval($time + 60) < time()) {
  54. return Util::returnArrEr('time out!');
  55. }
  56. return Util::returnArrSu('', $param);
  57. }
  58. /**
  59. * Des:返回错误 code模式
  60. * Name: returnEr
  61. * @param string $msg
  62. * @param string $data
  63. * @param int $code
  64. * @return string
  65. * @author 倪宗锋
  66. */
  67. public static function returnEr($msg = '', $data = '', $code = 1)
  68. {
  69. $return = array();
  70. $return['code'] = $code;
  71. $return['info'] = $msg;
  72. $return['data'] = $data;
  73. return json_encode($return);
  74. }
  75. /**
  76. * Des:返回成功 code模式
  77. * Name: returnSu
  78. * @param string $msg
  79. * @param string $data
  80. * @return string
  81. * @author 倪宗锋
  82. */
  83. public static function returnSu($msg = '', $data = '')
  84. {
  85. $return = array();
  86. $return['code'] = 0;
  87. $return['info'] = $msg;
  88. $return['data'] = $data;
  89. return json_encode($return);
  90. }
  91. }