stanley-king 1 year ago
parent
commit
118971adcc

+ 1 - 1
data/config/xyz/refill.ini.php

@@ -10762,7 +10762,7 @@ $third_jumps = [
 $config['third_jumps'] = $third_jumps;
 $config['third_jumps'] = $third_jumps;
 
 
 #油需要发短信的机构
 #油需要发短信的机构
-$config['sms_mchids'] = [1090,10116];
+//$config['sms_mchids'] = [1090,10116];
 
 
 #风险流水号管理
 #风险流水号管理
 $config['risk_official_sn'] = [
 $config['risk_official_sn'] = [

+ 6 - 2
helper/refill/EventManager.php

@@ -8,6 +8,7 @@ require_once(BASE_HELPER_PATH . '/refill/event/card_crash.php');
 require_once(BASE_HELPER_PATH . '/refill/event/cbparams_pick.php');
 require_once(BASE_HELPER_PATH . '/refill/event/cbparams_pick.php');
 
 
 use refill\event\card_crash;
 use refill\event\card_crash;
+use refill\event\cbparams_pick;
 use Cache;
 use Cache;
 use Log;
 use Log;
 
 
@@ -57,7 +58,10 @@ class EventManager
             $this->mStubs[] = $crash;
             $this->mStubs[] = $crash;
         }
         }
 
 
-
+        if($cfgs['open_notify_osn'] || $cfgs['open_sms']) {
+            $event = new cbparams_pick();
+            $event->load($cfgs);
+        }
     }
     }
 
 
     public function onBeforeSubmit(order $order)
     public function onBeforeSubmit(order $order)
@@ -127,7 +131,7 @@ class EventManager
     {
     {
         $stubs = $this->mStubs;
         $stubs = $this->mStubs;
         foreach ($stubs as $stub) {
         foreach ($stubs as $stub) {
-            $stub->onComplete($refill_info, $mch_info, $ctls);
+            $stub->onEventCallback($refill_info, $mch_info, $ctls);
         }
         }
     }
     }
 }
 }

+ 88 - 0
helper/refill/event/cbparams_pick.php

@@ -11,13 +11,101 @@ namespace refill\event;
 
 
 class cbparams_pick extends IEventRefill
 class cbparams_pick extends IEventRefill
 {
 {
+    private $mOpenOSN = false;
+    private $mOsnStarts = [];
+    private $mOsnMchids = [];
+
+    private $mOpenSMS = false;
+    private $mSmsMchids = [];
+
     public function load(array $cfgs)
     public function load(array $cfgs)
     {
     {
+        $osns_reader = function ($input)
+        {
+            $sns = [];
+            $data = explode(',', $input);
+            foreach ($data as $val)
+            {
+                $val = trim($val);
+                if (!empty($val)) {
+                    $sns[] = strtolower($val);
+                }
+            }
+
+            return $sns;
+        };
+
+        $ids_reader = function ($input)
+        {
+            $ids = [];
+            $data = explode(',', $input);
+            foreach ($data as $val)
+            {
+                $val = trim($val);
+                $val = intval($val);
+                if ($val > 0) {
+                    $ids[] = $val;
+                }
+            }
+
+            return $ids;
+        };
+
 
 
+        $this->mOpenOSN = $cfgs['open_notify_osn'] ?? false;
+        if ($this->mOpenOSN) {
+            $this->mOsnStarts = $osns_reader($cfgs['cfgs_notify_osn']['exclude_sns_start'] ?? []);
+            $this->mOsnMchids = $ids_reader($cfgs['cfgs_notify_osn']['exclude_mchids'] ?? []);
+        }
+
+        $this->mOpenSMS = $cfgs['open_sms'] ?? false;
+        if ($this->mOpenSMS) {
+            $this->mSmsMchids = $ids_reader($cfgs['cfgs_sms']['include_mchids'] ?? []);
+        }
     }
     }
 
 
     public function onEventCallback($refill_info, $mch_info, &$ctls)
     public function onEventCallback($refill_info, $mch_info, &$ctls)
     {
     {
+        $start_with = function ($haystack, $needle) {
+            $length = strlen($needle);
+            return (substr($haystack, 0, $length) === $needle);
+        };
+
+        $snNeedExclude = function ($osn) use ($start_with)
+        {
+            $osn = strtolower($osn);
+            foreach ($this->mOsnStarts as $header)
+            {
+                if ($start_with($osn, $header)) {
+                    return true;
+                }
+            }
+            return false;
+        };
+
+
+        $mchid = $refill_info['mchid'];
+
+        $need_osn = true;
+        if($this->mOpenOSN)
+        {
+            $osn = $refill_info['official_sn'] ?? "";
+            $snEx = $snNeedExclude($osn);
+            $mchNeed = in_array($mchid,$this->mOsnMchids);
+
+            if ($snEx and !$mchNeed) {
+                $need_osn = false;
+            }
+        }
+        $ctls['osn'] = $need_osn;
 
 
+        $need_sms = false;
+        if($this->mOpenSMS)
+        {
+            if(in_array($mchid,$this->mSmsMchids)) {
+                $need_sms = true;
+            }
+        }
+        $ctls['sms'] = $need_sms;
     }
     }
 }
 }

+ 19 - 18
helper/refill/policy/xyz/policy.php

@@ -520,12 +520,15 @@ class policy extends ProviderManager implements IPolicy
             $err_msg = 'fail';
             $err_msg = 'fail';
         }
         }
 
 
-        $ctls = ['official_sn' => true,
-            'sms' => false
-        ];
-
+        $ctls = ['osn' => true, 'sms' => false];
         util::onEventCallback($refill_info, $mch_info, $ctls);
         util::onEventCallback($refill_info, $mch_info, $ctls);
 
 
+        if($ctls['osn']) {
+            $osn = $refill_info['official_sn'] ?? "";
+        } else {
+            $osn = "";
+        }
+
         $params = [
         $params = [
             "mchid" => $refill_info['mchid'],
             "mchid" => $refill_info['mchid'],
             "order_sn" => $refill_info['mch_order'],
             "order_sn" => $refill_info['mch_order'],
@@ -535,13 +538,16 @@ class policy extends ProviderManager implements IPolicy
             "trade_no" => $refill_info['order_sn'],
             "trade_no" => $refill_info['order_sn'],
             "idcard" => $refill_info['idcard'] ?? "",
             "idcard" => $refill_info['idcard'] ?? "",
             "card_name" => $refill_info['card_name'] ?? "",
             "card_name" => $refill_info['card_name'] ?? "",
-            'official_sn' => $refill_info['official_sn'] ?? "",
+            'official_sn' => $osn,
             'message' => $err_msg,
             'message' => $err_msg,
             "state" => $state];
             "state" => $state];
 
 
-        [$has_sms,$sms] = $this->sms($refill_info);
-        if($has_sms) {
-            $params['sms'] = $sms;
+        if($ctls['sms'])
+        {
+            [$has_sms,$sms] = $this->sms($refill_info);
+            if($has_sms) {
+                $params['sms'] = $sms;
+            }
         }
         }
 
 
         $secure_key = $mch_info['secure_key'];
         $secure_key = $mch_info['secure_key'];
@@ -552,16 +558,11 @@ class policy extends ProviderManager implements IPolicy
 
 
     private function sms($refill_info)
     private function sms($refill_info)
     {
     {
-        global $config;
-
-        $mchids = $config['sms_mchids'];
-        $mchid = $refill_info['mchid'];
         $official_sn = $refill_info['official_sn'] ?? "";
         $official_sn = $refill_info['official_sn'] ?? "";
         $card_type = $refill_info['card_type'];
         $card_type = $refill_info['card_type'];
         $card_no = $refill_info['card_no'];
         $card_no = $refill_info['card_no'];
         $amount = intval($refill_info['refill_amount']);
         $amount = intval($refill_info['refill_amount']);
-
-        if(in_array($mchid,$mchids) && !empty($official_sn) && $card_type == mtopcard\SinopecCard && !empty($card_no))
+        if(!empty($official_sn) && $card_type == mtopcard\SinopecCard && !empty($card_no))
         {
         {
             $short_no = substr($card_no,-6);
             $short_no = substr($card_no,-6);
             $ret = preg_match('/\d{4}(?P<month>\d{2})(?P<day>\d{2})(?P<hour>\d{2})(?P<min>\d{2})\d{4}/u', $official_sn, $matches);
             $ret = preg_match('/\d{4}(?P<month>\d{2})(?P<day>\d{2})(?P<hour>\d{2})(?P<min>\d{2})\d{4}/u', $official_sn, $matches);
@@ -583,15 +584,15 @@ class policy extends ProviderManager implements IPolicy
         foreach ($params as $k => $v) {
         foreach ($params as $k => $v) {
             if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
             if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
                 if ($i == 0) {
                 if ($i == 0) {
-                    $body .= "{$k}" . "=" . urlencode($v);
+                    $body .= "$k" . "=" . urlencode($v);
                 } else {
                 } else {
-                    $body .= "&" . "{$k}" . "=" . urlencode($v);
+                    $body .= "&" . "$k" . "=" . urlencode($v);
                 }
                 }
                 $i++;
                 $i++;
             }
             }
         }
         }
-        $body .= "&key={$key}";
-        Log::record("notify body={$body}",Log::DEBUG);
+        $body .= "&key=$key";
+        Log::record("notify body=$body", Log::DEBUG);
 
 
         return md5($body);
         return md5($body);
     }
     }

+ 9 - 0
test/TestRefillUtil.php

@@ -15,6 +15,7 @@ require_once(BASE_HELPER_PATH . '/refill/XYZRefillFactory.php');
 require_once(BASE_HELPER_PATH . '/refill/util.php');
 require_once(BASE_HELPER_PATH . '/refill/util.php');
 require_once(BASE_HELPER_PATH . '/refill/EventManager.php');
 require_once(BASE_HELPER_PATH . '/refill/EventManager.php');
 require_once(BASE_HELPER_PATH . '/refill/event/test_crash.php');
 require_once(BASE_HELPER_PATH . '/refill/event/test_crash.php');
+require_once(BASE_HELPER_PATH . '/refill/event/cbparams_pick.php');
 require_once(BASE_HELPER_PATH . '/refill/order.php');
 require_once(BASE_HELPER_PATH . '/refill/order.php');
 
 
 class TestRefillUtil extends TestCase
 class TestRefillUtil extends TestCase
@@ -106,7 +107,15 @@ class TestRefillUtil extends TestCase
     {
     {
         $cacher = Cache::getInstance('cacheredis');
         $cacher = Cache::getInstance('cacheredis');
         $cfgs = $cacher->get('event-config', 'refill-');
         $cfgs = $cacher->get('event-config', 'refill-');
+        if(!empty($cfgs)) {
+            $cfgs = unserialize($cfgs);
+        }
 
 
+        if($cfgs['open_notify_osn'] || $cfgs['open_sms']) {
+            $event = new refill\event\cbparams_pick();
+            $event->load($cfgs);
+            $event->onEventCallback(['official_sn' => '1002','mchid' => 1093],[],$ctls);
+        }
     }
     }
 
 
     public function testGetDetail()
     public function testGetDetail()