فهرست منبع

for add electric fee

stanley-king 3 سال پیش
والد
کامیت
1620a394a7

+ 5 - 0
core/framework/libraries/log.php

@@ -26,6 +26,7 @@ class scope_trace
 
 class Log
 {
+    //ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < OFF
     const SQL = 1;
     const INFO = 2;
     const DEBUG = 3;
@@ -191,6 +192,10 @@ class Log
 
         if ($this->mAppFile !== false) {
             fwrite($this->mAppFile, $content);
+            fflush($this->mAppFile);
+        }
+        else {
+            exit();
         }
     }
 

+ 0 - 14
docker/compose/stanley/admin/docker-compose.yml

@@ -1,20 +1,6 @@
 version: "3.7"
 
 services:
-  nginxweb:
-    image: nginx:alpine
-    ports:
-      - "80:80"
-    volumes:
-      - ../../../../:/var/www/html
-      - /Volumes/Transcend/upload:/var/www/html/data/upload
-      - /Users/stanley-king/work/WebProject/wapshop/dist:/var/www/html/mshop
-      - ../conf/etc/localtime:/etc/localtime:ro
-      - ../conf/nginx/cert:/etc/nginx/cert
-      - ../conf/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
-    container_name: "panda-nginxweb"
-    command: [nginx,'-g','daemon off;']
-
   mchsrv:
     image: php-zts:7.3.18
     ports:

+ 9 - 0
docker/compose/stanley/conf/nginx/nginx.conf

@@ -103,6 +103,15 @@ http
             include fastcgi_params;
         }
 
+        location ~ /admin/[/\w]+\.php$ {
+            add_header Cache-Control no-store;
+            root           $folder_name;
+            fastcgi_pass   host.docker.internal:9000;
+            fastcgi_index  index.php;
+            fastcgi_param  SCRIPT_FILENAME  $folder_name$fastcgi_script_name;
+            include        fastcgi_params;
+        }
+
         location ~ \.php$ {
 	        add_header Cache-Control no-store;
             root           $folder_name;

+ 2 - 0
docker/compose/stanley/rmcontainer.sh

@@ -0,0 +1,2 @@
+docker container stop $(docker container ls -aq)
+docker container rm $(docker container ls -aq)

+ 23 - 2
helper/mtopcard/mtopcard.php

@@ -8,8 +8,6 @@ require_once(BASE_HELPER_PATH . '/mtopcard/user_topcards.php');
 require_once(BASE_HELPER_PATH . '/mtopcard/CardPaper.php');
 require_once(BASE_HELPER_PATH . '/mtopcard/cards_helper.php');
 
-use Log;
-
 #用户卡的类型
 const UnknownCard = 0;
 
@@ -23,6 +21,15 @@ const ChinaTelecomCard = 6;        //手机卡
 
 const ThirdRefillCard  = 7;        //三方账号充值
 
+//$input['third_card_type'];//账号类型1 手机号,2 QQ号,3 微信号,4 电卡
+const ThirdCardPhone = 1;
+const ThirdCardQQ = 2;
+const ThirdCardWexin = 3;
+const ThirdCardElect = 4;
+
+const ElectricCompanyTypes = ['nation', 'south'];
+const ElectricUseTypes  = ['home', 'commerce', 'pedlar'];
+const CardidVerifyLength = 6;
 
 #卡的状态
 const CardNormal = 1;
@@ -298,4 +305,18 @@ function valid_phone($card_no)
 {
     $query = new card_query();
     return $query->validate($card_no);
+}
+
+function electric_product_code($company_type,$use_type,$refill_amount)
+{
+    return "DF_{$company_type}_{$use_type}_{$refill_amount}";
+}
+
+function is_alpha($text) {
+    return is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text);
+};
+
+function electric_exists($product) {
+    static $products = [];
+    return in_array($product,$products);
 }

+ 25 - 2
helper/refill/order.php

@@ -31,6 +31,7 @@ class order
     private $mProductCode;
     private $mQuantity;
     private $mThirdCardType; // 三方充值账号类型
+    private $mElecticExtes = [];
 
     public function __construct()
     {
@@ -169,7 +170,6 @@ class order
     public function is_phone() {
         return in_array($this->mCardType,[mtopcard\ChinaMobileCard,mtopcard\ChinaUnicomCard,mtopcard\ChinaTelecomCard]);
     }
-
     private function setParams($params)
     {
         $this->mMchid = intval($params['mchid']);
@@ -200,6 +200,14 @@ class order
             $this->mCardType = $card_type;
             $this->mIsValidate = true;
             $this->mFirstCommit = true;
+
+            if($this->mThirdCardType == mtopcard\ThirdCardElect)
+            {
+                $this->mElecticExtes['company_type'] = $params['company_type'];
+                $this->mElecticExtes['use_type'] = $params['use_type'];
+                $this->mElecticExtes['province'] = $params['province'];
+                $this->mElecticExtes['card_id'] = $params['card_id'];
+            }
         }
         else
         {
@@ -266,6 +274,12 @@ class order
         $ext = ['order_id' => $order_id, 'order_sn' => $order_sn, 'account_type' => $this->mThirdCardType,
             'quantity' => $this->mQuantity, 'user_account' => $this->mCardNo , 'pcode' => $this->mProductCode
         ];
+        if($this->is_third() && $this->mThirdCardType == mtopcard\ThirdCardElect) {
+            $ext['company_type'] = $this->mElecticExtes['company_type'];
+            $ext['use_type'] = $this->mElecticExtes['use_type'];
+            $ext['province'] = $this->mElecticExtes['province'];
+            $ext['card_id'] = $this->mElecticExtes['card_id'];
+        }
         return $ext;
     }
     public function channel_params($order_id,$order_sn,$goods_id)
@@ -275,12 +289,21 @@ class order
             'quality' => $this->mCurQuality, 'order_id' => $order_id, 'regin_no' => $this->mRegionNo,
             'mchid' => $this->mMchid];
 
-        if($this->is_third()) {
+        if($this->is_third())
+        {
             $params['quantity'] = $this->mQuantity;
             $params['product_code'] = $this->mProductCode;
             $params['third_card_type'] = $this->mThirdCardType;
             $params['goods_id'] = $goods_id;
+
+            if($this->mThirdCardType == mtopcard\ThirdCardElect) {
+                $params['company_type'] = $this->mElecticExtes['company_type'];
+                $params['use_type'] = $this->mElecticExtes['use_type'];
+                $params['province'] = $this->mElecticExtes['province'];
+                $params['card_id'] = $this->mElecticExtes['card_id'];
+            }
         }
+
         return $params;
     }
 

+ 9 - 9
mobile/control/merchant.php

@@ -21,15 +21,15 @@ class merchantControl
             throw new Exception("机构已被关闭。");
         }
 
-        $ips = unserialize($mchinfo['ip_white_list']);
-        if(!empty($ips)) {
-            $addr = $_SERVER['REMOTE_ADDR'];
-            Log::record("request ip:{$addr}",Log::DEBUG);
-
-            if(!in_array($addr,$ips)) {
-                throw new Exception("请求地址不在白名单中");
-            }
-        }
+//        $ips = unserialize($mchinfo['ip_white_list']);
+//        if(!empty($ips)) {
+//            $addr = $_SERVER['REMOTE_ADDR'];
+//            Log::record("request ip:{$addr}",Log::DEBUG);
+//
+//            if(!in_array($addr,$ips)) {
+//                throw new Exception("请求地址不在白名单中");
+//            }
+//        }
 
         $this->mUseKey = intval($mchinfo['use_key']);
         if($this->mUseKey && !$this->verify_md5($mchinfo['secure_key'])) {

+ 104 - 0
mobile/control/refill.php

@@ -215,6 +215,110 @@ class refillControl extends merchantControl
         }
     }
 
+    private function check_electirc($params)
+    {
+        if(empty($params['notifyurl'])) {
+            return [false,'参数没有包含notifyurl'];
+        }
+        if(empty($params['order_sn'])) {
+            return [false,'参数没有包含贵方唯一订单号:order_sn'];
+        }
+
+        if(empty($params['amount']) || intval($params['amount']) <= 0) {
+            return [false,'参数没有包含充值金额:amount'];
+        }
+
+        if(empty($params['company_type']) || !in_array($params['company_type'],mtopcard\ElectricCompanyTypes)) {
+            return [false,'没有电卡类型参数(nation,south)'];
+        }
+        if(empty($params['use_type']) || !in_array($params['use_type'],mtopcard\ElectricUseTypes)) {
+            return [false,"没有电卡用途参数(home,commerce,pedlar)"];
+        }
+        if(empty($params['province']) || !array_key_exists($params['province'],mtopcard\ProvinceList)) {
+            return [false,"请传入省份"];
+        }
+
+        if($params['company_type'] === 'south')
+        {
+            $card_id = $params['card_id'];
+            if(empty($card_id) || strlen($card_id) != mtopcard\CardidVerifyLength || !mtopcard\is_alpha($card_id)) {
+                return [false,"请传入正确的身份证后6位"];
+            }
+        }
+
+        return [true,""];
+    }
+
+    public function add_electricOp()
+    {
+        [$success,$error] = $this->check_electirc($_GET);
+        if($success === false) {
+            return self::outerr(201,$error);
+        }
+
+        $notify_url = $_GET['notifyurl'];
+        $mch_order = $_GET['order_sn'];   //对方的order编号
+
+        $card_no = $_GET['cardno'] ?? '';
+
+        $quantity = 1;
+        $third_card_type = mtopcard\ThirdCardElect;
+        $company_type = $_GET['company_type'];
+        $use_type = $_GET['use_type'];
+        $province = intval($_GET['province']);
+        $amount = intval($_GET['amount']);
+
+        if($company_type == 'nation') {
+            $card_id = '';
+        } else {
+            $card_id = $_GET['card_id'] ?? '';
+        }
+
+//        $product_code = mtopcard\electric_product_code($company_type,$use_type,$amount);
+        $product_code = 'XYZ100744';
+        $amount = refill\util::ThirdRefillAmount;
+
+
+        //三方充值没有质量
+        $quality = 1;
+        $card_type = mtopcard\ThirdRefillCard;
+
+        if(!$this->check_mchorder($this->mchid(),$mch_order)) {
+            return self::outerr(205,"客户订单号重复或者为空.");
+        }
+
+        $params = ['mchid' => $this->mchid(),
+            'buyer_id' => $this->adminid(),
+            'amount' => $amount,
+            'mch_order' => $mch_order,
+            'notify_url' => $notify_url,
+
+            'org_quality' => $quality,
+            'card_type' => $card_type,
+
+            'card_no' => $card_no,
+            'product_code' => $product_code,
+            'quantity' => $quantity,
+            'third_card_type' => $third_card_type,
+
+            'company_type' => $company_type,
+            'use_type' => $use_type,
+            'province' => $province,
+            'card_id' => $card_id
+        ];
+
+        refill\util::push_queue_order($this->mchid(),$mch_order,ORDER_STATE_QUEUE);
+        Model('refill_order')->add_detail($this->mchid(),$mch_order,$params,ORDER_STATE_QUEUE);
+
+        $state = refill\util::push_addthird($params);
+        if ($state === true) {
+            return self::outsuccess(['state' => true]);
+        } else {
+            refill\util::del_queue_order($this->mchid(),$mch_order);
+            Model('refill_order')->del_detail($this->mchid(),$mch_order);
+            return self::outerr(208, '提交失败');
+        }
+    }
 
     private function can_refill($cardno)
     {

+ 2 - 0
mobile/mobile_run.php

@@ -1,5 +1,7 @@
 <?php
 
+echo('mobile start');
+
 define('APP_ID', 'mobile');
 define('MOBILE_SERVER',true);
 define('SUPPORT_PTHREAD',true);

+ 74 - 0
test/TestElectric.php

@@ -0,0 +1,74 @@
+<?php
+
+
+use PHPUnit\Framework\TestCase;
+
+define('APP_ID', 'test');
+define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
+
+require_once(BASE_ROOT_PATH . '/global.php');
+require_once(BASE_CORE_PATH . '/lrlz.php');
+require_once(BASE_ROOT_PATH . '/fooder.php');
+
+require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
+require_once(BASE_HELPER_PATH . '/refill_proxy.php');
+require_once(BASE_CORE_PATH . '/framework/function/http.php');
+
+class TestElectric extends TestCase
+{
+    public static function setUpBeforeClass() : void
+    {
+        Base::run_util();
+    }
+
+    public function testCardid()
+    {
+        $card_id = '051818';
+        $succ = mtopcard\is_alpha($card_id);
+    }
+
+    public function testAddElectric()
+    {
+        $params = [ 'mchid' => 1092,
+            "act" => "refill",
+            "op" => "add_electric",
+            'order_sn' => $this->make_sn(),
+            'notifyurl' => 'https://www.xyzshops.cn/mobile/signature.php',
+            'cardno' => '1004638637',
+            'amount' => 100,
+            'company_type' => 'south',
+            'use_type' => 'home',
+            'card_id' => '051818',
+            'province' => 1
+        ];
+
+        $proxy = new refill_proxy('210fe406954220f56085997d6a4c5b80');
+        $proxy->send(BASE_SITE_URL . "/mobile/index.php",$params);
+    }
+
+    public function testNet()
+    {
+        $params = [ 'mchid' => 1092,
+            "act" => "refill",
+            "op" => "add_electric",
+            'order_sn' => $this->make_sn(),
+            'notifyurl' => 'https://www.xyzshops.cn/mobile/signature.php',
+            'cardno' => '1004638637',
+            'amount' => 100,
+            'company_type' => 'south',
+            'use_type' => 'home',
+            'card_id' => '051818',
+            'province' => 1
+        ];
+
+        $x = http_request(BASE_SITE_URL . "/mobile/index.php",$params);
+    }
+
+    private function make_sn()
+    {
+        return mt_rand(1000, 9999)
+            . sprintf('%010d', time())
+            . sprintf('%06d', (float)microtime() * 1000000);
+    }
+
+}