| 
					
				 | 
			
			
				@@ -1,547 +0,0 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-<?php namespace Api\Lib;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-use Dever;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-class Platform
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-{
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected $platform;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected $info;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected $field;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    # 设置基本信息
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected function setting($id, $field = array())
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->info = Dever::db($this->type, 'api')->find($id);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (!$this->info) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return false;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->field = $field;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->platform = Dever::db('platform', 'api')->find($this->info['platform_id']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (!$this->platform) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return false;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->field['host'] = $this->platform['host'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->field['uri'] = $this->info['uri'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->field['time'] = time();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->field['timestamp'] = \Dever\Helper\Secure::timestamp();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->field['nonce'] = \Dever\Helper\Secure::nonce();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $setting = Dever::db('platform_setting', 'api')->select(array('platform_id' => $this->platform['id']));
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($setting) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            foreach ($setting as $k => $v) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (isset($field[$v['key']])) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $v['value'] = $field[$v['key']];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $this->field[$v['key']] = $v['value'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return $this;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    # 发起请求
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected function curl($url = false)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (!$url) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $url = $this->url();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $header = $body = array();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $method = 'get';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $json = false;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->info['method'] == -1) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $this->info['method'] = $this->platform['method'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $this->info['post_method'] = $this->platform['post_method'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->info['post_method'] == 2) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $method = 'file';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($this->info['method'] == 2) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $method = 'post';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->field['method'] = $method;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->info['post_method'] == 3) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $json = true;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        # 标准请求体
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->request($body, 'platform_request_body', array('platform_id' => $this->platform['id']));
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (method_exists($this, 'requestBody')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $this->requestBody($body);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->field['body'] = $body;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->field['body_json'] = $body ? Dever::json_encode($body) : '';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $sign = '';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->sign($body, $sign);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        # 标准请求头
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->request($header, 'platform_request_header', array('platform_id' => $this->platform['id']));
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (method_exists($this, 'requestHeader')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $this->requestHeader($header);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->field['header'] = $header;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $response = Dever::curl($url, $body, $method, $json, $header)->result();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $test = Dever::input('test');
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($test && $test == 1) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $result = array
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            (
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                'url' => $url,
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                'header' => $header,
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                'method' => $method,
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                'json' => $json,
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                'sign' => $sign,
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                'body' => $body,
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                'response' => $response,
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            );
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            echo Dever::json_encode($result);die;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $response = $this->response($response);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $response['request'] = $body;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return $response;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    # 处理url
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected function url()
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (strstr($this->info['uri'], 'http')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $this->platform['host'] = '';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $uri = Dever::db('api_uri', 'api')->select(array('api_id' => $this->info['id']));
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($uri) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $path = array();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $param = array();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            foreach ($uri as $k => $v) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $v['value'] = $this->value(array(), $v['key'], $v['value']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if ($v['type'] == 1) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $path[] = $v['value'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } elseif ($v['type'] == 2) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $path[] = $v['key'] . '/' . $v['value'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } elseif ($v['type'] == 3) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $path[] = $v['key'] . '=' . $v['value'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } elseif ($v['type'] == 4) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $param[] = $v['value'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } elseif ($v['type'] == 5) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $param[] = $v['key'] . '=' . $v['value'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($path) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $this->info['uri'] .= implode('/', $path);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($param) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (!strstr($this->info['uri'], '?')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $this->info['uri'] .= '?';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $this->info['uri'] .= implode('&', $param);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->field['uri'] = $this->info['uri'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return $this->platform['host'] . $this->info['uri'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    # 获取请求参数
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected function request(&$data, $table, $where)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $request = Dever::db($table, 'api')->select($where);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($request) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            foreach ($request as $k => $v) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $value = $this->value($data, $v['key'], $v['value'], $v['type']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if ($value) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $data[$v['key']] = $value;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $this->field[$v['key']] = $value;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    # 数据响应格式处理
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected function response($response)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->platform['response_type'] == 1) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $response = $this->filter($response);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return array
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            (
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                'status' => 1,
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                'msg' => 'ok',
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                'response' => false,
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                'request' => array(),
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                'data' => $response,
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            );
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->platform['response_type'] == 2) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $response = Dever::json_decode($response);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($this->platform['response_type'] == 3) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $response = (array) simplexml_load_string($response);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } else {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (strstr($response, ',')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $response = explode(',', $response);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } elseif (strstr($response, ' ')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $response = explode(' ', $response);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } elseif (strstr($response, '|')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $response = explode('|', $response);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $response = explode("\n", $response);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $msg = 'no';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $status = 2;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->platform['response_code'] && isset($response[$this->platform['response_code']])) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $code = $response[$this->platform['response_code']];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $code = Dever::db('response_code', 'api')->find(array('platform_id' => $this->platform['id'], 'value' => $code));
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($code && $code['type'] == 1) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $status = 1;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->platform['response_msg'] && isset($response[$this->platform['response_msg']])) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $msg = $this->platform['response_msg'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $data = $response;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->platform['response_data']) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (strstr($this->platform['response_data'], ',')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $temp = explode(',', $this->platform['response_data']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                foreach ($temp as $k => $v) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (isset($response[$v])) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        $data = $response[$v];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        break;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } elseif (strstr($this->platform['response_data'], '.')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $temp = explode('.', $this->platform['response_data']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $data = isset($response[$temp[0]][$temp[1]]) ? $response[$temp[0]][$temp[1]] : (isset($response[$temp[0]]) ? $response[$temp[0]] : false);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $data = $response[$this->platform['response_data']] ?? $response;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($data) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (method_exists($this, 'responseHandle')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $this->responseHandle($data);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return array
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        (
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            'status' => $status,
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            'msg' => $msg,
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            'response' => $response,
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            'request' => array(),
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            'data' => $data,
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        );
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected function sign(&$body, &$string)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->platform['sign_method'] == -1) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->platform['sign_sort'] == 3) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ksort($body);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->field['sign_name'] = $this->platform['sign_name'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $sign = array();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->info['sign_col']) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $this->col($this->info['sign_col'], $body, $sign);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($this->platform['sign_col']) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $this->col($this->platform['sign_col'], $body, $sign);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } else {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $sign = $body;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->platform['sign_sort'] == 2) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ksort($sign);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $split = $this->platform['sign_split'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (strstr($split, '\\')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $split = preg_replace_callback(
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                '/\\\\([nrtf])/', // 匹配 \n, \r, \t, \f 等特殊字符
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                function ($matches) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $map = [
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        'n' => "\n",
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        'r' => "\r",
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        't' => "\t",
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        'f' => "\f"
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    ];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    return $map[$matches[1]]; // 直接从映射中获取替换值
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                },
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $split
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            );
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $string = '';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        foreach ($sign as $k => $v) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($this->platform['sign_empty'] == 2 && !$v) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                continue;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($this->platform['sign_encode'] == 2 && strstr($v, 'http')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $v = urlencode($v);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (isset($body[$k])) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $body[$k] = $v;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($this->platform['sign_type'] == 1) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $string .= $v;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } elseif ($this->platform['sign_type'] == 2) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $string .= $k . '=' . $v;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } elseif ($this->platform['sign_type'] == 3) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $string .= $k . $v;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $string .= "{$split}";
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $sign = rtrim($string, $this->platform['sign_split']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->platform['sign_method'] == -2) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $sign = md5($sign);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($this->platform['sign_method'] == -3) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $sign = hash("sha256", $sign);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($this->platform['sign_method'] == -4) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $sign = sha1($sign);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } else {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $sign = $this->encrypt($this->platform['sign_method'], $sign);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->platform['sign_after'] == 2) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $sign = strtoupper($sign);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($this->platform['sign_after'] == 2) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $sign = strtolower($sign);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->platform['sign_name']) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $body[$this->platform['sign_name']] = $sign;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $this->field['sign'] = $sign;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return $sign;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected function col($col, $body, &$sign)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $col = explode('+', $col);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        foreach ($col as $k => $v) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($v == 'body') {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $sign = array_merge($body, $sign);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $k = $v;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (strstr($v, '=')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $t = explode('=', $v);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $v = $t[1];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $k = $t[0];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $sign[$k] = $this->value($body, $v, $v, 1);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected function value($data, $key, $value, $type = 1)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $value = trim($value);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($this->field && isset($this->field[$value])) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $value = $this->field[$value];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($value == 'notify') {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $value = $this->createNotify($this->field['order_num'] ?? '');
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($value == 'token') {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $value = $this->token(1, 'token');
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($value == 'ticket') {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $value = $this->token(2, 'ticket');
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif (strstr($value, 'key=') && strstr($value, '&')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            parse_str($value, $temp);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $k = $temp['key'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            unset($temp['key']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (isset($this->field[$k]) && isset($temp[$this->field[$k]])) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $value = $temp[$this->field[$k]];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($a = strstr($value, '{') || strstr($value, '(')) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($a) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $field = $this->field;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $func = function ($r) use($field) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    return $this->value($field, $r[1], $r[1]);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                };
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $value = preg_replace_callback('/{(.*?)}/', $func, $value);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $value = '$value = '.$value.';';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            eval($value);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (!$value) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $key = trim($key);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return Dever::input($key);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (is_array($value)) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $value = Dever::json_encode($value);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($type == 1 || $type == 100) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $value = (string) $value;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($type == 2 || $type == 200) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $value = (float) $value;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($type == 3 && is_array($value)) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $value = Dever::json_encode($value);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($type == 4) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $value = $this->encrypt($value);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($type == 300 && is_array($value)) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $value = Dever::json_decode($value);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($type == 400) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $value = $this->decrypt($value);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return $value;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected function service($data)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        # 转换处理
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $convert = Dever::db('convert', 'api')->select(array('platform_id' => $this->platform['id']));
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $param = array();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($convert && is_array($data)) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (isset($data[0])) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                foreach ($data as $k1 => $v1) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    foreach ($convert as $k => $v) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        if (isset($data[$k1][$v['before']])) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            $param[$k1][$v['after']] = $data[$k1][$v['before']];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                foreach ($convert as $k => $v) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (isset($data[$v['before']])) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        $param[$v['after']] = $data[$v['before']];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } else {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $param = $data;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        # 具体业务处理,这里先不做
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //Dever::load('channel/lib/service')->act($this->channel['id'], $this->info['service_id'], $this->type, $this->info['id'], $param);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return $param;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected function token($id = 1, $type = 'token')
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return '';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $db = Dever::db($type, 'api');
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $data['platform_id'] = $connect['id'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $data['api_id'] = $api['id'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $info = $db->find($data);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($info && time() - $info['mdate'] >= $info['expires']) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } elseif ($info) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return $info['value'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $result = $this->init()->curl();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (isset($result[$type])) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $data['value'] = $result[$type];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $data['expires'] = '7200';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (isset($result['expires'])) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $data['expires'] = $result['expires'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($info) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $data['where_id'] = $info['id'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $db->update($data);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $db->insert($data);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return $result[$type];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return '';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected function encrypt($ssl_id, $value)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $ssl = $this->ssl($ssl_id, 1, $value);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($ssl) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($ssl['type'] == 1) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # 非对称
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                openssl_public_encrypt($ssl['value'], $value, $ssl['cert'], $ssl['option']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } elseif ($ssl['type'] == 2 && $ssl['cipher_algo']) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # 对称
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $value = openssl_encrypt($ssl['value'], $ssl['cipher_algo'], $ssl['cert'], $ssl['option'], $ssl['iv'], $ssl['tag'], $ssl['aad'], $ssl['tag_len']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } elseif ($ssl['type'] == 3 && $ssl['cipher_algo']) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # 签名
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                openssl_sign($ssl['value'], $value, $ssl['cert'], $ssl['cipher_algo']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($ssl['after'] == 2) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $value = base64_encode($value);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return $value;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected function decrypt($ssl_id, $value)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (is_array($value)) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $value = Dever::json_encode($value);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $ssl = $this->ssl($ssl_id, 2, $value);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($ssl) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($ssl['after'] == 2) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $value = Dever::base64_decode($value);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($ssl['type'] == 1) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # 非对称
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                openssl_public_decrypt($ssl['value'], $value, $ssl['key'], $ssl['option']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } elseif ($ssl['type'] == 2 && $ssl['cipher_algo']) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # 对称
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $value = openssl_decrypt($ssl['value'], $ssl['cipher_algo'], $ssl['key'], $ssl['option'], $ssl['iv'], $ssl['tag'], $ssl['aad'], $ssl['tag_len']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } elseif ($ssl['type'] == 3 && $ssl['cipher_algo']) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # 签名验证
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $value = openssl_verify($ssl['value'], $value, $ssl['key'], $ssl['cipher_algo']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return $value;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected function ssl($ssl_id, $type, $value)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $ssl = Dever::db('platform_ssl', 'api')->find($ssl_id);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (!$ssl) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return false;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $ssl['value'] = $value;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $key = $type == 1 ? 'encrypt' : 'decrypt';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $ssl['cert_type'] = $ssl[$key . '_cert_type'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $ssl['cert'] = $ssl[$key . '_cert'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $ssl['cert_id'] = $ssl[$key . '_cert_id'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($ssl['cert_type'] == 3) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            # 公钥
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $ssl['cert'] = $this->field[$ssl['cert']] ?? $ssl['cert'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } else {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $cert = Dever::db('platform_cert', 'api')->find($ssl['cert_id']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $this->field['serial_no'] = $cert['number'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($ssl['cert_type'] == 2) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $key = 'private';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $method = 'openssl_get_privatekey';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $key = 'public';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $method = 'openssl_x509_read';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $ssl['cert'] = str_replace(Dever::host() . 'data/', Dever::data(), $cert[$key]);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $ssl['cert'] = $method(file_get_contents($ssl['cert']));
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (!$ssl['cert']) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return false;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        # 对称加密需要特殊处理一下
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if ($ssl['type'] == 2) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (!$ssl['option']) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $ssl['option'] = 'OPENSSL_NO_PADDING';
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $ssl['option'] = constant($ssl['option']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($padding === null) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $ssl['option'] = OPENSSL_NO_PADDING;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $ssl['iv'] = $this->field[$ssl['iv']] ?? $ssl['iv'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $ssl['aad'] = $this->field[$ssl['aad']] ?? $ssl['aad'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($ssl['tag_len']) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $ssl['tag'] = substr($ssl['value'], -$ssl['tag_len']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $ssl['value'] = substr($ssl['value'], 0, -$ssl['tag_len']);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (!$ssl['tag']) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $ssl['tag'] = null;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return $ssl;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    protected function filter($data)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return preg_replace("/<!--[^\!\[]*?(?<!\/\/)-->/","",$data);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-} 
			 |