Browse Source

merge and add provider yibao

ayHaru 4 years atrás
parent
commit
fbc6272bb2

+ 1 - 13
data/logic/queue.logic.php

@@ -1415,20 +1415,8 @@ class queueLogic
             return callback(false, 'QueryRefillState 参数order_id错误');
         }
         else {
-            refill\util::push_notify_merchant($order_id,$manual);
+            refill\util::push_query($order_id);
             return callback(true, '成功放入通知队列', ['order_id' => $order_id]);
         }
-
-        $order_id = intval($params['order_id']);
-        refill\util::push_query($params);
-
-
-        if($order_id <= 0) {
-            return callback(false);
-        }
-        $success = refill\RefillFactory::instance()->query($order_id);
-        if($success) {
-            return callback(true, '', ['order_id' => $order_id]);
-        }
     }
 }

+ 1 - 1
helper/fcgisrv/RAccServer.php

@@ -30,7 +30,7 @@ class RAccServer extends BaseServer
 
         $exfiles = [
             'callback/lingzh/baizeyd.php','callback/lingzh/aming.php','callback/lingzh/binghc.php',
-            'callback/lingzh/ruishun.php','callback/lingzh/wuchen.php'
+            'callback/lingzh/ruishun.php','callback/lingzh/wuchen.php','callback/lingzh/yibao.php'
         ];
 
         $this->setExFiles($exfiles);

+ 4 - 2
helper/refill/ProviderManager.php

@@ -281,10 +281,12 @@ class ProviderManager
         try
         {
             $file = BASE_HELPER_RAPI_PATH . "/{$name}/RefillCallBack.php";
-            if(file_exists($file)){
+            if(!file_exists($file)){
+                Log::record("provider callback api file={$file} not exist.",Log::DEBUG);
                 return false;
             } else {
-                include($file);
+                require_once($file);
+                Log::record("file={$file} load success.",Log::DEBUG);
             }
 
             $class_name = "refill\\{$name}\\RefillCallBack";

+ 25 - 29
helper/refill/RefillBase.php

@@ -404,41 +404,37 @@ class RefillBase
         $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id,'inner_status' => 0]);
 
         $chname = $refill_info['channel_name'];
-
         $provider = $this->mPolicy->provider($chname);
         [$state, $order_state] = $provider->query($refill_info);
 
-        if ($state === true)
-        {
-            $notify_state = $refill_info['notify_state'];
-            if($notify_state == 0)
-            {
-                $modify_able = true;
-                if(!$provider->callback())
-                {
-                    $logic_vr_order = Logic("vr_order");
-                    if ($order_state == ORDER_STATE_SUCCESS) {
-                        $logic_vr_order->changeOrderStateSuccess($order_id);
-                    } elseif ($order_state == ORDER_STATE_CANCEL) {
-                        $mod_order = Model('vr_order');
-                        $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
-                        $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口查询失败,不再重试.");
-                    } else {
-                        $modify_able = false;
-                        QueueClient::async_push("QueryRefillState",['order_id' => $order_id],180);
-                    }
-                }
+        if(!$state) {
+            QueueClient::async_push("QueryRefillState",['order_id' => $order_id],180);
+            return false;
+        }
 
-                if($modify_able) {
-                    $mod_refill->edit($order_id, ['notify_time' => time(), 'notify_state' => 1]);
-                    QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);
-                }
-            }
+        $mod_order = Model('vr_order');
+        $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
+        $org_state = $order_info['order_state'];
 
-            return true;
+        $modify_able = true;
+        if($org_state == ORDER_STATE_SEND)
+        {
+            $logic_vr_order = Logic("vr_order");
+            if ($order_state == ORDER_STATE_SUCCESS) {
+                $logic_vr_order->changeOrderStateSuccess($order_id);
+            } elseif ($order_state == ORDER_STATE_CANCEL) {
+                $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口查询失败,不再重试.");
+            } else {
+                $modify_able = false;
+                QueueClient::async_push("QueryRefillState",['order_id' => $order_id],180);
+            }
         }
-        else {
-            return false;
+
+        if($modify_able) {
+            $mod_refill->edit($order_id, ['notify_time' => time(), 'notify_state' => 1]);
+            QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => true]);
         }
+
+        return true;
     }
 }

+ 3 - 3
helper/refill/api/lingzh/aming/RefillPhone.php

@@ -34,14 +34,14 @@ class RefillPhone extends refill\IRefillPhone
 
         $resp = http_request(config::ORDER_URL, $params , 'POST' , false);
         if ($resp === false) {
-            return [false, '系统错误'];
+            return [false, '系统错误', true];
         } else {
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp ,true);
             if($resp['result'] == 'SUCCESS') {
-                return [true, $resp['orderNo']];
+                return [true, $resp['orderNo'], false];
             }
-            return [false , $resp['msg']];
+            return [false , $resp['msg'], false];
         }
     }
 

+ 3 - 0
helper/refill/api/lingzh/api.php

@@ -17,3 +17,6 @@ require_once(BASE_HELPER_RAPI_PATH . '/weisyd/RefillCallBack.php');
 
 require_once(BASE_HELPER_RAPI_PATH . '/wuchen/RefillPhone.php');
 require_once(BASE_HELPER_RAPI_PATH . '/wuchen/RefillCallBack.php');
+
+require_once(BASE_HELPER_RAPI_PATH . '/yibao/RefillPhone.php');
+require_once(BASE_HELPER_RAPI_PATH . '/yibao/RefillCallBack.php');

+ 3 - 3
helper/refill/api/lingzh/baizeyd/RefillPhone.php

@@ -33,14 +33,14 @@ class RefillPhone extends refill\IRefillPhone
 
         $resp = http_request(config::ORDER_URL, $params , 'POST' , false , config::ExtHeaders);
         if ($resp === false) {
-            return [false, '系统错误'];
+            return [false, '系统错误', true];
         } else {
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp ,true);
             if($resp['state'] == 'success' && $resp['code'] == 000) {
-                return [true, $resp['data']['id']];
+                return [true, $resp['data']['id'], false];
             }
-            return [false , $resp['message']];
+            return [false , $resp['message'], false];
         }
     }
 

+ 3 - 3
helper/refill/api/lingzh/binghc/RefillPhone.php

@@ -34,14 +34,14 @@ class RefillPhone extends refill\IRefillPhone
 
         $resp = http_request(config::ORDER_URL, $params , 'POST' , false);
         if ($resp === false) {
-            return [false, '系统错误'];
+            return [false, '系统错误', true];
         } else {
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp ,true);
             if($resp['result'] == 'SUCCESS') {
-                return [true, $resp['orderNo']];
+                return [true, $resp['orderNo'], false];
             }
-            return [false , $resp['msg']];
+            return [false , $resp['msg'], false];
         }
     }
 

+ 3 - 3
helper/refill/api/lingzh/legou/RefillPhone.php

@@ -41,14 +41,14 @@ class RefillPhone extends refill\IRefillPhone
 
         $resp = http_request(config::ORDER_URL, $params , 'POST' , false , config::ExtHeaders);
         if ($resp === false) {
-            return [false, '系统错误'];
+            return [false, '系统错误', true];
         } else {
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp ,true);
             if($resp['code']['status'] == 100000) {
-                return [true, $resp['obj']];
+                return [true, $resp['obj'], false];
             }
-            return [false , $resp['code']['desc']];
+            return [false , $resp['code']['desc'], false];
         }
     }
 

+ 3 - 3
helper/refill/api/lingzh/ruishun/RefillPhone.php

@@ -34,14 +34,14 @@ class RefillPhone extends refill\IRefillPhone
 
         $resp = http_request(config::ORDER_URL, $params , 'POST' , false);
         if ($resp === false) {
-            return [false, '系统错误'];
+            return [false, '系统错误', true];
         } else {
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp ,true);
             if($resp['result'] == 'SUCCESS') {
-                return [true, $resp['orderNo']];
+                return [true, $resp['orderNo'], false];
             }
-            return [false , $resp['msg']];
+            return [false , $resp['msg'], false];
         }
     }
 

+ 3 - 3
helper/refill/api/lingzh/weisyd/RefillPhone.php

@@ -33,14 +33,14 @@ class RefillPhone extends refill\IRefillPhone
 
         $resp = http_request(config::ORDER_URL, $params , 'POST' , false , config::ExtHeaders);
         if ($resp === false) {
-            return [false, '系统错误'];
+            return [false, '系统错误', true];
         } else {
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp ,true);
             if($resp['state'] == 'success' && $resp['code'] == 000) {
-                return [true, $resp['data']['id']];
+                return [true, $resp['data']['id'], false];
             }
-            return [false , $resp['message']];
+            return [false , $resp['message'], false];
         }
     }
 

+ 4 - 4
helper/refill/api/lingzh/wuchen/RefillPhone.php

@@ -50,18 +50,18 @@ class RefillPhone extends refill\IRefillPhone
         $params = json_encode($params);
         $resp = http_post_data(config::ORDER_URL, $params , $header);
         if ($resp === false) {
-            return [false, '系统错误'];
+            return [false, '系统错误', true];
         } else {
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp ,true);
             if($resp['code'] == 10000) {
                 if($resp['data']['orders_success'][0]['state'] == 'success') {
-                    return [true, $resp['orders_success'][0]['sys_sn']];
+                    return [true, $resp['orders_success'][0]['sys_sn'], false];
                 }else{
-                    return [false , $resp['orders_failure'][0]['message']];
+                    return [false , $resp['orders_failure'][0]['message'], false];
                 }
             }else{
-                return [false , $resp['message']];
+                return [false , $resp['message'], false];
             }
         }
     }

+ 59 - 0
helper/refill/api/lingzh/yibao/RefillCallBack.php

@@ -0,0 +1,59 @@
+<?php
+
+
+namespace refill\yibao;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yibao/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  = $params['result'] . $params['msg'];
+        if(is_null($params['order'])) {
+            $content .= "null";
+        }else{
+            $content .= $params['order'];
+        }
+        $content .= $params['phone_no'] . $params['amount'] . $params['op_no'] . config::KEY;
+        return md5($content);
+    }
+
+
+    public function notify($params)
+    {
+        $status = intval($params['orderStatus']);
+        $order_sn = $params['orderNo'];
+        $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['carrierOrderNo']) == 'null' ? '' : $params['carrierOrderNo'];
+
+        if ($status === 2) {
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 3) {
+            return [$order_id, false, false,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 120 - 0
helper/refill/api/lingzh/yibao/RefillPhone.php

@@ -0,0 +1,120 @@
+<?php
+
+namespace refill\yibao;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yibao/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $phone, int $amount, string $order_sn)
+    {
+        $params['appId'] = config::APP_ID;
+        $params['mobile'] = $phone;
+        $params['amount'] = $amount;
+        $params['orderNo'] = $order_sn;
+        $params['notifyUrl'] = config::NOTIFY_URL;
+
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params)
+    {
+        $params = $this->req_params($card_no, $amount, $params['order_sn']);
+        $productNo = $this->getproductNo($amount);
+        if($productNo == 0) {
+            return [false, '商品编号错误', false];
+        }
+        $params['productNo'] = $productNo;
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params , 'POST' , false , config::ExtHeaders);
+        if ($resp === false) {
+            return [false, '系统错误', true];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp ,true);
+            if($resp['code'] == 200) {
+                return [true, $resp['data']['tradeNo'], false];
+            }
+            return [false , $resp['msg'], false];
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['orderNo'] = $refill_info['order_sn'];
+        $params['appId'] = config::APP_ID;
+        $params['sign'] = $this->sign($params);
+
+        $resp = http_request(config::QUERY_URL, $params , 'POST' , false , config::ExtHeaders);
+        if ($resp === false) {
+            return [false, '系统错误'];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+
+            if ($resp['code'] == 200) {
+                $order_state = -1;
+                $data = $resp['data'];
+                if ($data['orderStatus'] == 2) {
+                    $order_state = ORDER_STATE_SUCCESS;
+                    $save['official_sn'] = strtolower($data['carrierOrderNo']) == 'null' ? '' : $data['carrierOrderNo'];
+                    Model('refill_order')->edit($refill_info['order_id'], $save);
+                } elseif ($data['orderStatus'] == 3) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($data['orderStatus'] == 1) {
+                    $order_state = ORDER_STATE_SEND;
+                }
+                if ($order_state == -1) {
+                    return [false, $resp['msg']];
+                }
+                return [true, $order_state];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            if (false === $this->check_empty($val) && "@" != substr($val, 0, 1)) {
+                $content .= "{$key}={$val}&";
+            }
+        }
+        $content .= "key=".config::KEY;
+
+        return md5($content);
+    }
+
+    private function getproductNo(int $amount)
+    {
+        switch ($amount){
+            case 30:
+                return 2110000030101;
+                break;
+            case 50:
+                return 2110000050000;
+                break;
+            case 100:
+                return 21100000100000;
+                break;
+            case 200:
+                return 21100000200101;
+                break;
+            default:
+                return 0;
+        }
+    }
+}

+ 16 - 0
helper/refill/api/lingzh/yibao/config.php

@@ -0,0 +1,16 @@
+<?php
+
+
+namespace refill\yibao;
+
+
+class config
+{
+    const ORDER_URL = 'http://hxx.nvtu.ren/gateway/recharge';
+    const QUERY_URL = 'http://hxx.nvtu.ren/gateway/recharge/order';
+
+    const APP_ID = 'RC6f3bd0202e3e4489876ca876854ef813';
+    const KEY = 'ab2f6127ca8b4fe2b848228c1fceb12c';
+    const NOTIFY_URL = "http://121.89.212.167/racc/callback/lingzh/yibao.php";
+    const ExtHeaders = ['ContentType: application/x-www-form-urlencoded;'];
+}

+ 2 - 3
rdispatcher/dispatcher.php

@@ -57,6 +57,5 @@ function work_proc()
 }
 
 //refill\RefillFactory::instance();
-work_proc();
-
-//event\util::fork_workerex('work_proc',$count);
+//work_proc();
+event\util::fork_workerex('work_proc',$count);

+ 15 - 5
rdispatcher/processor.php

@@ -21,10 +21,9 @@ class processor extends queue\ILooper
         {
             foreach ($msg as $key => $params)
             {
-                Log::record("start one", Log::DEBUG);
                 if (empty($params)) continue;
-
                 $method = strtolower($key);
+                Log::record("processor hanlde method={$method}", Log::DEBUG);
                 try
                 {
                     if ($method == 'add') {
@@ -37,10 +36,21 @@ class processor extends queue\ILooper
                         if(empty($channel) || empty($params))
                             return;
                         $this->mProxy->notify($channel,$input);
-                    } else {
-                        Log::record("Error msg", Log::DEBUG);
                     }
-                } catch (Exception $x) {
+                    elseif($method == 'notify_mechant') {
+                        $order_id = intval($params['order_id']);
+                        $manual = $params['manual'] ?? false;
+                        $this->mProxy->notify_merchant($order_id,$manual);
+                    }
+                    elseif($method == 'query') {
+                        $order_id = intval($params['order_id']);
+                        $this->mProxy->query($order_id);
+                    }
+                    else {
+                        Log::record("Error Method={$method}", Log::DEBUG);
+                    }
+                }
+                catch (Exception $x) {
                     Log::record($x->getMessage(), Log::ERR);
                 }
             }

+ 11 - 2
rdispatcher/proxy.php

@@ -68,7 +68,7 @@ class proxy
 
     private function latest_order($refill_order,$mchid,$mch_order)
     {
-        $orders = $refill_order->getOrderInfo(['mchid' => $mchid,'mch_order' => $mch_order]);
+        $orders = $refill_order->getMerchantOrderList(['mchid' => $mchid,'mch_order' => $mch_order]);
         if(empty($orders)) {
             return [];
         }
@@ -79,6 +79,15 @@ class proxy
 
     public function notify($channel,$input)
     {
-        refill\RefillFactory::instance()->notify($channel,$input);
+        return refill\RefillFactory::instance()->notify($channel,$input);
+    }
+
+    public function notify_merchant($order_id,$manual)
+    {
+        return refill\RefillFactory::instance()->notify_merchant($order_id,$manual);
+    }
+    public function query($order_id)
+    {
+        return refill\RefillFactory::instance()->query($order_id);
     }
 }