rabin 1 年之前
父節點
當前提交
82a69a2020
共有 9 個文件被更改,包括 353 次插入143 次删除
  1. 105 47
      database/yspay.php
  2. 35 7
      database/yspay_cash.php
  3. 18 8
      database/yspay_merchant.php
  4. 6 6
      database/yspay_sign.php
  5. 4 4
      database/yspay_tixian.php
  6. 2 2
      lib/Yspay.php
  7. 99 26
      yspay/Cash.php
  8. 52 25
      yspay/Multi.php
  9. 32 18
      yspay/Sign.php

+ 105 - 47
database/yspay.php

@@ -6,6 +6,12 @@ $type = array
 	2 => '有资金管理功能',
 );
 
+$cash_type = array
+(
+	1 => '通过交易金额分账',
+	2 => '通过实际金额分账',
+);
+
 return array
 (
 	# 表名
@@ -39,10 +45,80 @@ return array
 			'update'	=> 'hidden',
 		),
 
+		'per'		=> array
+		(
+			'type' 		=> 'varchar-11',
+			'name' 		=> '交易手续费百分比-如输入10,就是从总支付金额中收取10%手续费,这个会自动扣掉,输入0.1就是千分之1',
+			'default' 	=> '10',
+			'desc' 		=> '交易手续费百分比',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+		),
+
+		'sign_key'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '自助签约key',
+			'default' 	=> '',
+			'desc' 		=> '自助签约key',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+		),
+
+		'sign_accesser_id'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '自助签约accesser_id',
+			'default' 	=> '',
+			'desc' 		=> '自助签约accesser_id',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+		),
+
+		'tx_sys_id'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '提现系统编号',
+			'default' 	=> '',
+			'desc' 		=> '提现系统编号',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+		),
+
+		'tx_private_key'		=> array
+		(
+			'type' 		=> 'varchar-2000',
+			'name' 		=> '提现私钥',
+			'default' 	=> '',
+			'desc' 		=> '提现私钥',
+			'match' 	=> 'is_string',
+			'update'	=> 'textarea',
+		),
+
+		'tx_private_key_pkcs1'		=> array
+		(
+			'type' 		=> 'varchar-2000',
+			'name' 		=> '提现PKCS1私钥',
+			'default' 	=> '',
+			'desc' 		=> '提现PKCS1私钥',
+			'match' 	=> 'is_string',
+			'update'	=> 'textarea',
+		),
+
+		'tx_public_key'		=> array
+		(
+			'type' 		=> 'varchar-2000',
+			'name' 		=> '提现公钥',
+			'default' 	=> '',
+			'desc' 		=> '提现公钥',
+			'match' 	=> 'is_string',
+			'update'	=> 'textarea',
+		),
+
 		'type'		=> array
 		(
 			'type' 		=> 'tinyint-1',
-			'name' 		=> '资金管理类型',
+			'name' 		=> '资金管理设置',
 			'default' 	=> '1',
 			'desc' 		=> '支付类型',
 			'match' 	=> 'is_string',
@@ -51,7 +127,18 @@ return array
 			'control'	=> 'type',
 		),
 
-		'per'		=> array
+		'cash_groupid'		=> array
+		(
+			'type' 		=> 'varchar-200',
+			'name' 		=> '平台分账集团号',
+			'default' 	=> '',
+			'desc' 		=> '平台分账集团号',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'show'		=> 'type=2',
+		),
+
+		'cash_per'		=> array
 		(
 			'type' 		=> 'int-11',
 			'name' 		=> '平台分账百分比-如输入10,就是从总支付金额中分账10%',
@@ -62,7 +149,18 @@ return array
 			'show'		=> 'type=2',
 		),
 
-		'mid'		=> array
+		'cash_type'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '平台分账类型',
+			'default' 	=> '1',
+			'desc' 		=> '平台分账类型',
+			'match' 	=> 'is_string',
+			'update'	=> 'radio',
+			'option'	=> $cash_type,
+		),
+
+		'cash_mid'		=> array
 		(
 			'type' 		=> 'varchar-200',
 			'name' 		=> '平台分账商户号',
@@ -73,7 +171,7 @@ return array
 			'show'		=> 'type=2',
 		),
 
-		'card'		=> array
+		'cash_card'		=> array
 		(
 			'type' 		=> 'varchar-150',
 			'name' 		=> '平台分账卡号',
@@ -84,7 +182,7 @@ return array
 			'show'		=> 'type=2',
 		),
 
-		'private_file'		=> array
+		'cash_private_file'		=> array
 		(
 			'type' 		=> 'varchar-150',
 			'name' 		=> '资金管理私钥文件',
@@ -96,7 +194,7 @@ return array
 			'show'		=> 'type=2',
 		),
 
-		'private_file_password'		=> array
+		'cash_private_file_password'		=> array
 		(
 			'type' 		=> 'varchar-150',
 			'name' 		=> '资金管理私钥文件密码',
@@ -107,7 +205,7 @@ return array
 			'show'		=> 'type=2',
 		),
 
-		'public_file'		=> array
+		'cash_public_file'		=> array
 		(
 			'type' 		=> 'varchar-150',
 			'name' 		=> '资金管理公钥文件',
@@ -119,46 +217,6 @@ return array
 			'show'		=> 'type=2',
 		),
 
-		'sys_id'		=> array
-		(
-			'type' 		=> 'varchar-150',
-			'name' 		=> '提现系统编号',
-			'default' 	=> '',
-			'desc' 		=> '提现系统编号',
-			'match' 	=> 'is_string',
-			'update'	=> 'text',
-		),
-
-		'private_key'		=> array
-		(
-			'type' 		=> 'varchar-2000',
-			'name' 		=> '提现私钥',
-			'default' 	=> '',
-			'desc' 		=> '提现私钥',
-			'match' 	=> 'is_string',
-			'update'	=> 'textarea',
-		),
-
-		'private_key_pkcs1'		=> array
-		(
-			'type' 		=> 'varchar-2000',
-			'name' 		=> '提现PKCS1私钥',
-			'default' 	=> '',
-			'desc' 		=> '提现PKCS1私钥',
-			'match' 	=> 'is_string',
-			'update'	=> 'textarea',
-		),
-
-		'public_key'		=> array
-		(
-			'type' 		=> 'varchar-2000',
-			'name' 		=> '提现公钥',
-			'default' 	=> '',
-			'desc' 		=> '提现公钥',
-			'match' 	=> 'is_string',
-			'update'	=> 'textarea',
-		),
-
 		'state'		=> array
 		(
 			'type' 		=> 'tinyint-1',

+ 35 - 7
database/yspay_cash.php

@@ -5,7 +5,9 @@ $status = array
 	1 => '未确认',
     2 => '待入账',
 	3 => '已入账',
-	4 => '不入账',
+	4 => '申请提现',
+    5 => '已提现',
+    6 => '提现失败',
 );
 
 return array
@@ -66,14 +68,24 @@ return array
             'list'		=> true,
         ),
 
+        'ycash'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '交易金额',
+            'default'   => '0',
+            'desc'      => '交易金额',
+            'match'     => 'option',
+            'list'      => 'Dever::number({ycash}/100, 2)',
+        ),
+
         'cash'      => array
         (
             'type'      => 'int-11',
-            'name'      => '总金额',
+            'name'      => '实际金额',
             'default'   => '0',
-            'desc'      => '总金额',
+            'desc'      => '实际金额',
             'match'     => 'option',
-            'list'      => 'round({cash}/100, 2)',
+            'list'      => 'Dever::number({cash}/100, 2)',
         ),
 
         'hf_cash'      => array
@@ -84,7 +96,7 @@ return array
             'desc'      => '划付金额',
             'match'     => 'option',
             //'update'    => 'text',
-            'list'		=> 'round({hf_cash}/100, 2)',
+            'list'		=> 'Dever::number({hf_cash}/100, 2)',
         ),
 
         'fz_cash'      => array
@@ -95,7 +107,7 @@ return array
             'desc'      => '分账金额',
             'match'     => 'option',
             //'update'    => 'text',
-            'list'		=> 'round({fz_cash}/100, 2)',
+            'list'		=> 'Dever::number({fz_cash}/100, 2)',
         ),
 
         'rdate'     => array
@@ -110,6 +122,18 @@ return array
             'list_order' => 100,
         ),
 
+        'tdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '提现时间',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+            'search'    => 'date',
+            'list'      => '"{tdate}" ? date("Y-m-d H:i", \'{tdate}\') : "-"',
+            'list_order' => 101,
+        ),
+
         'status'        => array
         (
             'type'      => 'tinyint-1',
@@ -149,6 +173,10 @@ return array
         'edit' => false,
         'insert' => false,
         'delete' => false,
+        'button' => array
+        (
+            '资金划付' => array('oper', 'pay/yspay/cash.huafu_commit'),
+        ),
     ),
 
     'request' => array
@@ -158,7 +186,7 @@ return array
             'option' => array
             (
                 'merchant_id' => 'yes',
-                'status' => 'yes',
+                'status' => array('yes', '>='),
                 'state' => 1,
             ),
             'type' => 'one',

+ 18 - 8
database/yspay_merchant.php

@@ -92,7 +92,17 @@ return array
             'list'		=> true,
         ),
 
-        'per'		=> array
+        'merno'      => array
+        (
+            'type'      => 'varchar-200',
+            'name'      => '企业用户号-清分时使用',
+            'default'   => '',
+            'desc'      => '企业用户号',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
+        'cash_per'		=> array
 		(
 			'type' 		=> 'int-11',
 			'name' 		=> '平台分账百分比-如输入10,就是从总支付金额中分账10%,未输入则直接使用默认分账百分比',
@@ -122,7 +132,7 @@ return array
             'desc'      => '划付总额',
             'match'     => 'option',
             //'update'    => 'text',
-            //'list'		=> 'round({hf_cash}/100, 2)',
+            //'list'		=> 'Dever::number({hf_cash}/100, 2)',
         ),
 
         'fz_cash'      => array
@@ -133,7 +143,7 @@ return array
             'desc'      => '分账总额',
             'match'     => 'option',
             //'update'    => 'text',
-            //'list'		=> 'round({fz_cash}/100, 2)',
+            //'list'		=> 'Dever::number({fz_cash}/100, 2)',
         ),
 
         'yue'      => array
@@ -156,7 +166,7 @@ return array
             'desc'      => '划付总额',
             'match'     => 'option',
             //'update'    => 'text',
-            //'list'		=> 'round({tx_cash}/100, 2)',
+            //'list'		=> 'Dever::number({tx_cash}/100, 2)',
         ),
 
         'pay/yspay_sign-one#step'=> array
@@ -219,11 +229,11 @@ return array
         (
         	'edit' => array('编辑'),
 
-        	'add' => array('签约', '"yspay_sign&search_option_merchant_id={id}&where_id={id}&oper_table=account&oper_save_table=yspay_merchant"', '{status} == 2'),
+        	'add' => array('签约资料', '"yspay_sign&search_option_merchant_id={id}&where_id={id}&oper_table=account&oper_save_table=yspay_merchant"', '{status} == 2'),
 
-        	'oper' => array('提交资料', 'pay/yspay/sign.handle?sign_id={id}', '{pay/yspay_sign-one#step} == -1 && {status} == 2'),
-            'fast' => array('打款确认', '"yspay_sign&where_id={id}&col=cash"', '{pay/yspay_sign-one#step} == 2 && {status} == 2'),
-            'copy' => array('合同链接', 'pay/yspay/sign.getAgreement?sign_id={id}', '{pay/yspay_sign-one#step} == 4 && {status} == 2'),
+        	'oper' => array('签约提审', 'pay/yspay/sign.handle?sign_id={id}', '{pay/yspay_sign-one#step} == -1 && {status} == 2'),
+            'fast' => array('签约打款', '"yspay_sign&where_id={id}&col=cash"', '{pay/yspay_sign-one#step} == 2 && {status} == 2'),
+            'copy' => array('签约合同', 'pay/yspay/sign.getAgreement?sign_id={id}', '{pay/yspay_sign-one#step} == 4 && {status} == 2'),
 
         	'list' => array('资金流水', '"yspay_cash&search_option_merchant_id={id}&oper_table=yspay_merchant&top_table=account"', '{status} == 1'),
 

+ 6 - 6
database/yspay_sign.php

@@ -1,26 +1,26 @@
 <?php
 $acct_type = array
 (
-    -1 => '个人账户',
+    //-1 => '个人账户',
     1 => '公司账户',
 );
 $mer_type = array
 (
     2 => '个人工商户',
     1 => '企业商户',
-    3 => '小微商户',
+    //3 => '小微商户',
 );
 $desc = '';
 $col = Dever::input('col');
 if (!$col) {
-    $tab = array('门店信息', '法人信息', '企业信息', '银行信息');
+    $tab = array('基本信息', '法人信息', '企业信息', '银行信息');
 } else {
     $tab = '';
 }
 
 $step = array
 (
-    -1 => '待提交资料',
+    -1 => '待签约提审',
     1 => '入网:资料提交',//3.2
     2 => '入网:对公账户打款',//3.7
     3 => '入网:对公账户验证',//3.6
@@ -352,10 +352,10 @@ return array
         (
             'type'      => 'int-11',
             'name'      => '开户行账户类型',
-            'default'   => '-1',
+            'default'   => '1',
             'desc'      => '账户类型',
             'match'     => 'option',
-            'update'    => 'radio',
+            //'update'    => 'radio',
             'option'    => $acct_type,
             'tab'       => 3,
         ),

+ 4 - 4
database/yspay_tixian.php

@@ -9,17 +9,16 @@ $merchant_id = Dever::input('search_option_merchant_id');
 $button = array();
 $info = '';
 $tixian = Dever::input('tixian', 1);
-if ($shop) {
+if ($merchant_id) {
     # 申请提现和查看提现日志
     $account = Dever::db('pay/yspay_merchant')->find($merchant_id);
     if ($account) {
-        $info = $shop['name'] . ',当前余额:' . round($account['yue']/100, 2) . '元,总提现金额:' . round($account['tx_cash']/100, 2) . '元';
+        $info = $account['name'] . ',当前余额:' . round($account['yue']/100, 2) . '元,总提现金额:' . round($account['tx_cash']/100, 2) . '元';
     }
     
-
     if ($tixian == 1) {
         $button['手动申请提现'] = array('fast', 1,'yspay_tixian_apply&search_option_merchant_id=' . $merchant_id);
-        $button['提现申请记录'] = array('location', 'l=project/database/list&project=pay&table=yspay_tixian_log&search_option_state=1&search_option_merchant_id='.$merchant_id.'&oper_table=yspay_tixian');
+        $button['提现申请记录'] = array('location', 'l=project/database/list&project=pay&table=yspay_tixian_log&search_option_state=1&search_option_merchant_id='.$merchant_id.'&oper_table=yspay_tixian&top_table=yspay_merchant');
     }
 }
 
@@ -31,6 +30,7 @@ return array
     'lang' => '银联提现列表',
     'order' => -200,
     'info' => $info,
+    'menu' => false,
     # 数据结构
     'struct' => array
     (

+ 2 - 2
lib/Yspay.php

@@ -147,7 +147,6 @@ class Yspay extends Core
 		} else {
 			$request['merOrderId'] = $order_id;
 		}
-		
 
 		$request['mid'] = $this->config['mid'];
 		$request['tid'] = $this->config['tid'];
@@ -190,8 +189,9 @@ class Yspay extends Core
 				}
 				$request['subOrders'][] = $subOrders;
 
-				# 记录划付
 				Dever::load('pay/yspay/cash')->add($order_id, $request, $subOrders);
+			} else {
+				Dever::load('pay/yspay/cash')->add($order_id, $request, $request);
 			}
 			if ($request['subOrders']) {
 				$request['divisionFlag'] = true;

+ 99 - 26
yspay/Cash.php

@@ -9,47 +9,73 @@ class Cash
     	$mid = $info['mid'];
     	$merchant = Dever::db('pay/yspay_merchant')->one(array('mid' => $mid));
     	if ($merchant) {
-    		$per = $merchant['per'];
-    		if (!$per) {
-    			$yspay = Dever::db('pay/yspay')->one(array('account_id' => $merchant['account_id']));
-    			if ($yspay && $yspay['per']) {
-    				$per = $yspay['per'];
+    		$yspay = Dever::db('pay/yspay')->one(array('account_id' => $merchant['account_id']));
+    		if ($yspay) {
+    			$cash_per = 0;
+    			if ($yspay['type'] == 2) {
+    				$cash_per = $merchant['cash_per'];
+		    		if (!$cash_per) {
+		    			if ($yspay && $yspay['cash_per']) {
+		    				$cash_per = $yspay['cash_per'];
+		    			}
+		    		}
+		    		if (!$cash_per || $cash_per <= 0) {
+		    			$cash_per = 0;
+		    		} else {
+		    			$cash_per = $cash_per/100;
+		    		}
     			}
+    			
+	    		$per = $yspay['per']/100;
+	    		
+				$data['merchant_id'] = $merchant['id'];
+	    		$data['order_num'] = $info['merOrderId'];
+		        $data['source_order_num'] = $order_id;
+		        $data['ycash'] = $info['amount'];
+		        $data['cash'] = round($info['amount'] - $info['amount'] * $per, 2);
+		        if ($yspay['cash_type'] == 1) {
+		        	$fz_cash = $data['ycash'];
+		        } else {
+		        	$fz_cash = $data['cash'];
+		        }
+		        $data['fz_cash'] = round($fz_cash*$cash_per, 2);
+		        $data['hf_cash'] = round($data['cash'] - $data['fz_cash'], 2);
+		        $data['status'] = 1;
+		        $id = Dever::db('pay/yspay_cash')->insert($data);
+		        return $id;
     		}
-    		if (!$per || $per <= 0) {
-    			$per = 0;
-    		} else {
-    			$per = $per/100;
-    		}
-    		
-			$data['merchant_id'] = $merchant['id'];
-    		$data['order_num'] = $info['merOrderId'];
-	        $data['source_order_num'] = $order_id;
-	        $data['cash'] = $info['amount'];
-	        $data['fz_cash'] = round($data['cash']*$per, 2);
-	        $data['hf_cash'] = round($data['cash'] - $data['fz_cash'], 2);
-	        $data['status'] = 1;
-	        $id = Dever::db('pay/yspay_cash')->insert($data);
-	        return $id;
     	}
     	return false;
     }
 
     # 修改状态
-    public function up($order_id, $status = 2)
+    public function up($id, $status = 2)
     {
-    	$where['source_order_num'] = $order_id;
+    	if (is_numeric($id)) {
+    		$where['id'] = $id;
+    	} else {
+    		$where['source_order_num'] = $id;
+    	}
+    	
     	$info = Dever::db('pay/yspay_cash')->find($where);
     	if ($info) {
     		$update = array('status' => $status, 'where_id' => $info['id']);
     		if ($status == 3) {
-    			# 开始分账和划付
-    			$state = $this->tixian($info);
+    			# 开始划付
+    			$state = $this->huafu_act($info);
     			if ($state != 'ok') {
     				return false;
     			}
     			$update['rdate'] = time();
     		}
+    		if ($status == 4) {
+    			# 开始提现
+    			$state = $this->tixian_act($info);
+    			if ($state != 'ok') {
+    				return false;
+    			}
+    			$update['tdate'] = time();
+    		}
     		$state = Dever::db('pay/yspay_cash')->update($update);
     		if ($state) {
     			if ($status == 3) {
@@ -64,13 +90,26 @@ class Cash
     	return false;
     }
 
-    private function tixian($info)
+    private function huafu_act($info)
     {
     	$merchant = Dever::db('pay/yspay_merchant')->one($info['merchant_id']);
     	if ($merchant) {
     		$config = Dever::db('pay/yspay')->one(array('account_id' => $merchant['account_id']));
     		if ($config) {
-    			return Dever::load('pay/yspay/multi')->huafu($config, $merchant, $info);
+    			return Dever::load('pay/yspay/multi')->act($config, $merchant, $info);
+    		}
+    	}
+
+    	return false;
+    }
+
+    private function tixian_act($info)
+    {
+    	$merchant = Dever::db('pay/yspay_merchant')->one($info['merchant_id']);
+    	if ($merchant) {
+    		$config = Dever::db('pay/yspay')->one(array('account_id' => $merchant['account_id']));
+    		if ($config) {
+    			return Dever::load('pay/yspay/account')->act($config, $merchant, $info);
     		}
     	}
 
@@ -79,4 +118,38 @@ class Cash
 
     # 定时获取总额
 
+    # 测试数据
+    public function test_add_api()
+    {
+    	$info['mid'] = 'test';
+    	$info['merOrderId'] = 'test123';
+    	$info['amount'] = 10000;
+
+    	$this->add('test123', array(), $info);
+    	return 'ok';
+    }
+
+    # 将测试数据改成待入账
+    public function test_edit_api()
+    {
+    	$data = Dever::db('pay/yspay_cash')->select(array('order_num' => 'test123', 'status' => 1));
+    	if ($data) {
+    		foreach ($data as $k => $v) {
+    			$this->up($v['id'], 2);
+    		}
+    	} 
+    	return 'ok';
+    }
+
+    # 资金划付
+    public function huafu_commit_api()
+    {
+    	$data = Dever::db('pay/yspay_cash')->select(array('order_num' => 'test123', 'status' => 2));
+    	if ($data) {
+    		foreach ($data as $k => $v) {
+    			$this->up($v['id'], 3);
+    		}
+    	}
+    	return 'ok';
+    }
 }

+ 52 - 25
yspay/Multi.php

@@ -4,26 +4,35 @@ use Dever\Http\Curl;
 # 银联商务商户资金自主管理系统
 class Multi
 {
-	static $test_host = 'https://mobl-test.chinaums.com/channel/Business/UnifyMulti/';
-	static $host = 'https://cloudpay.chinaums.com/channel/Business/UnifyMulti/';
+	static $host = 'https://im.chinaums.com/channel/Business/UnifyMulti/';
+
+    public function act($config, $merchant, $info, $auto = 1)
+    {
+        $result = $this->huafu($config, $merchant, $info);
+        if ($result == 'ok') {
+            //$this->fenzhang($config, $merchant, $info);
+        }
+        
+        return $result;
+    }
 
 	# 划付
-    public function huafu($config, $merchant, $info, $auto = 1)
+    protected function huafu($config, $merchant, $info, $auto = 1)
     {
     	$this->config = $config;
 
     	$mid = $merchant['mid'];
-    	$cash = $info['tx_cash'];
-    	$order_num = $info['order_num'];
+    	$cash = $info['hf_cash'];
+    	$order_num = $this->getOrderNum($info['order_num']);
 
     	//整理内容信息
         $content = [
-            'merNo' => $mid,
-            'merOrderNo' => $order_num,
+            'merNo' => $merchant['merno'],
+            //'merOrderNo' => $order_num,
             'payAmt' => $cash,
         ];
         Dever::log($content, 'yspay_huafu');
-        $result = $this->curl('202001', $content);
+        $result = $this->curl('202002', $content);
         if ($result == 'ok') {
         	$data['status'] = 1;
         } else {
@@ -41,26 +50,24 @@ class Multi
         $data['auto'] = $auto;
         Dever::db('pay/yspay_cash_log')->insert($data);
 
-        $this->fenzhang($config, $merchant, $info, $auto);
-
         return 'ok';
     }
 
     # 分账
-    public function fenzhang($config, $merchant, $info, $auto = 1)
+    protected function fenzhang($config, $merchant, $info, $auto = 1)
     {
     	$this->config = $config;
 
-    	$mid = $this->config['mid'];
+    	$mid = $merchant['mid'];
     	$cash = $info['fz_cash'];
     	if (!$cash || $cash <= 0) {
-    		return;
+    		return false;
     	}
-    	$order_num = $info['order_num'];
+    	$order_num = $this->getOrderNum($info['order_num']);
 
     	//整理内容信息
         $content = [
-            'merNo' => $mid,
+            'merNo' => $merchant['merno'],
             'merOrderNo' => $order_num,
             'payAmt' => $cash,
             'cardNo' => hash("sha256",$this->config['card']),
@@ -86,6 +93,17 @@ class Multi
         Dever::db('pay/yspay_cash_log')->insert($data);
     }
 
+    protected function getOrderNum($order_num)
+    {
+        $where['order_num'] = $order_num . '_' . Dever::rand(8, 0);
+        $state = Dever::db('pay/yspay_cash_log')->one($where);
+        if (!$state) {
+            return $where['order_num'];
+        } else {
+            return $this->getOrderNum($order_num);
+        }
+    }
+
 	protected function header($code)
     {
         $header = array(
@@ -95,7 +113,7 @@ class Multi
             'srcReqTime' => date("His"),
             'srcReqId' => Dever::uuid(),
             'channelId' => '043',
-            'groupId' => config('param.groupId'),
+            'groupId' => $this->config['cash_groupid'],
         );
 
         return $header;
@@ -103,15 +121,21 @@ class Multi
 
 	protected function curl($code, $param, $state = true)
 	{
-		$url = $this->config['box'] == 1 ? self::$host : self::$test_host;
+		$url = self::$host;
 		$url .= $code;
 
     	$header = $this->header($code);
     	$header['signature'] = $this->sign($param);
+        echo $url;
+        print_r($header);
+        print_r($param);
     	$curl = Curl::getInstance($url, $param, 'post', true, $header)->setResultHeader(true);
     	$header = $curl->header();
 		$body = $curl->result();
 
+        print_r($header);
+        print_r($body);die;
+
 		if (strstr($body, '<html><head>')) {
 			return 'error';
 		}
@@ -119,7 +143,9 @@ class Multi
 		if (isset($header['respCode'])) {
 			if ($header['respCode'] == '99999999') {
 				return $state ? 'ok' : $body;
-			} else {
+			} elseif ($header['respCode'] == 'FAN00012') {
+                return $this->curl($code, $param, $state);
+            } else {
 				return $header['respMsg'];
 			}
 		} else {
@@ -130,12 +156,13 @@ class Multi
 	protected function sign($data)
 	{
 		$data = $this->getParams($data);
-		$file = $this->config['file_cert'];
-		if(!file_exists($file)) {
-            Dever::alert('private_key not exit');
+		$file = $this->config['cash_private_file'];
+        if (!strstr($file, 'http')) {
+            $file = Dever::local($file);
         }
+        
 		$pkcs12 = file_get_contents($file);
-		openssl_pkcs12_read($pkcs12, $certs, $this->config['key']);
+		openssl_pkcs12_read($pkcs12, $certs, $this->config['cash_private_file_password']);
 		if (!$certs) {
             Dever::alert('private_key error');
         }
@@ -149,9 +176,9 @@ class Multi
 
 	protected function checkSign($data, $signature)
 	{
-		$file = $this->config['file_key'];
-		if(!file_exists($file)) {
-            Dever::alert('public_key not exit');
+		$file = $this->config['cash_public_file'];
+        if (!strstr($file, 'http')) {
+            $file = Dever::local($file);
         }
 		$cert = file_get_contents($file);
         $cert = '-----BEGIN CERTIFICATE-----' . PHP_EOL

+ 32 - 18
yspay/Sign.php

@@ -4,15 +4,26 @@ use Dever;
 header("Content-Type:text/html;charset=utf-8");
 Class Sign
 {
-	static $key = "o5ho739mgrphdm28g5rwx1nw";
-	static $accesser_id = '2d9081bd7db8ad75017dbbe68981314f';
+	private $key = "o5ho739mgrphdm28g5rwx1nw";
+	private $accesser_id = '2d9081bd7db8ad75017dbbe68981314f';
 	private $url = 'https://yinshangpai.chinaums.com/self-contract-nmrs/interface/autoReg/';
-
-	static $sign_type = 'SHA-256';
+	private $sign_type = 'SHA-256';
 	private $test = 2;
 	
-	//private $product_id = array('0','1','in1','in2','in3','in4');
-	private $product_id = array('0');
+	/*
+	0-银联卡(1)
+	1-全民付(86)
+	2-POS通(68)
+	4-营销联盟(40)
+	8-公共支付-通用(9)
+	16-代付业务(74)
+	21-统一会员卡(37)
+	in1-APP支付(in1)
+	in2-H5支付(in2)
+	in3-公众号支付(in3)
+	in4-小程序支付(in4)
+	*/
+	private $product_id = array('8');
 	private $document_type = array
 	(
 		'idcard_front' => ['document_type' => '0001','document_name' => '身份证正面'],
@@ -77,7 +88,7 @@ Class Sign
 			$step = Dever::db('pay/yspay_sign_log')->config['step'][$log['step']];
 			return $date . '<br />' . $step . '<br />' . $log['desc'];
 		} else {
-			return '待提交资料';
+			return '待签约提审';
 		}
 	}
 
@@ -126,7 +137,11 @@ Class Sign
 		if (!$sign) {
 			Dever::alert('档案资料未上传');
 		}
-		$sign['bank_acct_no'] = str_replace(' ', '', $sign['bank_acct_no']);
+		$sign['merchant'] = Dever::db('pay/yspay_merchant')->one($sign['merchant_id']);
+		$sign['yspay'] = Dever::db('pay/yspay')->one(array('account_id' => $sign['merchant']['account_id']));
+		$this->key = $sign['yspay']['sign_key'];
+		$this->accesser_id = $sign['yspay']['sign_accesser_id'];
+		$sign['bank_acct_no'] = trim($sign['bank_acct_no']);
 		switch($sign['step']) {
 			case -1:
 				# 提交资料
@@ -203,7 +218,7 @@ Class Sign
 		$data['legal_idcard_no'] = $sign['idcard'];#法人身份证号
 		$data['legal_mobile'] = $sign['mobile'];#法人手机号
 		$data['legal_card_deadline'] = $sign['card_deadline'] == '长期' ? '9999-12-31' : date('Y-m-d',$sign['card_deadline']);#证件截止代表日期
-		$data['shop_name'] = $sign['name'];#店铺名称
+		$data['shop_name'] = $sign['merchant']['name'];#商户名称
 		if ($sign['bank_acct_type'] == -1) {
 			$data['bank_acct_type'] = 0;
 			$data['bank_acct_name'] = $sign['name'];#开户账号名称
@@ -375,7 +390,8 @@ Class Sign
 			$update['step'] = $step;
 			$update['clear'] = true;
 			if ($result['data']['apply_status'] == '03' && isset($result['data']['mer_no']) && $result['data']['mer_no']) {
-				$update['mid'] = $result['data']['mer_no'];
+				$mid = $result['data']['mer_no'];
+				Dever::db('pay/yspay_merchant')->update(array('merchant_id' => $sign['merchant_id'], 'mid' => $mid));
 			}
 			Dever::db('pay/yspay_sign')->update($update);
 			$this->log($update['step'], $sign, $result['data']['apply_status_msg'], $data, $result['data'], $result['request_seq']);
@@ -385,23 +401,21 @@ Class Sign
 		return $result;
 	}
 
-	private function encrypt($data='', $key='', $use3des = true)
+	private function encrypt($data)
 	{
-		$key = self::$key;
-		$res = bin2hex(openssl_encrypt($data, 'DES-EDE3', $key, OPENSSL_RAW_DATA));
+		$res = bin2hex(openssl_encrypt($data, 'DES-EDE3', $this->key, OPENSSL_RAW_DATA));
 		return $res;
 	}
 
-	private function decrypt($data='', $key='', $use3des = true)
+	private function decrypt($data)
 	{
-		$key = self::$key;
-		return openssl_decrypt(pack('H*',$data), 'DES-EDE3', $key, OPENSSL_RAW_DATA);
+		return openssl_decrypt(pack('H*',$data), 'DES-EDE3', $this->key, OPENSSL_RAW_DATA);
 	}
 
 	private function get($service, $data)
 	{
-		$accesser_id = self::$accesser_id;
-		$sign_type = self::$sign_type;
+		$accesser_id = $this->accesser_id;
+		$sign_type = $this->sign_type;
 		$param = $data;
 		$param['service'] = $service;
 		$param['sign_type'] = $sign_type;