stanley-king 3 年之前
父節點
當前提交
de363ba611

+ 7 - 4
core/framework/function/core.php

@@ -723,8 +723,11 @@ function delCacheFile($dir){
 				if (basename($v) != 'index.html')@unlink($v);
 			}
 		}
-	}else{
-		if (basename($path) != 'index.html') @unlink($path);
+	}elseif (basename($path) != 'index.html') {
+        @unlink($path);
+    }
+	else {
+	    Log::record("delCacheFile function error",Log::DEBUG);
 	}
 	return true;
 }
@@ -787,7 +790,7 @@ function readFileList($path,&$file_list,$ignore_dir=array()){
 * @return int	$price_format
 */
 function ncPriceFormat($price) {
-	$price_format	= number_format($price,2,'.','');
+	$price_format	= number_format($price,4,'.','');
 	return $price_format;
 }
 
@@ -799,7 +802,7 @@ function ncPriceFormat($price) {
 */
 function ncPriceFormatForList($price) {
     if ($price >= 10000) {
-       return number_format(floor($price/100)/100,2,'.','').L('ten_thousand');
+       return number_format(floor($price/100)/100,4,'.','').L('ten_thousand');
     } else {
      return L('currency').$price;
     }

+ 0 - 1
data/api/aop/AopEncrypt.php

@@ -41,7 +41,6 @@ namespace aop;
 
 	$encrypt_str = stripPKSC7Padding($encrypt_str);
 	return $encrypt_str;
-
 }
 
 /**

+ 1 - 1
data/model/merchant.model.php

@@ -6,7 +6,7 @@ class merchantModel extends Model
 {
     public function getMerchant($mchid)
     {
-        return $this->table('merchant')->where(['mchid' => $mchid])->select();
+        return $this->table('merchant')->where(['mchid' => $mchid])->find();
     }
 
     public function addMerchant($insert){

+ 10 - 1
data/model/thrid_refill.model.php

@@ -11,6 +11,11 @@ class thrid_refillModel extends Model
         return $this->table('third_proprice')->where(['store_id' => $store_id,'goods_id' => $goods_id,'system_code' => $system_code])->field('*')->find();
     }
 
+    public function getProduct($condition)
+    {
+        return $this->table('third_product')->field('*')->where($condition)->find();
+    }
+
     public function getProductList($condition, $page = null, $order = '', $field = '*', $limit = '')
     {
         return $this->table('third_product')->field($field)->where($condition)->order($order)->limit($limit)->page($page)->select();
@@ -39,9 +44,13 @@ class thrid_refillModel extends Model
         return $this->table('refill_third')->insert($data);
     }
 
-    public function refill_third_edit($order_id,$data)
+    public function edit_third($order_id,$data)
     {
         return $this->table('refill_third')->where(['order_id' => $order_id])->update($data);
     }
 
+    public function getThird($order_id)
+    {
+        return $this->table('refill_third')->where(['order_id' => $order_id])->find();
+    }
 }

+ 18 - 2
helper/refill/RefillBase.php

@@ -179,9 +179,12 @@ class RefillBase
 
     public function zero_order($mchid, $buyer_id, $amount, $card_no,
                         $mch_order, $idcard, $card_name, $notify_url,$quality,$org_quality,
-                        $order_time = 0, $commit_times = 0,$errmsg='')
+                        $order_time = 0, $commit_times = 0,$errmsg='',$card_type = 0,$quantity = 1,$third_params = [])
     {
-        $card_type = mtopcard\card_type($card_no,$regin_no);
+        if($card_type == mtopcard\UnknownCard) {
+            $card_type = mtopcard\card_type($card_no,$regin_no);
+        }
+
         $minfo = new member_info($buyer_id);
 
         $calc = new ZeroMerchantPrice($mchid, $amount, $card_type,$quality);
@@ -211,6 +214,7 @@ class RefillBase
             if (empty($mch_order)) {
                 $mch_order = $order_sn;
             }
+
             //虚拟订单表信息扩展
             $orderext = ['order_id' => $order_id, 'order_sn' => $order_sn, 'mchid' => $mchid,
                 'refill_amount' => $amount, 'mch_order' => $mch_order,
@@ -222,6 +226,18 @@ class RefillBase
                 'card_type' => $card_type, 'card_no' => $card_no, 'quality' => $quality, 'org_quality' => $org_quality,
                 'err_msg' => $errmsg];
             $mod_refill->add_refill($orderext);
+
+            if($card_type == mtopcard\ThirdRefillCard) {
+                $thrid_refill = Model('thrid_refill');
+                $ext = ['order_id' => $order_id,
+                    'order_sn' => $order_sn,
+                    'account_type' => $third_params['third_card_type'],
+                    'quantity' => $quantity,
+                    'user_account' => $card_no,
+                    'pcode' => $third_params['product_code']
+                ];
+                $thrid_refill->addExt($ext);
+            }
             return $order_id;
         }
         else {

+ 19 - 12
helper/refill/api/lingzh/sctongqian/RefillCallBack.php

@@ -28,22 +28,29 @@ class RefillCallBack implements refill\IRefillCallBack
     {
         $status = intval($params['State']);
         $order_sn = $params['MOrderID'];
+
         $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
-//        if (empty($order_info)) {
-//            return [false, false, false,false];
-//        }
+        if (empty($order_info)) {
+            return [false, false, false,false];
+        }
         $order_id = $order_info['order_id'];
 
-        if ($status === 2) {
-            $result = $this->rsa_decode($params['CardInfo']);
-            if (empty($result)) {
-                $data['ret_state'] = 2;
-                $data['card_info'] = '回调解密,解密失败';
-            } else {
-                $data['ret_state'] = 1;
-                $data['card_info'] = $result;
+        if ($status === 2)
+        {
+            $card_info = $params['CardInfo'];
+            if(!empty($card_info))
+            {
+                $result = $this->rsa_decode($params['CardInfo']);
+                if (empty($result)) {
+                    $data['ret_state'] = 2;
+                    $data['card_info'] = '回调解密,解密失败';
+                } else {
+                    $data['ret_state'] = 1;
+                    $data['card_info'] = $result;
+                }
+                Model('thrid_refill')->edit_third($order_id, $data);
             }
-            Model('thrid_refill')->refill_third_edit($order_id, $data);
+
             return [$order_id, true, false,true];
         }
         elseif ($status === 3) {

+ 3 - 5
helper/refill/api/lingzh/sctongqian/RefillPhone.php

@@ -72,8 +72,7 @@ class RefillPhone extends refill\IRefillPhone
         $goods_id = intval($params['goods_id']);
         $product_code = $this->getProductCode($goods_id,$params['product_code']);
 
-        Model('thrid_refill')->refill_third_edit($params['order_id'], ['chcode' => $product_code]);
-
+        Model('thrid_refill')->edit_third($params['order_id'], ['chcode' => $product_code]);
         $quantity = intval($params['quantity']);
 
         $params = $this->req_params($order_sn,$product_code,$quantity);
@@ -85,7 +84,6 @@ class RefillPhone extends refill\IRefillPhone
         $params['Sign'] = $sign;
 
         $resp = http_request(config::ORDER_URL, $params);
-
         if (empty($resp)) {
             return [false, '网络错误', true];
         }
@@ -108,7 +106,7 @@ class RefillPhone extends refill\IRefillPhone
         $order_sn = $params['order_sn'];
         $goods_id = intval($params['goods_id']);
         $product_code = $this->getProductCode($goods_id,$params['product_code']);
-        Model('thrid_refill')->refill_third_edit($params['order_id'], ['chcode' => $product_code]);
+        Model('thrid_refill')->edit_third($params['order_id'], ['chcode' => $product_code]);
 
         $quantity = intval($params['quantity']);
         $params = $this->req_params($order_sn,$product_code,$quantity);
@@ -171,7 +169,7 @@ class RefillPhone extends refill\IRefillPhone
                             $data['ret_state'] = 1;
                             $data['card_info'] = $result;
                         }
-                        Model('thrid_refill')->refill_third_edit($refill_info['order_id'], $data);
+                        Model('thrid_refill')->edit_third($refill_info['order_id'], $data);
                     }
                     $order_state = ORDER_STATE_SUCCESS;
                 }

+ 11 - 12
helper/refill/api/lingzh/sctongqian/config.php

@@ -4,21 +4,20 @@ namespace refill\sctongqian;
 class config
 {
     //正式地址及正式账号信息
-//    const ORDER_URL = 'http://video.api.sctongqian.com/Order/DirectOrder';//直充订单提交地址
-//    const CARD_ORDER_URL = 'http://video.api.sctongqian.com/Order/CardOrder';//卡密订单提交地址
-//    const QUERY_URL= 'http://video.api.sctongqian.com/Business/QueryOrder';
-//    const APP_KEY= 211394768;
-//    const App_Secret = 'vA+24E7SOUWPAIHvNMdXyw==';
+    const ORDER_URL = 'http://video.api.sctongqian.com/Order/DirectOrder';//直充订单提交地址
+    const CARD_ORDER_URL = 'http://video.api.sctongqian.com/Order/CardOrder';//卡密订单提交地址
+    const QUERY_URL= 'http://video.api.sctongqian.com/Business/QueryOrder';
+    const APP_KEY= 211394768;
+    const App_Secret = 'vA+24E7SOUWPAIHvNMdXyw==';
 
     //沙箱环境账号
-    const ORDER_URL = 'http://182.150.21.90:8050/Order/DirectOrder';//直充订单提交地址
-    const CARD_ORDER_URL = 'http://182.150.21.90:8050/Order/CardOrder';//卡密订单提交地址
-    const QUERY_URL= 'http://182.150.21.90:8050/Business/QueryOrder';
-    const APP_KEY= 211394658;
-    const App_Secret = 'ZZV9akQWGkmR0ln6zOGmsQ==';
+//    const ORDER_URL = 'http://182.150.21.90:8050/Order/DirectOrder';//直充订单提交地址
+//    const CARD_ORDER_URL = 'http://182.150.21.90:8050/Order/CardOrder';//卡密订单提交地址
+//    const QUERY_URL= 'http://182.150.21.90:8050/Business/QueryOrder';
+//    const APP_KEY= 211394658;
+//    const App_Secret = 'ZZV9akQWGkmR0ln6zOGmsQ==';
 
-//    const NOTIFY_URL = BASE_SITE_URL . "/racc/callback/lingzh/app.php";
-    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/signature.php";
+    const NOTIFY_URL = BASE_SITE_URL . "/racc/callback/lingzh/sctongqian.php";
     const API_IP = NET_IP;
     const PUBLIC_KEY = <<<heredoc
 -----BEGIN PUBLIC KEY-----

+ 22 - 2
helper/refill/policy/lingzh/policy.php

@@ -4,6 +4,9 @@
 namespace refill;
 
 use Log;
+use mtopcard;
+use function aop\addPKCS7Padding;
+use function aop\stripPKSC7Padding;
 
 class policy extends ProviderManager implements IPolicy
 {
@@ -162,10 +165,27 @@ class policy extends ProviderManager implements IPolicy
             "ord" => $refill_info['mch_order'],
             'bz' => $refill_info['official_sn'] ?? "",
             "state" => $state];
-
         $secure_key = $mch_info['secure_key'];
-        $sign = $this->sign($params, $secure_key);
 
+        $card_type = $refill_info['card_type'];
+        if($card_type == mtopcard\ThirdRefillCard)
+        {
+            $mod_third = Model('thrid_refill');
+            $thrid_info = $mod_third->getThird($refill_info['order_id']);
+
+            if (!empty($thrid_info))
+            {
+                $card_info = $thrid_info['card_info'];
+                if (!empty($card_info)) {
+                    $encrypt = openssl_encrypt($card_info,'AES-128-CBC',$secure_key);
+                    if($encrypt != false) {
+                        $params['card_info'] = $encrypt;
+                    }
+                }
+            }
+        }
+
+        $sign = $this->sign($params, $secure_key);
         return [$params, $sign];
     }
 

+ 0 - 4
racc/callback/lingzh/app.php

@@ -1,4 +0,0 @@
-<?php
-
-refill\util::push_notify('app',$_POST);
-echo ('ok');

+ 4 - 0
racc/callback/lingzh/sctongqian.php

@@ -0,0 +1,4 @@
+<?php
+
+refill\util::push_notify('sctongqian',$_POST);
+echo ('ok');

+ 74 - 29
racc/control/lzrefill.php

@@ -113,7 +113,12 @@ class lzrefillControl extends lzbaseControl
         if(empty($params['product_code'])) {
             return -9;
         }
-        if(empty($params['quantity'])) {
+        $pcode = $params['product_code'];
+        if($this->check_pcode($pcode)) {
+            return -10;
+        }
+
+        if(empty($params['quantity']) || intval($params['quantity']) < 1) {
             return -9;
         }
 
@@ -153,9 +158,11 @@ class lzrefillControl extends lzbaseControl
         return true;
     }
 
-    private function check_pcode()
+    private function check_pcode($pcode)
     {
-        //todo
+        $mod_third = Model('thrid_refill');
+        $product = $mod_third->getProduct(['system_code' => $pcode]);
+        return !empty($product);
     }
 
     public function add_thirdOp()
@@ -194,7 +201,6 @@ class lzrefillControl extends lzbaseControl
             'notify_url' => $notify_url,
             'org_quality' => $quality,
             'card_type' => $card_type,
-
             'card_no' => $card_no,
             'product_code' => $product_code,
             'quantity' => $quantity,
@@ -264,47 +270,86 @@ class lzrefillControl extends lzbaseControl
             return true;
         }
 
+        if(empty($refill_info))
+        {
+            $ret = refill\util::query_queue($mchid,$order_sn);
+            if ($ret > 0) {
+                $state = 0;
+                $msg = "{$order_sn}-充值中";
+                $remark = "";
+                $content = "|{$state}|{$msg}|{$remark}";
+                echo $content;
+                return true;
+            } else {
+                $state = 3;
+                $msg = "{$order_sn}-无此订单";
+                $remark = "";
+                $content = "|{$state}|{$msg}|{$remark}";
+                echo $content;
+                return true;
+            }
+        }
+
         $vr_order = Model('vr_order');
         $order_info = $vr_order->getOrderInfo(['order_sn' => $refill_info['order_sn']]);
 
-        $order_state = $order_info['order_state'];
-        if($order_state == ORDER_STATE_SEND || $order_state == ORDER_STATE_PAY || $order_state == ORDER_STATE_NEW) {
+        if($refill_info['is_retrying'])
+        {
             QueueClient::push("QueryRefillState",['order_id' => $refill_info['order_id']]);
             $state = 0;
             $msg = "{$order_sn}-充值中";
             $remark = "";
         }
-        elseif($order_state == ORDER_STATE_CANCEL) {
-            $state = 2;
-            $msg = "{$order_sn}-充值失败";
-            $remark = "";
+        else
+        {
+            $order_state = $order_info['order_state'];
+            if($order_state == ORDER_STATE_SEND || $order_state == ORDER_STATE_PAY || $order_state == ORDER_STATE_NEW) {
+                QueueClient::push("QueryRefillState",['order_id' => $refill_info['order_id']]);
+                $state = 0;
+                $msg = "{$order_sn}-充值中";
+                $remark = "";
+            }
+            elseif($order_state == ORDER_STATE_CANCEL) {
+                $state = 2;
+                $msg = "{$order_sn}-充值失败";
+                $remark = "";
+            }
+            else {
+                $state = 1;
+                $msg = "{$order_sn}-充值成功";
+                $remark = "{$refill_info['official_sn']}";
+            }
         }
-        else {
-            $state = 1;
-            $msg = "{$order_sn}-充值成功";
-            $remark = "{$refill_info['official_sn']}";
+
+        if($refill_info['card_type'] == mtopcard\ThirdRefillCard) {
+            $remark = $this->third_remark($refill_info);
         }
 
         $content = "|{$state}|{$msg}|{$remark}";
         echo $content;
+
         return true;
     }
 
-    private function format($order_info,$refill_info)
+    private function third_remark($refill_info)
     {
-        $result = [];
-
-        $result['mchid'] = $refill_info['mchid'];
-        $result['trade_no'] = $refill_info['order_sn'];
-        $result['order_sn'] = $refill_info['mch_order'];
-        $result['card_no'] = $refill_info['card_no'];
-        $result['card_type'] = $refill_info['card_type'];
-        $result['refill_amount'] = $refill_info['refill_amount'];
-        $result['order_amount'] = $refill_info['mch_amount'];
-        $result['order_time'] = $refill_info['order_time'];
-        $result['success_time'] = $refill_info['notify_time'];
-        $result['order_state'] = $order_info['order_state'];
-
-        return $result;
+        $mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $this->mchid()]);
+        $mod_third = Model('thrid_refill');
+        $thrid_info = $mod_third->getThird($refill_info['order_id']);
+        $secure_key = $mchinfo['secure_key'];
+
+        $remark = '';
+        if (!empty($thrid_info))
+        {
+            $card_info = $thrid_info['card_info'];
+            if (!empty($card_info)) {
+                $encrypt = openssl_encrypt($card_info,'AES-128-CBC',$secure_key);
+                if($encrypt != false) {
+                    $remark = $encrypt;
+                }
+            }
+        }
+
+        return $remark;
     }
 }

+ 2 - 1
rdispatcher/codispatcher.php

@@ -20,7 +20,8 @@ require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
 require_once(BASE_PATH . '/processor.php');
 require_once(BASE_PATH . '/proxy.php');
 
-Co::set(['hook_flags' => SWOOLE_HOOK_NATIVE_CURL]);
+//Co::set(['hook_flags' => SWOOLE_HOOK_NATIVE_CURL]);
+Co::set(['hook_flags' => 0]);
 
 if (empty($_SERVER['argv'][1])) exit('parameter error');
 $process_count = intval($_SERVER['argv'][1]);

+ 13 - 32
rdispatcher/proxy.php

@@ -186,42 +186,23 @@ class proxy
 
         if($errcode !== true)
         {
-            $fNotify = true;
-            if(($errcode === refill\errcode::MERCHANT_REFILL_ERROR && $neterr) || $errcode == refill\errcode::PROVIDER_OVERLOAD || $errcode == errcode::MERCHANT_PRICE_UNSETTING)
+            if ($order_id === 0)
             {
-                [$org_quality,$quality] = refill\RefillFactory::instance()->find_quality($mchid,$amount,$card_type,$org_quality,$commit_times,time() - $order_time);
-                if ($quality > 0) {
-                    $fNotify = false;
-                    $params['order_id'] = $order_id;
-                    if($order_id > 0) {
-                        $refill_order->edit($order_id, ['is_retrying' => 1]);
-                    }
-                    if(defined('USE_COROUTINE') && USE_COROUTINE && $errcode == refill\errcode::PROVIDER_OVERLOAD) {
-                        \Swoole\Coroutine::sleep(1);
-                    }
-                    refill\util::push_add($params);
+                $order_info = $this->latest_order($refill_order, $mchid, $mch_order);
+                if (empty($order_info)) {
+                    $order_id = refill\RefillFactory::instance()->zero_order($mchid, $buyer_id, $amount, $card_no,
+                        $mch_order, $idcard, $card_name, $notify_url, $org_quality, $org_quality,
+                        $order_time, $commit_times, $errmsg,$quantity,$third_params);
+                    refill\util::pop_queue($mchid,$mch_order);
+                } else {
+                    $order_id = $order_info['order_id'];
                 }
             }
-
-            if($fNotify)
-            {
-                if ($order_id === 0)
-                {
-                    $order_info = $this->latest_order($refill_order, $mchid, $mch_order);
-                    if (empty($order_info)) {
-                        $order_id = refill\RefillFactory::instance()->zero_order($mchid, $buyer_id, $amount, $card_no,
-                            $mch_order, $idcard, $card_name, $notify_url, $quality, $org_quality, $order_time, $commit_times, $errmsg);
-                        refill\util::pop_queue($mchid,$mch_order);
-                    } else {
-                        $order_id = $order_info['order_id'];
-                    }
-                }
-                else {
-                    $refill_order->edit($order_id, ['notify_time' => time(), 'notify_state' => 1,'is_retrying' => 0]);
-                }
-
-                QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);
+            else {
+                $refill_order->edit($order_id, ['notify_time' => time(), 'notify_state' => 1,'is_retrying' => 0]);
             }
+
+            QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);
         }
     }
 }

+ 30 - 0
test/TestRefillThird.php

@@ -3,6 +3,7 @@
 
 use PHPUnit\Framework\TestCase;
 use refill\lingzhdl\config;
+use function aop\stripPKSC7Padding;
 
 define('APP_ID', 'test');
 define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
@@ -74,8 +75,37 @@ class TestRefillThird extends TestCase
         return $params;
     }
 
+    public function testCallBack()
+    {
+        $body = '{"AppKey":"211394658","TimesTamp":"1620987358973","MOrderID":"7088040674302538334319","OrderID":"210514101558013001","State":"2","ChargeAccount":"403149064","Version":"1.0","BuyCount":"5","Attach":"","Sign":"BF8D2895A6C214931A511AE12EB9E8EE"}';
+        $params = json_decode($body, true);
+        refill\RefillFactory::instance()->notify('sctongqian', $params);
+    }
+
     public function testInstance()
     {
         refill\RefillFactory::instance()->notify_merchant(1,false);
     }
+
+    public function testEncrypt()
+    {
+        $mod_mch = Model('merchant');
+        $mch_info = $mod_mch->getMerchant(9618);
+
+        $mod_third = Model('thrid_refill');
+        $thrid_info = $mod_third->getThird(6244720);
+
+        if (!empty($mch_info) && !empty($thrid_info))
+        {
+            $card_info = $thrid_info['card_info'];
+            if (!empty($card_info)) {
+                $passwd = $mch_info['secure_key'];
+                $encrypt = openssl_encrypt($card_info,'AES-128-CBC',$passwd);
+                if($encrypt != false) {
+                    $params['card_info'] = $encrypt;
+                }
+                $output = openssl_decrypt($encrypt, 'AES-128-CBC', $passwd);
+            }
+        }
+    }
 }