Browse Source

refill_queue

stanley-king 4 years ago
parent
commit
3715fc9d64

+ 0 - 1
data/config/lingzh/refill.ini.php

@@ -9,7 +9,6 @@ $config['refill_specs'] = [
     'chinatelecom'  => [10 , 20 , 30 , 50 , 100 , 200 , 300 , 500]
 ];
 
-
 //充值渠道配置表
 
 //速汇充京东加油通道

+ 2 - 2
docker/compose/lz-28/docker-compose.yml

@@ -49,7 +49,7 @@ services:
       - ../../../:/var/www/html
       - ../../conf/php/lz-php.ini:/usr/local/etc/php/php.ini
       - /nfs/upload:/var/www/html/data/upload
-      - ../../conf/php/racc-spwan-start:/usr/local/bin/docker-spwan-start
+      - ../../conf/php/racc-spwan-start-lz:/usr/local/bin/docker-spwan-start
     container_name: "panda-racc"
     command: [docker-spwan-start]
     depends_on:
@@ -63,7 +63,7 @@ services:
       - /nfs/upload:/var/www/html/data/upload
       - ../../conf/php/lz-php-swoole.ini:/usr/local/etc/php/php.ini
     container_name: "panda-dispatcher"
-    command: [php,"/var/www/html/rdispatcher/dispatcher.php","1"]
+    command: [php,"/var/www/html/rdispatcher/dispatcher.php","20"]
     depends_on:
       - "redisrv"
 

+ 1 - 1
docker/compose/stanley/docker-compose.yml

@@ -71,7 +71,7 @@ services:
     links:
       - redisrv
     container_name: "panda-dispatcher"
-    command: [php,"/var/www/html/rdispatcher/dispatcher.php","5"]
+    command: [php,"/var/www/html/rdispatcher/dispatcher.php","1"]
     depends_on:
       - "redisrv"
 

+ 11 - 0
docker/conf/php/racc-spwan-start-lz

@@ -0,0 +1,11 @@
+#!/bin/sh
+set -e
+spawn-fcgi -a 0.0.0.0 -p 9101 -F 20 -f "php /var/www/html/racc/racc.php"
+
+time=$(date "+%Y%m%d")
+
+if [ ! -f "/var/www/html/data/log/${time}-racc.log" ]; then
+    touch "/var/www/html/data/log/${time}-racc.log"
+fi
+
+tail -f "/var/www/html/data/log/${time}-racc.log"

+ 7 - 21
helper/refill/RefillFactory.php

@@ -16,7 +16,6 @@ require_once(BASE_HELPER_PATH . '/refill/CalcMerchantPrice.php');
 require_once(BASE_HELPER_PATH . '/refill/util.php');
 require_once(BASE_HELPER_RAPI_PATH . '/api.php');
 
-
 use Log;
 use mtopcard;
 use QueueClient;
@@ -535,7 +534,11 @@ class RefillFactory
             }
 
             $params = ['order_sn' => $order_sn, 'idcard' => $idcard, 'card_name' => $card_name];
-            [$state, $err] = $provider->add($card_no, $card_type, $amount, $params);
+//            [$state, $err] = $provider->add($card_no, $card_type, $amount, $params);
+
+            $px = $this->provider('baidu',$card_type);
+            [$state, $err] = $px->add($card_no, $card_type, $amount, $params);
+
             if ($state)
             {
                 $trade_no = $err;
@@ -664,26 +667,9 @@ class RefillFactory
         $chname = $refill_info['channel_name'];
         $card_type = intval($refill_info['card_type']);
 
-        $pthis = $this;
-        $finder = function ($chname, $card_type) use ($pthis)
-        {
-            if ($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard) {
-                $providers = $pthis->mOilProvider;
-            } else {
-                $providers = $pthis->mPhoneProvider;
-            }
-
-            foreach ($providers as $provider) {
-                if ($chname == $provider->name()) {
-                    return $provider;
-                }
-            }
-
-            return NULL;
-        };
-
-        $provider = $finder($chname, $card_type);
+        $provider = $this->provider($chname, $card_type);
         [$state, $order_state] = $provider->query($refill_info);
+
         if ($state === true)
         {
             $notify_state = $refill_info['notify_state'];

+ 4 - 0
helper/refill/api/test/api.php

@@ -0,0 +1,4 @@
+<?php
+
+require_once(BASE_HELPER_RAPI_PATH . '/baidu/RefillPhone.php');
+require_once(BASE_HELPER_RAPI_PATH . '/baidu/RefillCallBack.php');

+ 53 - 0
helper/refill/api/test/baidu/RefillCallBack.php

@@ -0,0 +1,53 @@
+<?php
+
+
+namespace refill\baidu;
+
+require_once(BASE_HELPER_TEST_PATH . '/baidu/config.php');
+
+
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = $this->sign($params);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $content  = config::MCHID . $params['pt_order_id'] . $params['mch_order_id'] . $params['op_order_id'] . $params['tel'];
+        $content .= $params['price'] . $params['pay_type'] . $params['status'] . config::KEY;
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['mch_order_id'];
+        $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
+        if (empty($order_info)) {
+            return [false, false, false,false];
+        }
+        $order_id = $order_info['order_id'];
+        
+        $data['official_sn'] = strtolower($params['op_order_id']) == 'null' ? '' : $params['op_order_id'];
+
+        if ($status === 1) {
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 0) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 85 - 0
helper/refill/api/test/baidu/RefillPhone.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace refill\baidu;
+
+require_once(BASE_HELPER_TEST_PATH . '/baidu/config.php');
+
+use refill;
+use Log;
+use mtopcard;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $phone, int $amount, string $order_sn)
+    {
+        $params['tel'] = $phone;
+        $params['mch_order_id'] = $order_sn;
+        $params['mchid'] = config::MCHID;
+        $params['price'] = $amount;
+        $params['notify'] = config::NOTIFY_URL;
+        $params['teltype'] = $this->phone_type($phone);
+        $params['timeout'] = 50;
+        $params['time'] = time();
+        $params['rand'] = rand(100000,999999);
+
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params)
+    {
+        $params = $this->req_params($card_no, $amount, $params['order_sn']);
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params , 'POST' , false);
+        if ($resp === false) {
+            return [false, '系统错误'];
+        } else {
+            $rand = mt_rand(0,1);
+            Log::record("add return rand : $resp", Log::DEBUG);
+            return [$rand , ''];
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['mch_order_id'] = $refill_info['order_sn'];
+        $params['mchid'] = config::MCHID;
+        $content = $params['mchid'] . $params['mch_order_id'] . config::KEY;
+        $params['sign'] = md5($content);
+        $resp = http_request(config::QUERY_URL, $params , 'POST' , false);
+        if ($resp === false) {
+            return [false, '系统错误'];
+        } else {
+            $rand = mt_rand(0,1);
+            Log::record("query return rand : $resp", Log::DEBUG);
+            return [$rand , ''];
+        }
+    }
+
+    private function sign($params)
+    {
+        $key = config::KEY;
+        $content  = $params['mchid'] . $params['tel'] . $params['mch_order_id'] . $params['price'] . $params['teltype'] . $params['timeout'] . $params['notify'];
+        $content .= $params['time'] . $params['rand'] . $key;
+        return md5($content);
+    }
+
+    private function phone_type($phone)
+    {
+        $card_type = mtopcard\card_type($phone);
+
+        if ($card_type == mtopcard\ChinaMobileCard) {
+            return 2;
+        } elseif ($card_type == mtopcard\ChinaUnicomCard) {
+            return 1;
+        } elseif ($card_type == mtopcard\ChinaTelecomCard) {
+            return 3;
+        }
+    }
+}

+ 15 - 0
helper/refill/api/test/baidu/config.php

@@ -0,0 +1,15 @@
+<?php
+
+
+namespace refill\baidu;
+
+
+class config
+{
+    const ORDER_URL = 'https://www.baidu.com/';
+    const QUERY_URL = 'https://www.baidu.com/';
+
+    const MCHID = 10019;
+    const KEY = '953b8e10a70ef4e85b77f09448c0e316';
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/refill_baidu.php";
+}

+ 15 - 33
rdispatcher/dispatcher.php

@@ -9,18 +9,12 @@ define('BASE_PATH',BASE_ROOT_PATH . '/rdispatcher');
 
 require_once(BASE_ROOT_PATH . '/global.php');
 require_once(BASE_ROOT_PATH . '/fooder.php');
-require_once(BASE_ROOT_PATH . '/fooder.php');
-
 require_once(BASE_HELPER_PATH . '/event_looper.php');
 require_once(BASE_HELPER_PATH . '/queue/rdispatcher.php');
 require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
-require_once(BASE_HELPER_PATH . '/message/msgstates.php');
-require_once(BASE_HELPER_PATH . '/message/msgutil.php');
-require_once(BASE_HELPER_PATH . '/message/subscriber.php');
-
+require_once(BASE_HELPER_PATH . '/algorithm.php');
 require_once(BASE_PATH . '/processor.php');
 require_once(BASE_PATH . '/proxy.php');
-require_once(BASE_PATH . '/yzpolicy.php');
 
 //这个可以
 //Co::set(['hook_flags' => SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_TCP ^ SWOOLE_HOOK_UDP ^
@@ -45,49 +39,37 @@ Co::set(['hook_flags' => SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_TCP]);
 if (empty($_SERVER['argv'][1])) exit('parameter error');
 $count = intval($_SERVER['argv'][1]);
 
-
-
 function all_channels() {
     return ['refill'];
 }
 
+function handle_error($level, $message, $file, $line)
+{
+    if($level == E_NOTICE) return;
+    $trace = "handle_error: level={$level},msg={$message} file={$file},line={$line}\n";
+    $backtrace = debug_backtrace();
+    foreach ($backtrace as $item) {
+        $trace .= "{$item['file']}\t{$item['line']}\t{$item['function']}\n";
+    }
+
+    Log::record($trace,Log::ERR);
+}
+
 function work_proc()
 {
     Base::run_util();
-
-    $trdid = Thread::getCurrentThreadId();
-    Log::record("thread id = {$trdid}",Log::INFO);
-//
-//    $gMessageStates = new MsgStates();
-//    StatesHelper::init();
-//    $listener = new message\subscriber($gMessageStates);
-//    $listener->start();
-
+    set_error_handler('handle_error');
     $looper = new processor();
     $looper->run();
 }
 
+//swoole 和 pthreads 冲突
 function corun()
 {
     Log::record("start run process",Log::DEBUG);
     Co\run(function() {
         work_proc();
     });
-
-//    $process = new swoole_process(function(swoole_process $process)
-//    {
-//        try {
-//            Log::record("start run process",Log::DEBUG);
-//            Co\run(function() {
-//                work_proc();
-//            });
-//        } catch (Exception $ex) {
-//            Log::record("",Log::ERR);
-//        }
-//    });
-//
-//    $pid = $process->start();
-//    return $pid;
 }
 
 event\util::fork_workerex('corun',$count);

+ 2 - 41
rdispatcher/processor.php

@@ -2,16 +2,11 @@
 
 require_once(BASE_CORE_PATH . '/framework/function/http.php');
 
-
 class processor extends queue\ILooper
 {
-    private $mProxy;
-    const USE_COROUTINE = 1;
-
     public function __construct()
     {
         parent::__construct(new queue\DispatcherServer());
-        $this->mProxy = new proxy();
     }
 
     protected function handle($msg)
@@ -26,30 +21,10 @@ class processor extends queue\ILooper
             {
                 Log::record("start one", Log::DEBUG);
                 $method = strtolower($key);
+
+                $proxy = new proxy();
                 if($method == 'add')
                 {
-//                    go(function () use ($params) {
-//                        Log::record(__FUNCTION__,Log::DEBUG);
-//                        $mchid = $params['mchid'];
-//                        $buyer_id = $params['buyer_id'];
-//                        $amount = $params['amount'];
-//                        $card_no = $params['card_no'];
-//                        $mch_order = $params['mch_order'];
-//                        $notify_url = $params['notify_url'];
-//                        $idcard = $params['idcard'] ?? '';
-//                        $card_name = $params['card_name'] ?? '';
-//                        $order_time = $params['order_time'] ?? 0;
-//                        $commit_times = $params['commit_times'] ?? 0;
-//
-//                        $minfo = new member_info($buyer_id);
-//                        $available = $minfo->available_predeposit();
-//                        Log::record("available = {$available}",Log::DEBUG);
-//
-//                        $resp = http_request('https://www.xyzshops.cn/mobile/index.php?act=index&op=index&client_type=ios');
-//                        Log::record("recv size=" . strlen($resp), Log::DEBUG);
-//                    });
-
-                    $proxy = new proxy();
                     go(function () use ($proxy,$params) {
                         try {
                             $proxy->add($params);
@@ -58,20 +33,6 @@ class processor extends queue\ILooper
                             Log::record($x->getMessage(),Log::ERR);
                         }
                     });
-
-//                    Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_CURL);
-//                    Swoole\Coroutine\run(function () use ($proxy,$params) {
-//                        $proxy->add($params);
-//                    });
-
-//                    if(processor::USE_COROUTINE) {
-//                        Swoole\Coroutine\run(function () use ($proxy,$params) {
-//                            $proxy->add($params);
-//                        });
-//                    }
-//                    else {
-//                        $proxy->add($params);
-//                    }
                 }
                 elseif($method == 'notify') {
 

+ 0 - 6
rdispatcher/test.php

@@ -19,12 +19,6 @@ require_once(BASE_PATH . '/processor.php');
 require_once(BASE_ROOT_PATH . '/core/framework/function/http.php');
 
 Co::set(['hook_flags' => SWOOLE_HOOK_ALL]);
-
-//go(function ()
-//{
-//
-//});
-
 Co\run(function()
 {
     $n = 1000;

+ 0 - 13
rdispatcher/yzpolicy.php

@@ -1,13 +0,0 @@
-<?php
-
-class yzpolicy
-{
-    public function __construct()
-    {
-
-    }
-
-    private function init() {
-
-    }
-}

+ 1 - 0
searcher.php

@@ -19,6 +19,7 @@ require_once(BASE_HELPER_PATH . '/special_helper.php');
 require_once(BASE_HELPER_PATH . '/search/area_library.php');
 require_once(BASE_HELPER_PATH . '/brand_helper.php');
 require_once(BASE_HELPER_PATH . '/algorithm.php');
+
 require_once(BASE_HELPER_PATH . '/message/msgstates.php');
 require_once(BASE_HELPER_PATH . '/message/msgutil.php');
 require_once(BASE_HELPER_PATH . '/message/subscriber.php');