dever 2 år sedan
förälder
incheckning
3e09c1b142

+ 174 - 11
database/channel.php

@@ -4,10 +4,31 @@ $sign_col = '';
 
 $sign_method = array
 (
+	-1 => '不加密',
 	1 => 'md5',
 	2 => 'sha256',
 );
 
+$sign_type = array
+(
+	1 => 'value+value形式',
+	2 => 'key=value&key=value形式',
+);
+
+
+$sign_sort = array
+(
+	1 => '按照请求加密参数顺序排序',
+	2 => '按照首字母正序排序',
+);
+
+$sign_after = array
+(
+	1 => '不处理',
+	2 => '转大写',
+	3 => '转小写',
+);
+
 $type = array
 (
 	1 => '标准请求体',
@@ -28,6 +49,19 @@ $post_method = array
 	//4 => 'XML:text/xml',
 );
 
+$response_state = array
+(
+	1 => '是',
+	2 => '否',
+);
+
+$response_type = array
+(
+	1 => '普通文本',
+	2 => 'JSON',
+	3 => 'XML',
+);
+
 return array
 (
 	# 表名
@@ -70,27 +104,27 @@ return array
 			'edit'		=> true,
 		),
 
-		'appid'		=> array
+		'appkey'		=> array
 		(
 			'type' 		=> 'varchar-150',
-			'name' 		=> '渠道APPID',
+			'name' 		=> '渠道APPKEY',
 			'default' 	=> '',
-			'desc' 		=> '渠道APPID',
+			'desc' 		=> '渠道APPKEY',
 			'match' 	=> 'is_string',
 			'update'	=> 'text',
 			'search'	=> 'fulltext',
 			'list'		=> true,
 		),
 
-		'appkey'		=> array
+		'appsecret'		=> array
 		(
 			'type' 		=> 'varchar-150',
-			'name' 		=> '渠道APPKEY',
+			'name' 		=> '渠道APPSecret',
 			'default' 	=> '',
-			'desc' 		=> '渠道APPKEY',
+			'desc' 		=> '渠道APPSecret',
 			'match' 	=> 'is_string',
 			'update'	=> 'text',
-			//'search'	=> 'fulltext',
+			'search'	=> 'fulltext',
 			//'list'		=> true,
 		),
 
@@ -109,12 +143,60 @@ return array
 		'sign_method'		=> array
 		(
 			'type' 		=> 'tinyint-1',
-			'name' 		=> '请求加密方式',
+			'name' 		=> '签名加密方式',
 			'default' 	=> '1',
-			'desc' 		=> '请求加密方式',
+			'desc' 		=> '签名加密方式',
 			'match' 	=> 'is_numeric',
 			'update'	=> 'radio',
 			'option'	=> $sign_method,
+			'tab'		=> 1,
+		),
+
+		'sign_col'		=> array
+		(
+			'type' 		=> 'varchar-1000',
+			'name' 		=> '签名加密参数-按顺序做加密,用+号隔开,为空则所有字段均参与加密',
+			'default' 	=> '',
+			'desc' 		=> '签名加密参数',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'tab'		=> 1,
+		),
+
+		'sign_type'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '签名加密形式',
+			'default' 	=> '1',
+			'desc' 		=> '签名加密形式',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'radio',
+			'option'	=> $sign_type,
+			'tab'		=> 1,
+		),
+
+		'sign_sort'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '签名加密排序',
+			'default' 	=> '1',
+			'desc' 		=> '签名加密排序',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'radio',
+			'option'	=> $sign_sort,
+			'tab'		=> 1,
+		),
+
+		'sign_after'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '签名加密后处理',
+			'default' 	=> '1',
+			'desc' 		=> '签名加密后处理',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'radio',
+			'option'	=> $sign_after,
+			'tab'		=> 1,
 		),
 
 		'method'		=> array
@@ -128,6 +210,7 @@ return array
 			'option'	=> $method,
 			//'list'		=> true,
 			'control'	=> 'method',
+			'tab'		=> 2,
 		),
 
 		'post_method'		=> array
@@ -140,6 +223,7 @@ return array
 			'update'	=> 'radio',
 			'option'	=> $post_method,
 			'show'		=> 'method=2',
+			'tab'		=> 2,
 		),
 
 		'type'		=> array
@@ -148,11 +232,12 @@ return array
 			'name' 		=> '是否有标准请求参数',
 			'default' 	=> '1,2',
 			'desc' 		=> '是否有标准请求参数',
-			'match' 	=> 'is_numeric',
+			'match' 	=> 'is_string',
 			'update'	=> 'checkbox',
 			'option'	=> $type,
 			//'list'		=> true,
 			'control'	=> 'type',
+			'tab'		=> 2,
 		),
 
 		'middleware-channel_request_body'=> array
@@ -165,6 +250,7 @@ return array
 			'sync'		=> array('id', 'channel_id'),
 			'update'	=> array(1),
 			'show'		=> 'type=1',
+			'tab'		=> 2,
 		),
 
 		'middleware-channel_request_header'=> array
@@ -177,6 +263,83 @@ return array
 			'sync'		=> array('id', 'channel_id'),
 			'update'	=> array(1),
 			'show'		=> 'type=2',
+			'tab'		=> 2,
+		),
+
+		'response_state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '是否有标准响应参数',
+			'default' 	=> '1',
+			'desc' 		=> '是否有标准响应参数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'radio',
+			'option'	=> $response_state,
+			//'list'		=> true,
+			'control'	=> 'response_state',
+			'tab'		=> 3,
+		),
+
+		'response_type'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '响应数据类型',
+			'default' 	=> '1',
+			'desc' 		=> '响应数据类型',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'radio',
+			'option'	=> $response_type,
+			'tab'		=> 3,
+			'show'		=> 'response_state=1',
+		),
+
+		'response_data'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '响应业务数据字段名',
+			'default' 	=> '',
+			'desc' 		=> '响应业务数据字段名',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'tab'		=> 3,
+			'show'		=> 'response_state=1',
+		),
+
+		'response_msg'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '响应信息字段名',
+			'default' 	=> '',
+			'desc' 		=> '响应信息字段名',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'tab'		=> 3,
+			'show'		=> 'response_state=1',
+		),
+
+		'response_code'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '响应状态码字段名',
+			'default' 	=> '',
+			'desc' 		=> '响应状态码字段名',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'tab'		=> 3,
+			'show'		=> 'response_state=1',
+		),
+
+		'middleware-channel_response_code'=> array
+		(
+			'name' 		=> '响应状态码列表-设置标准的响应状态码,也可以只设置成功值,其他值均为失败',
+			'default' 	=> '',
+			'desc' 		=> '响应状态码列表',
+			'match' 	=> 'option',
+			# 同步更新另外一个表的内容,两个表相关联的id,更新另一个表的字段
+			'sync'		=> array('id', 'channel_id'),
+			'update'	=> array(1),
+			'show'		=> 'response_state=1',
+			'tab'		=> 3,
 		),
 
 		'reorder'		=> array
@@ -218,7 +381,7 @@ return array
 
 	'manage' => array
 	(
-		//'tab' => array('基本设置', '联系人信息', '认证信息'),
+		'tab' => array('基本设置', '签名加密', '标准请求', '标准响应'),
 		'button' => array
         (
             //'类型配置' => array('list', 'supplier_type&oper_parent=supplier'),

+ 19 - 1
database/channel_api.php

@@ -16,6 +16,13 @@ $status = array
 	2 => '已完成',
 );
 
+$response_type = array
+(
+	1 => '普通文本',
+	2 => 'JSON',
+	3 => 'XML',
+);
+
 return array
 (
 	# 表名
@@ -76,6 +83,17 @@ return array
 			'list'		=> true,
 		),
 
+		'sign_col'		=> array
+		(
+			'type' 		=> 'varchar-1000',
+			'name' 		=> '签名加密参数-按顺序做加密,用+号隔开,为空则所有字段均参与加密',
+			'default' 	=> '',
+			'desc' 		=> '签名加密参数',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'tab'		=> 1,
+		),
+
 		'method'		=> array
 		(
 			'type' 		=> 'tinyint-1',
@@ -219,7 +237,7 @@ return array
 		'list_button' => array
         (
         	//'edit' => array('编辑'),
-        	'list' => array('字段列表', 'service_product_col&oper_table=service_product&top_table=service&search_option_product_id={id}'),
+        	//'list' => array('字段列表', 'service_product_col&oper_table=service_product&top_table=service&search_option_product_id={id}'),
         )
 	),
 

+ 99 - 0
database/channel_api_data.php

@@ -0,0 +1,99 @@
+<?php
+
+$type = array
+(
+	1 => '数值型',
+	2 => '字符串型',
+	3 => 'JSON型',
+);
+
+return array
+(
+	# 表名
+	'name' => 'channel_api_data',
+	# 显示给用户看的名称
+	'lang' => '接口数据',
+	# 是否显示在后台菜单
+	'order' => -10,
+	'menu' => false,
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'list'		=> true,
+			'order'		=> 'desc',
+		),
+
+		'api_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '接口id',
+			'default' 	=> '1',
+			'desc' 		=> '接口id',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'hidden',
+			'value'		=> Dever::input('search_option_api_id'),
+		),
+
+		'data'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '数据',
+			'default' 	=> '',
+			'desc' 		=> '数据',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+		
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			//'search'	=> 'date',
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	'manage' => array
+	(
+		'insert' => false,
+        'edit' => false,
+
+        # 自定义快捷新增和编辑
+        'button' => array
+        (
+            '新增' => array('fast'),
+        ),
+		'list_button' => array
+        (
+        	'edit' => array('编辑'),
+        )
+	),
+
+	'request' => array
+	(
+		
+	)
+);

+ 1 - 18
database/channel_api_request.php

@@ -7,12 +7,6 @@ $type = array
 	3 => 'JSON型',
 );
 
-$sign = array
-(
-	1 => '参与签名',
-	2 => '不参与签名',
-);
-
 return array
 (
 	# 表名
@@ -22,7 +16,7 @@ return array
 	# 是否显示在后台菜单
 	'order' => -10,
 	'menu' => false,
-	'check' => 'key',
+	'check' => 'api_id,key',
 
 	# 数据结构
 	'struct' => array
@@ -96,17 +90,6 @@ return array
 			'option'	=> $type,
 		),
 
-		'sign'		=> array
-		(
-			'type' 		=> 'tinyint-1',
-			'name' 		=> '是否参与签名',
-			'default' 	=> '1',
-			'desc' 		=> '是否参与签名',
-			'match' 	=> 'is_numeric',
-			'update'	=> 'radio',
-			'option'	=> $sign,
-		),
-
 		'reorder'		=> array
 		(
 			'type' 		=> 'int-11',

+ 1 - 19
database/channel_api_response.php

@@ -6,13 +6,6 @@ $type = array
 	2 => '字符串型',
 );
 
-$sign = array
-(
-	1 => '参与签名',
-	2 => '不参与签名',
-);
-
-
 return array
 (
 	# 表名
@@ -22,7 +15,7 @@ return array
 	# 是否显示在后台菜单
 	'order' => -10,
 	'menu' => false,
-	'check' => 'key',
+	'check' => 'api_id,key',
 
 	# 数据结构
 	'struct' => array
@@ -96,17 +89,6 @@ return array
 			'option'	=> $type,
 		),
 
-		'sign'		=> array
-		(
-			'type' 		=> 'tinyint-1',
-			'name' 		=> '是否参与签名',
-			'default' 	=> '1',
-			'desc' 		=> '是否参与签名',
-			'match' 	=> 'is_numeric',
-			'update'	=> 'radio',
-			'option'	=> $sign,
-		),
-
 		'reorder'		=> array
 		(
 			'type' 		=> 'int-11',

+ 1 - 18
database/channel_request_body.php

@@ -7,12 +7,6 @@ $type = array
 	3 => 'JSON型',
 );
 
-$sign = array
-(
-	1 => '参与签名',
-	2 => '不参与签名',
-);
-
 return array
 (
 	# 表名
@@ -22,7 +16,7 @@ return array
 	# 是否显示在后台菜单
 	'order' => -10,
 	'menu' => false,
-	'check' => 'key',
+	'check' => 'channel_id,key',
 
 	# 数据结构
 	'struct' => array
@@ -96,17 +90,6 @@ return array
 			'option'	=> $type,
 		),
 
-		'sign'		=> array
-		(
-			'type' 		=> 'tinyint-1',
-			'name' 		=> '是否参与签名',
-			'default' 	=> '1',
-			'desc' 		=> '是否参与签名',
-			'match' 	=> 'is_numeric',
-			'update'	=> 'radio',
-			'option'	=> $sign,
-		),
-
 		'reorder'		=> array
 		(
 			'type' 		=> 'int-11',

+ 1 - 1
database/channel_request_header.php

@@ -16,7 +16,7 @@ return array
 	# 是否显示在后台菜单
 	'order' => -10,
 	'menu' => false,
-	'check' => 'key',
+	'check' => 'channel_id,key',
 
 	# 数据结构
 	'struct' => array

+ 137 - 0
database/channel_response_code.php

@@ -0,0 +1,137 @@
+<?php
+
+$type = array
+(
+	1 => '成功',
+	2 => '失败',
+	3 => '其他',
+);
+
+return array
+(
+	# 表名
+	'name' => 'channel_response_code',
+	# 显示给用户看的名称
+	'lang' => '响应状态码列表',
+	# 是否显示在后台菜单
+	'order' => -10,
+	'menu' => false,
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'list'		=> true,
+			'order'		=> 'desc',
+		),
+
+		'channel_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '渠道id',
+			'default' 	=> '1',
+			'desc' 		=> '渠道id',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'hidden',
+			'value'		=> Dever::input('search_option_channel_id'),
+		),
+
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '返回码描述',
+			'default' 	=> '',
+			'desc' 		=> '返回码描述',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'value'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '返回码值',
+			'default' 	=> '',
+			'desc' 		=> '返回码值',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'type'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '返回码类型',
+			'default' 	=> '1',
+			'desc' 		=> '返回码类型',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'radio',
+			'option'	=> $type,
+		),
+
+		'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '排序(数值越大越靠前)',
+			'default' 	=> '1',
+			'desc' 		=> '请输入排序',
+			'match' 	=> 'option',
+			//'update'	=> 'text',
+			'search'	=> 'order',
+			'list_name' => '排序',
+			'list'		=> true,
+			'order'		=> 'desc',
+			'edit'		=> true,
+		),
+		
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			//'search'	=> 'date',
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	'manage' => array
+	(
+		'insert' => false,
+        'edit' => false,
+
+        # 自定义快捷新增和编辑
+        'button' => array
+        (
+            '新增' => array('fast'),
+        ),
+		'list_button' => array
+        (
+        	'edit' => array('编辑'),
+        )
+	),
+
+	'request' => array
+	(
+		
+	)
+);

+ 1 - 1
database/service_product_col.php

@@ -16,7 +16,7 @@ return array
 	# 是否显示在后台菜单
 	'order' => -10,
 	'menu' => false,
-	'check' => 'key',
+	'check' => 'product_id,key',
 
 	# 数据结构
 	'struct' => array

+ 139 - 9
lib/Task.php

@@ -9,10 +9,18 @@ class Task
     # 执行某个业务接口
     public function run_api()
     {
-        $channel_id = 1;
-        $api_id = 1;
-        $channel = Dever::db('middleware/channel')->find($channel_id);
+        $this->signname = 'signature';
+        $api_id = Dever::input('api_id', 1);
+        
         $channel_api = Dever::db('middleware/channel_api')->find($api_id);
+        if ($channel_api) {
+            $channel = Dever::db('middleware/channel')->find($channel_api['channel_id']);
+            if (!$channel) {
+                Dever::alert('接口错误');
+            }
+        } else {
+            Dever::alert('接口错误');
+        }
 
         $url = $channel['host'] . $channel_api['uri'];
 
@@ -51,18 +59,131 @@ class Task
             $body = $this->body($channel, $channel_api);
         }
 
-        # 如果是ssl 这里需要处理一下
+        $this->sign($body, $channel, $channel_api);
 
+        if (strstr($url, '//')) {
+            $url = str_replace('//', '/', $url);
+        }
+
+        $log['type'] = 'request';
         $log['url'] = $url;
         $log['body'] = $body;
         $log['method'] = $method;
         $log['json'] = $json;
         $log['header'] = $header;
 
-        print_r($log);die;
-        //Dever::log($log, 'middleware');
+        Dever::log($log, 'middleware');
 
         $response = Dever::curl($url, $body, $method, $json, $header);
+        $response = $this->response($response, $channel, $channel_api);
+        if ($response['status'] == 1 && $response['data']) {
+            $insert['api_id'] = $channel_api['id'];
+            $insert['data'] = Dever::json_encode($response['data']);
+            $response['id'] = Dever::db('middleware/channel_api_data')->insert($insert);
+        }
+        $response['request'] = $log;
+
+        return $response;
+    }
+
+    # 数据响应格式处理
+    public function response($response, $channel, $channel_api)
+    {
+        $log['type'] = 'response';
+        $log['data'] = $response;
+        Dever::log($log, 'middleware');
+
+        if ($channel['response_type'] == 2) {
+            $response = Dever::json_decode($response);
+        } elseif ($channel['response_type'] == 2) {
+            $response = (array) simplexml_load_string($data);
+        }
+        $msg = '';
+        $status = 2;
+        if (isset($response[$channel['response_code']])) {
+            $code = Dever::db('middleware/channel_response_code')->find(array('value' => $response[$channel['response_code']]));
+            if ($code && $code['type'] == 1) {
+                $status = 1;
+            }
+        }
+        $msg = isset($response[$channel['response_msg']]) ? $response[$channel['response_msg']] : 'no';
+        if (strstr($channel['response_data'], '.')) {
+            $temp = explode('.', $channel['response_data']);
+            $data = isset($response[$temp[0]][$temp[1]]) ? $response[$temp[0]][$temp[1]] : (isset($response[$temp[0]]) ? $response[$temp[0]] : false);
+        } else {
+            $data = isset($response[$channel['response_data']]) ? $response[$channel['response_data']] : false;
+        }
+
+        return array
+        (
+            'status' => $status,
+            'msg' => $msg,
+            'response' => $response,
+            'data' => $data,
+        );
+    }
+
+    public function sign(&$body, $channel, $channel_api)
+    {
+        $sign = array();
+        if ($channel['sign_col']) {
+            $col = explode('+', $channel['sign_col']);
+            foreach ($col as $k => $v) {
+                $v = trim($v);
+                if (isset($body[$v]) && $body[$v]) {
+                    $sign[$v] = $body[$v];
+                } elseif (isset($channel[$v]) && $channel[$v]) {
+                    $sign[$v] = $channel[$v];
+                }
+            }
+        }
+        if ($channel_api && $channel_api['sign_col']) {
+            $col = explode('+', $channel_api['sign_col']);
+            foreach ($col as $k => $v) {
+                $v = trim($v);
+                if (isset($body[$v]) && $body[$v]) {
+                    $sign[$v] = $body[$v];
+                } elseif (isset($channel[$v]) && $channel[$v]) {
+                    $sign[$v] = $channel[$v];
+                }
+            }
+        }
+
+        if ($channel['sign_sort'] == 2) {
+            ksort($sign);
+        }
+        if ($channel['sign_type'] == 1) {
+            $sign = implode('', $sign);
+        } else {
+            foreach ($sign as $k => $v) {
+                if (strstr($v, 'http')) {
+                    $v = urlencode($v);
+                }
+                $sign .= $k . '=' . $v . '&';
+            }
+            $sign = rtrim($sign, '&');
+        }
+
+        $test = Dever::input('test');
+        if ($test == 1) {
+            print_r($sign);die;
+        }
+
+        # 如果是ssl 这里需要处理一下,后续处理吧
+
+        if ($channel['sign_method'] == 2) {
+            $sign = hash("sha256", $sign);
+        } else {
+            $sign = md5($sign);
+        }
+
+        if ($channel['sign_after'] == 2) {
+            $sign = strtoupper($sign);
+        } elseif ($channel['sign_after'] == 2) {
+            $sign = strtolower($sign);
+        }
+
+        $body[$this->signname] = $sign;
     }
 
     public function value($data, $channel, $channel_api = array())
@@ -72,15 +193,21 @@ class Task
             $value = '$value = '.$value.';';
             eval($value);
         } elseif ($value == '{timestamp}') {
-            $value = time();
+            $value = Dever::timestamp();
         } elseif ($value == '{appkey}') {
             $value = $channel['appkey'];
+        } elseif ($value == '{appSecret}') {
+            $value = $channel['appsecret'];
         } elseif ($value == '{signature}') {
-            //$value = $channel['signature'];//待处理
+            $this->signname = $data['key'];
         } elseif ($value == '{api_request}' && $channel_api) {
             $value = $this->body($channel, $channel_api);
         }
 
+        if (!Dever::zero($value) && !$value) {
+            return Dever::input($data['key']);
+        }
+
         if ($data['type'] == 1) {
             $value = (float) $value;
         } elseif ($data['type'] == 2) {
@@ -97,7 +224,10 @@ class Task
         $request_body = Dever::db('middleware/channel_' . $table)->select($where);
         if ($request_body) {
             foreach ($request_body as $k => $v) {
-                $data[$v['key']] = $this->value($v, $channel, $channel_api);
+                $value = $this->value($v, $channel, $channel_api);
+                if ($value || Dever::zero($value)) {
+                    $data[$v['key']] = $value;
+                }
             }
         }
     }

+ 17 - 0
src/Data.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace Middleware\Src;
+
+use Dever;
+
+class Data
+{
+    # 获取接口数据
+    public function api()
+    {
+    	$api_id = Dever::input('id', 1);
+    	$data = Dever::db('middleware/channel_api_data')->find(array('api_id' => $api_id));
+        
+        return $data;
+    }
+}

+ 18 - 0
src/Test.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace Middleware\Src;
+
+use Dever;
+
+class Test
+{
+    # 获取测试数据
+    public function data()
+    {
+        $data = array();
+
+        $data['voucherID'] = 1;
+        $data['groupID'] = 2;
+        return $data;
+    }
+}