stanley-king 4 tahun lalu
induk
melakukan
1fb66e8678

+ 2 - 5
helper/exceptionex.php

@@ -51,12 +51,9 @@ class UnImplementsException extends Exception
 
 class LzException extends Exception
 {
-    public function __construct()
+    public function __construct($content)
     {
-        $code = errcode::ErrSignParamter;
-        $message = errcode::msg($code);
-
-        parent::__construct($message, $code, null);
+        parent::__construct($content, 0, null);
     }
 
 }

+ 5 - 3
helper/fcgisrv/LZRAccServer.php

@@ -18,8 +18,10 @@ use UnSignException;
 use Exception;
 use merchantControl;
 use errcode;
+use LzException;
 
-class RAccServer extends BaseServer
+
+class LZRAccServer extends BaseServer
 {
     public function __construct($subPath)
     {
@@ -60,8 +62,8 @@ class RAccServer extends BaseServer
                 echo "no such file.";
             }
         }
-        catch (UnSignException $ex) {
-            merchantControl::outerr(errcode::ErrUnLogin,errcode::msg(errcode::ErrUnLogin));
+        catch (LzException $ex) {
+            echo ($ex->getMessage());
         }
         catch (Exception $ex) {
             merchantControl::outerr($ex->getCode(),$ex->getMessage());

+ 1 - 1
helper/fcgisrv/RAccServer.php

@@ -26,7 +26,7 @@ class RAccServer extends BaseServer
         parent::__construct($subPath);
 
         $exfiles = [
-            'callback/baizeyd.php','callback/am.php','callback/bhc.php',
+            'callback/lingzh/baizeyd.php','callback/lingzh/am.php','callback/lingzh/bhc.php',
         ];
 
         $this->setExFiles($exfiles);

helper/refill/api/test/aming/RefillCallBack.php → helper/refill/api/lingzh/aming/RefillCallBack.php


helper/refill/api/test/aming/RefillPhone.php → helper/refill/api/lingzh/aming/RefillPhone.php


helper/refill/api/test/aming/config.php → helper/refill/api/lingzh/aming/config.php


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

@@ -0,0 +1,13 @@
+<?php
+
+require_once(BASE_HELPER_RAPI_PATH . '/baizeyd/RefillPhone.php');
+require_once(BASE_HELPER_RAPI_PATH . '/baizeyd/RefillCallBack.php');
+
+require_once(BASE_HELPER_RAPI_PATH . '/aming/RefillPhone.php');
+require_once(BASE_HELPER_RAPI_PATH . '/aming/RefillCallBack.php');
+
+require_once(BASE_HELPER_RAPI_PATH . '/binghc/RefillPhone.php');
+require_once(BASE_HELPER_RAPI_PATH . '/binghc/RefillCallBack.php');
+
+require_once(BASE_HELPER_RAPI_PATH . '/weisyd/RefillPhone.php');
+require_once(BASE_HELPER_RAPI_PATH . '/weisyd/RefillCallBack.php');

helper/refill/api/test/baizeyd/RefillCallBack.php → helper/refill/api/lingzh/baizeyd/RefillCallBack.php


helper/refill/api/test/baizeyd/RefillPhone.php → helper/refill/api/lingzh/baizeyd/RefillPhone.php


helper/refill/api/test/baizeyd/config.php → helper/refill/api/lingzh/baizeyd/config.php


helper/refill/api/test/binghc/RefillCallBack.php → helper/refill/api/lingzh/binghc/RefillCallBack.php


helper/refill/api/test/binghc/RefillPhone.php → helper/refill/api/lingzh/binghc/RefillPhone.php


helper/refill/api/test/binghc/config.php → helper/refill/api/lingzh/binghc/config.php


helper/refill/api/test/legou/RefillCallBack.php → helper/refill/api/lingzh/legou/RefillCallBack.php


helper/refill/api/test/legou/RefillPhone.php → helper/refill/api/lingzh/legou/RefillPhone.php


helper/refill/api/test/legou/config.php → helper/refill/api/lingzh/legou/config.php


helper/refill/api/test/weisyd/RefillCallBack.php → helper/refill/api/lingzh/weisyd/RefillCallBack.php


helper/refill/api/test/weisyd/RefillPhone.php → helper/refill/api/lingzh/weisyd/RefillPhone.php


helper/refill/api/test/weisyd/config.php → helper/refill/api/lingzh/weisyd/config.php


+ 1 - 13
helper/refill/api/test/api.php

@@ -1,16 +1,4 @@
 <?php
 
 require_once(BASE_HELPER_RAPI_PATH . '/baidu/RefillPhone.php');
-require_once(BASE_HELPER_RAPI_PATH . '/baidu/RefillCallBack.php');
-
-require_once(BASE_HELPER_RAPI_PATH . '/baizeyd/RefillPhone.php');
-require_once(BASE_HELPER_RAPI_PATH . '/baizeyd/RefillCallBack.php');
-
-require_once(BASE_HELPER_RAPI_PATH . '/aming/RefillPhone.php');
-require_once(BASE_HELPER_RAPI_PATH . '/aming/RefillCallBack.php');
-
-require_once(BASE_HELPER_RAPI_PATH . '/binghc/RefillPhone.php');
-require_once(BASE_HELPER_RAPI_PATH . '/binghc/RefillCallBack.php');
-
-require_once(BASE_HELPER_RAPI_PATH . '/weisyd/RefillPhone.php');
-require_once(BASE_HELPER_RAPI_PATH . '/weisyd/RefillCallBack.php');
+require_once(BASE_HELPER_RAPI_PATH . '/baidu/RefillCallBack.php');

+ 1 - 0
helper/refill/api/xyz/bjbyd/RefillPhone.php

@@ -19,6 +19,7 @@ class RefillPhone extends refill\IRefillPhone
         $params['mob'] = $phone;
         $params['amt'] = $amount;
         $params['ord'] = $order_sn;
+        
         $params['tim'] = date("YmdHis");
         $params['yysid'] = 0;
         $params['hmlx'] = 0;

+ 10 - 0
helper/refill/policy/lingzh/speed.php

@@ -0,0 +1,10 @@
+<?php
+
+
+namespace refill;
+
+
+class speed
+{
+
+}

+ 1 - 0
helper/refill/policy/lingzh/speed_item.php

@@ -0,0 +1 @@
+<?php

+ 6 - 6
racc/callback/aming.php

@@ -1,6 +1,6 @@
-<?php
-require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
-
-refill\RefillFactory::instance()->notify('am',$_POST);
-
-echo ('success');
+<?php
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
+
+refill\RefillFactory::instance()->notify('am',$_POST);
+
+echo ('success');

+ 6 - 6
racc/callback/baizeyd.php

@@ -1,6 +1,6 @@
-<?php
-require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
-
-refill\RefillFactory::instance()->notify('baizeyd',$_POST);
-
-echo ('success');
+<?php
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
+
+refill\RefillFactory::instance()->notify('baizeyd',$_POST);
+
+echo ('success');

+ 6 - 6
racc/callback/binghc.php

@@ -1,6 +1,6 @@
-<?php
-require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
-
-refill\RefillFactory::instance()->notify('bhc',$_POST);
-
-echo ('success');
+<?php
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
+
+refill\RefillFactory::instance()->notify('bhc',$_POST);
+
+echo ('success');

+ 58 - 72
racc/control/lzbase.php

@@ -5,19 +5,24 @@ class lzbaseControl
     private $mMchid;
     private $mAdminid;
     private $mUseKey;
+    protected $available;
+
     public function __construct()
     {
         $mchid = $_POST['usr'];
         $mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $mchid]);
         if(empty($mchinfo)) {
-            throw new Exception("合作方ID:{$mchid}不存在");
+            throw new LzException(self::text_content(-5,0));
         }
         else {
             $this->mAdminid = intval($mchinfo['admin_id']);
         }
 
+        $minfo = new member_info($this->adminid());
+        $this->available = $minfo->available_predeposit();
+
         if ($mchinfo['merchant_state'] != 1) {
-            throw new LzException("机构已被关闭。");
+            throw new LzException(self::text_content(-7,$this->available));
         }
 
         $ips = unserialize($mchinfo['ip_white_list']);
@@ -26,13 +31,13 @@ class lzbaseControl
             Log::record("request ip:{$addr}",Log::DEBUG);
 
             if(!in_array($addr,$ips)) {
-                throw new Exception("请求地址不在白名单中");
+                throw new LzException(self::text_content(-12,$this->available));
             }
         }
 
         $this->mUseKey = intval($mchinfo['use_key']);
         if($this->mUseKey && !$this->verify_md5($mchinfo['secure_key'])) {
-            throw new UnSignException();
+            throw new LzException(self::text_content(-4,$this->available));
         }
 
         $this->mMchid = intval($mchid);
@@ -46,99 +51,80 @@ class lzbaseControl
         return $this->mAdminid;
     }
 
-    private function pubKey($mchid)
-    {
-        static $pubs = [];
-
-        if(array_key_exists($mchid,$pubs)) {
-            return $pubs[$mchid];
-        }
-        else {
-            $pub_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pub.pem";
-            $key = file_get_contents($pub_key);
-            $pub = openssl_get_publickey($key);
-            $pubs[$mchid] = $pub;
-            return $pub;
-        }
-    }
 
     private function verify_md5($key)
     {
         $input = $_GET;
-        $sign = $input['sign'];
-
-        $input['sign'] = null;
-        $input['from'] = null;
+        $sign = $input['sgn'];
 
         $body = $this->sign_body($input);
-
         if($this->mUseKey) {
-            $body .= "&key={$key}";
+            $body .= $key;
         }
 
-        return ($sign == md5($body));
+        return ($sign == strtoupper(md5($body)));
     }
 
-    private function verify_rsa($mchid)
+    private function sign_body($params)
     {
-        $pub = $this->pubKey($mchid);
-        if(empty($pub)) {
-            return false;
-        }
-        $input = $_GET;
-        $sign = $input['sign'];
-        $input['sign'] = null;
-        $input['from'] = null;
-
-        $data = $this->sign_body($input);
-        $res = openssl_verify($data,base64_decode($sign),$pub);
-        Log::record("openssl_verify res={$res}",Log::DEBUG);
-
-        return ($res == 1);
+        $content = $params['usr'] . $params['ord'] . $params['mob'] . $params['amt'] . $params['tim'];
+        return $content;
     }
 
-    protected function check_empty($value)
+    public static function msg($code)
     {
-        if (!isset($value))
-            return true;
-        if ($value === null)
-            return true;
-        if (trim($value) === "")
-            return true;
-
-        return false;
+        static $msgs = [0 => '订单提交成功',
+            2 => '运营商充值账户余额不足',
+            4 => '账户余额不足',
+            6 => '暂不支持此商品',
+            7 => '连接该运营商设备失败',
+            8 => '在规定时间内不得重复提交同一号码',
+            10 => '该帐号不能在此计算机缴费',
+            11 => '流水号重复',
+            30 => '面值不符',
+            41 => '该地区维护',
+            42 => '运营商设备忙',
+            43 => '暂不支持该面额的缴费',
+            44 => '无该地区缴费权限',
+            -2 => '命令已发送,请查看交易流水是否有缴费成功(这种情况是服务器在排队等待处理,间隔10-20分钟后查单核实)',
+            -3 => '数据添加失败',
+            -4 => '签名错误',
+            -5 => '没有此代理商',
+            -6 => '提交失败',
+            -7 => '无此接口权限',
+            -8 => '提交日期不是当天日期',
+            -9 => '参数不对',
+            -11 => '手机号码位数不符',
+            -12 => '绑定IP不符',
+            1001 => '销售数量请大于0',
+            1002 => '该商品库存维护',
+            1003 => '该供货商品库存维护'];
+
+        if(array_key_exists($code,$msgs)) {
+            return $msgs[$code];
+        }
+        else {
+            return '';
+        }
     }
 
-    private function sign_body($params)
+    public static function text_content($code,$available)
     {
-        ksort($params);
-
-        $content = "";
-        $i = 0;
-        foreach ($params as $k => $v)
-        {
-            if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
-            {
-                if ($i == 0) {
-                    $content .= "{$k}" . "=" . urlencode($v);
-                } else {
-                    $content .= "&" . "{$k}" . "=" . urlencode($v);
-                }
-                $i++;
-            }
-        }
-
+        $msg = self::msg($code);
+        $available = ncPriceFormat($available);
+        $content = "0|{$msg}|{$available}";
         return $content;
     }
 
-    public static function outsuccess($data)
+    public static function outsuccess($available)
     {
-        joutput_data($data);
+        echo self::text_content(0,$available);
         return true;
     }
-    public static function outerr($code, $msg = '')
+
+    public static function outerr($code,$available)
     {
-        joutput_error($code, $msg);
+        echo self::text_content($code,$available);
         return true;
     }
 }

+ 172 - 0
racc/control/lzrefill.php

@@ -0,0 +1,172 @@
+<?php
+
+class lzrefillControl extends lzbaseControl
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    public function goodsOp()
+    {
+        $result = refill\RefillFactory::instance()->goods();
+        $sorter = function (array $items) {
+            $ret = [];
+            foreach ($items as $key => $val) {
+                sort($val);
+                $ret[$key] = $val;
+            }
+            return $ret;
+        };
+
+        $result = $sorter($result);
+        return self::outsuccess($result);
+    }
+
+    private function check_params($params)
+    {
+        if(empty($params['mob'])) {
+            return -9;
+        }
+        if(empty($params['amt'])) {
+            return -9;
+        }
+
+        $card_no = $_GET['cardno'];
+        if(!preg_match('/^1\d{10}$/',$card_no,$matches)) {
+            return -11;
+        }
+
+        if(empty($params['notifyurl'])) {
+            return -9;
+        }
+
+        if(empty($params['ord'])) {
+            return -9;
+        }
+
+        //todo 增加时间判断
+
+        return true;
+    }
+
+    public function add_mobOp()
+    {
+        $code = $this->check_params($_GET);
+        if($code !== true) {
+            return self::outerr($code,$this->available);
+        }
+
+        $amount = intval($_GET['amt']);
+        $card_no = $_GET['mob'];
+        $notify_url = $_GET['notifyurl'];
+        $mch_order = $_GET['ord']; //对方的order编号
+
+        if($amount > $this->available) {
+            return self::outerr(4,$this->available);
+        }
+
+        if(!$this->check_mchorder($this->mchid(),$mch_order)) {
+            return self::outerr(11,$this->available);
+        }
+
+        if(!$this->can_refill($card_no)) {
+            return self::outerr(10,$this->available);
+        }
+
+        $params = [ 'mchid' => $this->mchid(),
+            'buyer_id' => $this->adminid(),
+            'amount' => $amount,
+            'card_no' => $card_no,
+            'mch_order' => $mch_order,
+            'notify_url' => $notify_url];
+        $ret = refill\util::push_add($params);
+
+        if($ret) {
+            return self::outsuccess($this->available);
+        }
+        else {
+            return self::outerr(-6,$this->available);
+        }
+    }
+
+    private function can_refill($cardno)
+    {
+        $card_info = refill\util::read_card($cardno);
+        if(empty($card_info)) return false;
+
+        return intval($card_info['black_card']) === 0;
+    }
+
+    private function check_mchorder($mchid,$mch_order)
+    {
+        if(empty($mch_order)) {
+            return false;
+        }
+        else {
+            $refill_order = Model('refill_order');
+            $ret = $refill_order->getOrderInfo(['mchid' => $mchid,'mch_order' => $mch_order]);
+
+            return empty($ret);
+        }
+    }
+
+    public function balanceOp()
+    {
+        $uid = $this->adminid();
+        $minfo = new member_info($uid);
+        $available = $minfo->available_predeposit();
+        return self::outsuccess(['balance' => $available]);
+    }
+
+    private function format($order_info,$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;
+    }
+
+    public function queryOp()
+    {
+        $mchid = $this->mchid();
+        $order_sn = $_GET['ord']; //用户方的订单号,对应数据库中的mch_order
+
+        if(empty($order_sn)) {
+            return self::outerr(201,);
+        }
+
+        $mod_refill = Model('refill_order');
+        $refill_info = $mod_refill->getOrderInfo(['mch_order' => $order_sn,'mchid' => $mchid,'inner_status' => 0]);
+
+        if(empty($refill_info)) {
+            return self::outerr(201,"无此订单");
+        }
+
+        $vr_order = Model('vr_order');
+        $order_info = $vr_order->getOrderInfo(['order_sn' => $refill_info['order_sn']]);
+
+        if(empty($order_info)) {
+            return self::outerr(201,"无此交易号");
+        }
+
+        if($order_info['order_state'] == ORDER_STATE_SEND) {
+            QueueClient::push("QueryRefillState",['order_id' => $refill_info['order_id']]);
+        }
+
+        $result = $this->format($order_info,$refill_info);
+
+        return self::outsuccess($result);
+    }
+
+}