123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace frontend\base;
- use Yii;
- use yii\web\Response;
- class Help
- {
- const ERROR = 300;
- const SUCCESS = 200;
- public static function JsonData($code,$msg,$count = 0,$data)
- {
- Yii::$app->response->format = Response::FORMAT_JSON;
- $list['code'] = $code;
- $list['msg'] = $msg;
- $list['count'] = $count;
- $list['data'] = !empty($data) ? $data : [] ;
- return $list;
- }
-
- public static function JsonCode($code,$msg = '',$data = null)
- {
- Yii::$app->response->format=Response::FORMAT_JSON;
- $list['code'] = $code;
- $list['msg'] = $msg;
- $list['data'] = $data;
- return $list;
- }
- public static function Attributes($model,$model1)
- {
- }
-
- public static function SetAttr($input,$model,$setModel)
- {
- if(is_array($input))
- {
- foreach ($input as $key=>$val)
- {
- if(isset($model[$key]))
- {
- $setModel[$key] = $model[$key];
- }
- }
- return $setModel;
- }
- }
-
- public function AjaxRequest($event)
- {
- if(empty($event->data['path']) || empty($event->data['data'])) return false;
- $host = $_SERVER['HTTP_HOST'];
- $query_Data = http_build_query($event->data['data']);
- $fp = fsockopen($host, 80, $errno, $errstr, 30);
- if (!$fp) {
- return false;
- }
- $out = "POST ".$event->data['path']." HTTP/1.1\r\n";
- $out .= "Host: $host\r\n";
- $out .= "Content-type: application/x-www-form-urlencoded\r\n";
- $out .= "Content-Length: ".strlen($query_Data)."\r\n";
- $out .= "Connection: Close\r\n\r\n";
- $out .= $query_Data;
- fwrite($fp, $out);
-
- fclose($fp);
- }
- }
|