stanley-king před 1 rokem
rodič
revize
7bc42b93b3

+ 33 - 66
data/config/dev/base.ini.php

@@ -54,85 +54,52 @@ define('SSH_TUNEL_PROD','local');
 
 if(SSH_TUNEL_PROD ==='local') {
     $config['db'][1]['dbhost']       = MASTER_DBHOST;
-    $config['db'][1]['dbport']       = '3307';
-    $config['db'][1]['dbuser']       = 'root';
-    $config['db'][1]['dbpwd']        = '55668899';
-    $config['db'][1]['dbname']       = 'xyzshop';
-    $config['db'][1]['dbcharset']    = 'UTF-8';
-
-    $config['db']['slave'][0]['dbhost']     = SLAVE_DBHOST;
-    $config['db']['slave'][0]['dbport']     = '3307';
-    $config['db']['slave'][0]['dbuser']     = 'root';
-    $config['db']['slave'][0]['dbpwd']      = '55668899';
-    $config['db']['slave'][0]['dbname']     = 'xyzshop';
-    $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
-}
-if(SSH_TUNEL_PROD ==='workcuda') {
-    $config['db'][1]['dbhost']       = MASTER_DBHOST;
     $config['db'][1]['dbport']       = '3306';
     $config['db'][1]['dbuser']       = 'root';
     $config['db'][1]['dbpwd']        = '55668899';
-    $config['db'][1]['dbname']       = 'ylshop';
+    $config['db'][1]['dbname']       = 'xyzshop';
     $config['db'][1]['dbcharset']    = 'UTF-8';
 
     $config['db']['slave'][0]['dbhost']     = SLAVE_DBHOST;
     $config['db']['slave'][0]['dbport']     = '3306';
     $config['db']['slave'][0]['dbuser']     = 'root';
     $config['db']['slave'][0]['dbpwd']      = '55668899';
-    $config['db']['slave'][0]['dbname']     = 'ylshop';
-    $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
-}
-elseif(SSH_TUNEL_PROD === 'xyz') {
-    //调试是先执行这行命令
-    //shell_exec("ssh -NCPf root@39.103.201.41 -L 3307:127.0.0.1:3306");
-    $config['db'][1]['dbhost']       = MASTER_DBHOST;
-    $config['db'][1]['dbport']       = '3307';
-    $config['db'][1]['dbuser']       = 'root';
-    $config['db'][1]['dbpwd']        = 'XTZ@shop@951688';
-    $config['db'][1]['dbname']       = 'xyzshop';
-    $config['db'][1]['dbcharset']    = 'UTF-8';
-
-    $config['db']['slave'][0]['dbhost']     = SLAVE_DBHOST;
-    $config['db']['slave'][0]['dbport']     = '3307';
-    $config['db']['slave'][0]['dbuser']     = 'root';
-    $config['db']['slave'][0]['dbpwd']      = 'XTZ@shop@951688';
-    $config['db']['slave'][0]['dbname']     = 'xyzshop';
-    $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
-}
-elseif(SSH_TUNEL_PROD === 'xyztest') {
-    //调试是先执行这行命令
-    //shell_exec("ssh -NCPf root@39.103.162.175 -L 3307:127.0.0.1:3306");
-    $config['db'][1]['dbhost']       = MASTER_DBHOST;
-    $config['db'][1]['dbport']       = '3307';
-    $config['db'][1]['dbuser']       = 'root';
-    $config['db'][1]['dbpwd']        = 'XTZ@shop@951688';
-    $config['db'][1]['dbname']       = 'xyzshop';
-    $config['db'][1]['dbcharset']    = 'UTF-8';
-
-    $config['db']['slave'][0]['dbhost']     = SLAVE_DBHOST;
-    $config['db']['slave'][0]['dbport']     = '3307';
-    $config['db']['slave'][0]['dbuser']     = 'root';
-    $config['db']['slave'][0]['dbpwd']      = 'XTZ@shop@951688';
     $config['db']['slave'][0]['dbname']     = 'xyzshop';
     $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
 }
-elseif(SSH_TUNEL_PROD === 'lingzh') {
-    //调试是先执行这行命令
-    //shell_exec("ssh -NCPf root@121.89.212.167 -L 3307:127.0.0.1:3306");
-    $config['db'][1]['dbhost']       = MASTER_DBHOST;
-    $config['db'][1]['dbport']       = '3307';
-    $config['db'][1]['dbuser']       = 'root';
-    $config['db'][1]['dbpwd']        = 'Linzhuhmnbmhhah#2021';
-    $config['db'][1]['dbname']       = 'xyzshop';
-    $config['db'][1]['dbcharset']    = 'UTF-8';
 
-    $config['db']['slave'][0]['dbhost']     = SLAVE_DBHOST;
-    $config['db']['slave'][0]['dbport']     = '3307';
-    $config['db']['slave'][0]['dbuser']     = 'root';
-    $config['db']['slave'][0]['dbpwd']      = 'Linzhuhmnbmhhah#2021';
-    $config['db']['slave'][0]['dbname']     = 'xyzshop';
-    $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
-}
+//if(SSH_TUNEL_PROD ==='workcuda') {
+//    $config['db'][1]['dbhost']       = MASTER_DBHOST;
+//    $config['db'][1]['dbport']       = '3306';
+//    $config['db'][1]['dbuser']       = 'root';
+//    $config['db'][1]['dbpwd']        = '55668899';
+//    $config['db'][1]['dbname']       = 'ylshop';
+//    $config['db'][1]['dbcharset']    = 'UTF-8';
+//
+//    $config['db']['slave'][0]['dbhost']     = SLAVE_DBHOST;
+//    $config['db']['slave'][0]['dbport']     = '3306';
+//    $config['db']['slave'][0]['dbuser']     = 'root';
+//    $config['db']['slave'][0]['dbpwd']      = '55668899';
+//    $config['db']['slave'][0]['dbname']     = 'ylshop';
+//    $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
+//}
+//elseif(SSH_TUNEL_PROD === 'xyz') {
+//    //调试是先执行这行命令
+//    //shell_exec("ssh -NCPf root@39.103.201.41 -L 3307:127.0.0.1:3306");
+//    $config['db'][1]['dbhost']       = MASTER_DBHOST;
+//    $config['db'][1]['dbport']       = '3307';
+//    $config['db'][1]['dbuser']       = 'root';
+//    $config['db'][1]['dbpwd']        = 'XTZ@shop@951688';
+//    $config['db'][1]['dbname']       = 'xyzshop';
+//    $config['db'][1]['dbcharset']    = 'UTF-8';
+//
+//    $config['db']['slave'][0]['dbhost']     = SLAVE_DBHOST;
+//    $config['db']['slave'][0]['dbport']     = '3307';
+//    $config['db']['slave'][0]['dbuser']     = 'root';
+//    $config['db']['slave'][0]['dbpwd']      = 'XTZ@shop@951688';
+//    $config['db']['slave'][0]['dbname']     = 'xyzshop';
+//    $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
+//}
 
 $config['session_expire'] 	= 3600;
 $config['lang_type'] 		= 'zh_cn';

+ 11 - 12
helper/rbridge/BridgeTrait.php

@@ -15,16 +15,12 @@ trait BridgeTrait
 {
     public function order_query($mchid,$mch_order)
     {
-        if(empty($order_sn)) {
-            return [201,"客户订单号{$mch_order}不能为空."];
-        }
-
         $order_state = refill\util::query_queue_order($mchid,$mch_order);
         if ($order_state == ORDER_STATE_QUEUE || $order_state == ORDER_STATE_SEND) {
             Log::record("query_state in queue mchid=$mchid mch_order=$mch_order order_state=$order_state", Log::DEBUG);
             $result['mchid'] = $mchid;
-            $result['order_sn'] = $order_sn;
-            $result['order_state'] = $order_state;
+            $result['order_sn'] = $mch_order;
+            $result['order_state'] = ORDER_STATE_SEND;
             return [200,$result];
         }
         else
@@ -45,7 +41,7 @@ trait BridgeTrait
                     $insert['msg'] = "检索充值中的单子,查不到任何订单信息.";
                     $mod_qerr->add($insert);
 
-                    return [202, ''];
+                    return [201, []];
                 } else {
                     Log::record("DEBUG_TAG: query_state in db mchid=$mchid mch_order=$mch_order order_state not completed.", Log::DEBUG);
 
@@ -55,7 +51,7 @@ trait BridgeTrait
                     $mod_qerr->add($insert);
 
                     $result['mchid'] = $mchid;
-                    $result['order_sn'] = $order_sn;
+                    $result['order_sn'] = $mch_order;
                     $result['order_state'] = ORDER_STATE_SEND;
 
                     return [200, $result];
@@ -65,18 +61,21 @@ trait BridgeTrait
             {
                 $vr_order = Model('vr_order');
                 $order_info = $vr_order->partition(refill\util::part_query())->getOrderInfo(['order_sn' => $refill_info['order_sn']]);
-                Log::record("query_state in db mchid=$mchid mch_order=$order_sn order_state={$order_info['order_state']}" ,Log::DEBUG);
+                Log::record("query_state in db mchid=$mchid mch_order=$mch_order order_state={$order_info['order_state']}" ,Log::DEBUG);
 
                 if (empty($order_info))
                 {
                     $mod_qerr = Model('refill_query_err');
-                    $insert = ['mch_order' => $order_sn,'mchid' => $mchid];
-
+                    $insert = ['mch_order' => $mch_order,'mchid' => $mchid];
                     $insert['code'] = 203;
                     $insert['msg'] = "检索充值中的单子能查到,但inner_status=0时查不到vr_order中的订单.";
                     $mod_qerr->add($insert);
 
-                    return [203, []];
+                    $result['mchid'] = $mchid;
+                    $result['order_sn'] = $mch_order;
+                    $result['order_state'] = ORDER_STATE_SEND;
+
+                    return [200, $result];
                 } else {
                     $result = $this->format($order_info, $refill_info);
                     return [200, $result];

+ 26 - 1
helper/rbridge/RBridgeFactory.php

@@ -3,12 +3,16 @@
 namespace rbridge;
 
 require_once(BASE_HELPER_PATH . '/refill_proxy.php');
+
 require_once(BASE_HELPER_PATH . '/rbridge/IBridge.php');
+require_once(BASE_HELPER_PATH . '/rbridge/IBridgeEx.php');
+require_once(BASE_HELPER_PATH . '/rbridge/BridgeTrait.php');
 require_once(BASE_HELPER_PATH . '/rbridge/wsd/Bridge.php');
 require_once(BASE_HELPER_PATH . '/rbridge/fulu/Bridge.php');
 require_once(BASE_HELPER_PATH . '/rbridge/fulu_ylyw/Bridge.php');
 require_once(BASE_HELPER_PATH . '/rbridge/fulu_youjun/Bridge.php');
 require_once(BASE_HELPER_PATH . '/rbridge/fulu_qdw/Bridge.php');
+require_once(BASE_HELPER_PATH . '/rbridge/gy/Bridge.php');
 
 use Exception;
 use Log;
@@ -51,7 +55,6 @@ class RBridgeFactory
         }
 
         $ret = $bridge->notify($parmas);
-
         if($ret) {
             return "SUCCESS";
         }
@@ -60,6 +63,28 @@ class RBridgeFactory
         }
     }
 
+    public function query($mch_name,$parmas)
+    {
+        $bridge = $this->find($mch_name);
+        if(is_null($bridge)) {
+            return false;
+        }
+
+        $ret = $bridge->query($parmas);
+        return $ret;
+    }
+
+    public function balance($mch_name,$parmas)
+    {
+        $bridge = $this->find($mch_name);
+        if(is_null($bridge)) {
+            return false;
+        }
+
+        $ret = $bridge->balance($parmas);
+        return $ret;
+    }
+
     private function find($name)
     {
         try

+ 172 - 85
helper/rbridge/gy/Bridge.php

@@ -4,32 +4,40 @@ namespace rbridge\gy;
 
 require_once(BASE_HELPER_PATH . '/rbridge/gy/config.php');
 
-use rbridge\BridgeTrait;
 use rbridge\IBridge;
 use rbridge\IBridgeEx;
+use rbridge\BridgeTrait;
 use refill;
 use Log;
-use StatesHelper;
+use SimpleXMLElement;
+use member_info;
 
 class Bridge implements IBridge, IBridgeEx
 {
     use BridgeTrait;
+
     public function add($params)
     {
+        $input_names = ['userid', 'request_id', 'telephone', 'money', 'callbackurl'];
+        $out_names = ['order_id', 'request_id', 'telephone', 'money', 'result'];
+
         $mchid = config::mchid($params);
-        if($mchid === false) {
-            return [false, "机构不存在"];
+        if ($mchid === false) {
+            $params['result'] = 4; //请求参数不完整或不合法
+            return [false, $this->result_format($params, $out_names, '')];
         }
 
         $mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $mchid]);
-        if(empty($mchinfo)) {
-            return [false, "机构{$mchid}不存在"];
+        if (empty($mchinfo)) {
+            $params['result'] = 6; //代理商不存在
+            return [false, $this->result_format($params, $out_names, '')];
         }
 
-        $names = ['userid','request_id','telephone','money','callbackurl'];
-        [$succ, $errmsg] = $this->check($mchinfo, $params, $names);
-        if(!$succ) {
-            return [$succ,$errmsg];
+        $secure_key = $mchinfo['secure_key'];
+        [$succ, $result] = $this->check($mchinfo, $params, $input_names);
+        if (!$succ) {
+            $params['result'] = $result;
+            return [false, $this->result_format($params, $out_names, $secure_key)];
         }
 
         Model('merchant_query')->add_info($mchid, $params['request_id'], json_encode($params));
@@ -37,7 +45,7 @@ class Bridge implements IBridge, IBridgeEx
         $order_time = time();
         $mch_order = $params['request_id'];
         $card_no = $params['telephone'];
-        $input = [ 'mchid' => $mchid,
+        $input = ['mchid' => $mchid,
             'buyer_id' => intval($mchinfo['admin_id']),
             'amount' => $params['money'],
             'card_no' => $card_no,
@@ -46,25 +54,58 @@ class Bridge implements IBridge, IBridgeEx
             'order_time' => $order_time
         ];
 
-        refill\util::push_queue_order($mchid,$mch_order,ORDER_STATE_QUEUE);
-        Model('refill_order')->add_detail($mchid,$mch_order,$order_time,$params,ORDER_STATE_QUEUE);
+        refill\util::push_queue_order($mchid, $mch_order, ORDER_STATE_QUEUE);
+        $detail_id = Model('refill_order')->add_detail($mchid, $mch_order, $order_time, $params, ORDER_STATE_QUEUE);
 
         $state = refill\util::push_add($input);
         if ($state === true) {
-            Log::record("gy::Bridge refill::util::push_add success mchid={$mchid} mch_order={$mch_order} state={$state}",Log::DEBUG);
-            return [true, '提交成功'];
+            Log::record("gy::Bridge refill::util::push_add success mchid=$mchid mch_order=$mch_order state=true", Log::DEBUG);
+            $params['order_id'] = $detail_id;
+            $params['result'] = 2; //提交成功,正在充值(适用于异步接口)
+            return [true, $this->result_format($params, $out_names, $secure_key)];
         } else {
-            refill\util::del_queue_order($mchid,$mch_order);
-            Model('refill_order')->del_detail($mchid,$mch_order);
-            Log::record("gy::Bridge refill::util::push_add error mchid={$mchid} mch_order={$mch_order} state={$state}",Log::DEBUG);
-            return [false, '提交失败'];
+            refill\util::del_queue_order($mchid, $mch_order);
+            Model('refill_order')->del_detail($mchid, $mch_order);
+            Log::record("gy::Bridge refill::util::push_add error mchid=$mchid mch_order=$mch_order state=$state", Log::DEBUG);
+
+            $params['result'] = 12; //未知错误
+            return [true, $this->result_format($params, $out_names, $secure_key)];
         }
     }
 
+    private function result_format($input, $names, $secure_key)
+    {
+        $result = $this->sign($input, $names, $secure_key);
+        $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><root></root>');
+        config::arrayToXml($xml,$result);
+
+        return $xml->asXML();
+    }
+
+
+    private function sign($input, $names, $secure_key)
+    {
+        $result = [];
+
+        $body = '';
+        foreach ($names as $name) {
+            $val = $input[$name] ?? '';
+            $body .= $val;
+
+            $result[$name] = $val;
+        }
+        $body .= $secure_key;
+
+        $sign = strtoupper(md5($body));
+        $result['sign'] = $sign;
+        return $result;
+    }
+
+
     private function check($mchinfo, $input, $names): array
     {
         if ($mchinfo['merchant_state'] != 1) {
-            return [false,"机构已被关闭."];
+            return [false, 6]; //代理商不存在
         }
 
         $ips = unserialize($mchinfo['ip_white_list']);
@@ -73,30 +114,25 @@ class Bridge implements IBridge, IBridgeEx
             $addr = $_SERVER['REMOTE_ADDR'];
             if(!in_array($addr,$ips)) {
                 Log::record("request ip:$addr", Log::DEBUG);
-                return [false,"请求地址不在白名单中."];
+                return [false, 12]; //未知错误
             }
         }
 
         $usekey = intval($mchinfo['use_key']);
         $key = $mchinfo['secure_key'];
 
-        if($usekey)
-        {
+        if ($usekey) {
             $ret = $this->verify($input, $names, $key);
-            if(!$ret) {
-                return [false,'签名认证失败.'];
+            if (!$ret) {
+                return [false, 5]; //签名错误
             }
         }
 
-        return [true,''];
+        return [true, ''];
     }
 
     private function verify($params, $names, $key)
     {
-        $orgSign = $params['sign'];
-        unset($params['sign']);
-        ksort($params);
-
         $body = '';
         foreach ($names as $name) {
             $val = $params[$name] ?? '';
@@ -105,93 +141,144 @@ class Bridge implements IBridge, IBridgeEx
         $body .= $key;
 
         $sign = strtoupper(md5($body));
-        return $orgSign == $sign;
+        return $params['sign'] == $sign;
     }
 
     public function query($params)
     {
+        $input_names = ['userid', 'request_id'];
+        $out_names = ['order_id', 'request_id', 'telephone', 'money', 'result'];
+
         $mchid = config::mchid($params);
-        if($mchid === false) {
-            return [false, "机构不存在"];
+        $mch_order = $params['request_id'];
+
+        if ($mchid === false or empty($mch_order)) {
+            $params['result'] = 4; //请求参数不完整或不合法
+            return [false, $this->result_format($params, $out_names, '')];
         }
 
         $mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $mchid]);
-        if(empty($mchinfo)) {
-            return [false, "机构{$mchid}不存在"];
+        if (empty($mchinfo)) {
+            $params['result'] = 6; //代理商不存在
+            return [false, $this->result_format($params, $out_names, '')];
         }
 
-        $names = ['userid','request_id'];
-        [$succ, $errmsg] = $this->check($mchinfo, $params, $names);
+        $secure_key = $mchinfo['secure_key'];
+        [$succ, $result] = $this->check($mchinfo, $params, $input_names);
         if(!$succ) {
-            return [$succ,$errmsg];
+            $params['result'] = $result;
+            return [$succ, $this->result_format($params, $out_names, $secure_key)];
         }
 
-        $mch_order = $params['request_id'];
-        [$code,$result] = $this->order_query($mchid,$mch_order);
+        [$detail_id,$info] = $this->detail($mchid, $mch_order);
+        [$code, $order] = $this->order_query($mchid, $mch_order);
+
+        if ($code == 200) {
+            $info['order_id'] = $detail_id;
+            $order_state = $order['order_state'];
+        } else {
+            $order_state = ORDER_STATE_NOEXIST;
+        }
+
+        if(in_array($order_state,[ORDER_STATE_QUEUE,ORDER_STATE_NEW,ORDER_STATE_PAY,ORDER_STATE_SEND])) {
+            $info['result'] = 2;
+        }
+        elseif($order_state == ORDER_STATE_SUCCESS) {
+            $info['result'] = 0;
+        }
+        elseif($order_state == ORDER_STATE_CANCEL) {
+            $info['result'] = 1;
+        }
+        else {
+            $info['result'] = 3;
+        }
+
+        return [true, $this->result_format($info, $out_names, $secure_key)];
+    }
+
+    private function detail($mchid, $mch_order)
+    {
+        $mod_refill = Model('refill_order');
+        $detail = $mod_refill->get_detail($mchid,$mch_order);
+        if(empty($detail)) {
+            return [false, []];
+        }
+        else {
+            return [intval($detail['detail_id']), json_decode($detail['params'], true)];
+        }
     }
 
     public function balance($params)
     {
+        $input_names = ['userid'];
+        $out_names = ['userid', 'money'];
+
+        $mchid = config::mchid($params);
+
+        if ($mchid === false) {
+            $params['result'] = 4; //请求参数不完整或不合法
+            return [false, $this->result_format($params, $out_names, '')];
+        }
+
+        $mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $mchid]);
+        if (empty($mchinfo)) {
+            $params['result'] = 6; //代理商不存在
+            return [false, $this->result_format($params, $out_names, '')];
+        }
+
+        $secure_key = $mchinfo['secure_key'];
+        [$succ, $result] = $this->check($mchinfo, $params, $input_names);
+        if(!$succ) {
+            $params['result'] = $result;
+            return [$succ, $this->result_format($params, $out_names, $secure_key)];
+        }
+
+        $uid = intval($mchinfo['admin_id']);
+        $minfo = new member_info($uid);
+        $available = $minfo->available_predeposit();
+        $money = ncPriceFormat($available - $mchinfo['credit_bonus']);
+        $params['money'] = $money;
+
+        return [false, $this->result_format($params, $out_names, $secure_key)];
     }
 
 
     public function notify($params)
     {
+        $out_names = ['order_id', 'request_id', 'telephone', 'money', 'result'];
+
         $mchid = $params['mchid'];
-        $mch_ordersn = $params['order_sn'];
-        $body = $this->notify_body($params);
-
-        $userID = config::USER_ID;
-        $header = [
-            'Content-Type: application/json',
-            "OrderNo: {$mch_ordersn}",
-            "UserID: {$userID}",
-        ];
+        $mch_order = $params['order_sn'];
+        [$detail_id,$input] = $this->detail($mchid, $mch_order);
+
+
+        $mchid = $params['mchid'];
+        $mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $mchid]);
+        $secure_key = $mchinfo['secure_key'];
 
-        $body = json_encode($body, JSON_UNESCAPED_UNICODE);
-        $body = $this->aes_encrypt($body);
-        $reqData['PostData'] = $body;
-        $reqData = json_encode($reqData, JSON_UNESCAPED_UNICODE);
+        $body = $this->notify_body($detail_id,$input,$params['state']);
+        $body = $this->sign($body,$out_names,$secure_key);
 
-        $resp = http_post_data(config::ORDER_COMPLETE_URL, $reqData, $header, $net_errno);
+        $resp = http_request($input['callbackurl'], $body, 'GET');
         if (empty($resp)) {
-            Log::record("回调下游,请求超时 mchid = {$mchid} mch_order = {$mch_ordersn}", Log::ERR);
+            Log::record("回调下游,请求超时 mchid = $mchid mch_order = $mch_order", Log::ERR);
+            return false;
+        } elseif (in_array($resp, ['success'])) {
+            return true;
+        } else {
             return false;
-        }
-        else
-        {
-            Log::record($resp, Log::DEBUG);
-            $resp = json_decode($resp, true);
-            if (empty($resp)) {
-                Log::record("回调下游,返回数据格式有误 mchid = {$mchid} mch_order = {$mch_ordersn}", Log::ERR);
-                return false;
-            } elseif ($resp['code'] === '200' && $resp['data'] === true) {
-                return true;
-            } else {
-                Log::record("回调下游,返回失败 mchid = {$mchid} mch_order = {$mch_ordersn} message = {$resp['message']}", Log::ERR);
-                return false;
-            }
         }
     }
 
-    private function notify_body($params)
+    private function notify_body($detail_id, $input, $order_state)
     {
-        $success = $params['state'] == 'SUCCESS';
-        $body = [
-            "OrderNo" => $params['order_sn'],
-            "Status" => $success ? 1 : 2,
-            "Description" => '',
-            "RealCost" => "",
-            "SubstituteAccount" => "",
-            "ChannelAccountId" => "",
-            "InventoryId" => "",
-            "OperatorSerialNumber" => ""
-        ];
-
-        if($body['Status'] === 1) {
-            $body['OperatorSerialNumber'] = $params['official_sn'];
+        $input['order_id'] = $detail_id;
+        if($order_state == 'SUCCESS') {
+            $input['result'] = 0;
+        } else {
+            $input['result'] = 1;
         }
 
-        return $body;
+        return $input;
     }
 }

+ 16 - 26
helper/rbridge/gy/config.php

@@ -4,36 +4,26 @@ namespace rbridge\gy;
 
 class config
 {
-    public const stUserinfofs = [
-        '1' => ['mchid' => 1099],
-        '2' => ['mchid' => 1100],
-    ];
     const MCH_NOTIFY_URL = 'gy';
-
     public static function mchid($params)
     {
-        $userid = $params['userid'];
-        if (array_key_exists($userid, self::stUserinfofs)) {
-            return self::stUserinfofs[$userid]['mchid'];
-        }
-
-        return false;
+        $userid = intval($params['userid']);
+        return $userid;
     }
 
-//    const DEFAULT_MCHID = 10299;
-//    const MCH_KEY  = '';
-//    const MCH_NOTIFY_URL = 'fulu';
-//
-//    const AES_IV = '1111111111111111';
-//    const KEY   = 'Dw^V9&6*Tzz1rMe5';
-//    const USER_ID = '786a9dd8-6a0e-4eac-91f9-cf231660cfb5';
-//
-//    const ORDER_SEND_URL = 'https://public-robot.open.fulu.com/api/OutOrder/UpdateStatusProcess'; //配送中
-//    const ORDER_COMPLETE_URL = 'https://public-robot.open.fulu.com/api/OutOrder/UpdateStatus'; //成功/失败/可疑
-//
-//    const ORDER_STATUS = [
-//        ORDER_STATE_SUCCESS => 1,
-//        ORDER_STATE_CANCEL  => 2,
-//    ];
+    public static function arrayToXml($obj, $array)
+    {
+        foreach ($array as $k => $v)
+        {
+            if (is_numeric($k))
+                $k = 'item' . $k;
+            if (is_array($v)) {
+                $node = $obj->addChild($k);
+                self::arrayToXml($node, $v);
+            } else {
+                $obj->addChild($k, htmlspecialchars($v));
+            }
+        }
+    }
 }
 

+ 0 - 6
helper/rbridge/gy/product.php

@@ -1,6 +0,0 @@
-<?php
-
-namespace rbridge\gy;
-
-
-

+ 0 - 16
helper/rbridge/gy/readme.txt

@@ -1,16 +0,0 @@
-福禄开放平台我要供货教程-客户版 https://docs.qq.com/doc/DVmZ5QWhhQnFMQUNW
-物流自助服务使用教程-客户版 https://docs.qq.com/doc/DVnVQSERJdnZWTFRZ
-物流接口文档-V2.0 https://www.yuque.com/docs/share/4d5956bb-ca0f-46a2-a5e3-dd110f81a7ec?#
-
-http://console.open.fulu.com/
-
-公司:北京椰子电子商务有限责任公司
-账号:18513846008
-密码:yezi123456
-
-公司:北京趣带娃科技有限公司
-账号:15136908757
-密码:qudaiwa123
-
-
-https://www.xyzshops.cn/mobile/bridge/fulu.php

+ 25 - 0
racc/bridge/gy.php

@@ -0,0 +1,25 @@
+<?php
+/**
+ *   add.php
+ *   stanley-king
+ *   2023/12/16
+ *   PhpStorm
+ *   PHPProject
+ */
+
+require_once(BASE_CORE_PATH . '/framework/function/http.php');
+require_once(BASE_HELPER_PATH . '/rbridge/RBridgeFactory.php');
+
+$params = $_POST;
+
+if (isset($params['request_id']) and isset($params['telephone'])) {
+    [$ret, $message] = rbridge\RBridgeFactory::instance()->add('gy', $params);
+}
+elseif(isset($params['request_id'])) {
+    [$ret, $message] = rbridge\RBridgeFactory::instance()->query('gy', $params);
+}
+else {
+    [$ret, $message] = rbridge\RBridgeFactory::instance()->balance('gy', $params);
+}
+
+echo($message);

+ 0 - 18
racc/bridge/gy/add.php

@@ -1,18 +0,0 @@
-<?php
-/**
- *   add.php
- *   stanley-king
- *   2023/12/16
- *   PhpStorm
- *   PHPProject
- */
-
-require_once(BASE_CORE_PATH . '/framework/function/http.php');
-require_once(BASE_HELPER_PATH . '/rbridge/RBridgeFactory.php');
-
-
-$params = $_SERVER['post_content'];
-
-[$ret, $message] = rbridge\RBridgeFactory::instance()->add('gy',$params);
-Log::record("gaoyang rbridge add result : {$ret}, message : {$message}", Log::DEBUG);
-echo 'ok';

+ 0 - 8
racc/bridge/gy/balance.php

@@ -1,8 +0,0 @@
-<?php
-/**
- *   balance.php
- *   stanley-king
- *   2023/12/16
- *   PhpStorm
- *   PHPProject
- */

+ 0 - 8
racc/bridge/gy/query.php

@@ -1,8 +0,0 @@
-<?php
-/**
- *   query.php
- *   stanley-king
- *   2023/12/16
- *   PhpStorm
- *   PHPProject
- */

+ 151 - 0
test/TestRBridge.php

@@ -144,4 +144,155 @@ class TestRBridge extends TestCase
         return $sign;
     }
 
+    public function testDetail()
+    {
+        $detail_id_getter = function ($mchid,$mch_order)
+        {
+            $mod_refill = Model('refill_order');
+            $detail = $mod_refill->get_detail($mchid,$mch_order);
+            if(empty($detail)) {
+                return [false, []];
+            }
+            else {
+                return [intval($detail['detail_id']), json_decode($detail['params'], true)];
+            }
+        };
+
+        [$detail_id,$info] = $detail_id_getter(10234,'5a095fd33955c4ef941f04e9307c4845');
+    }
+
+    public function testGyAdd()
+    {
+        $signer = function ($params,$names)
+        {
+            $key = '57ccb90f02ad5d5b099f518f8afb2c19';
+            $body = '';
+            foreach ($names as $name) {
+                $val = $params[$name] ?? '';
+                $body .= $val;
+            }
+            $body .= $key;
+
+            $sign = strtoupper(md5($body));
+            return $sign;
+        };
+
+        $params = [
+            'userid' => 10234,
+            'request_id' => $this->make_sn(),
+            'telephone' => 13911129867,
+            'money' => 50,
+            'callbackurl' => 'https://api.mhigh.cn/racc/callback/testcb.php'
+        ];
+        $names = ['userid','request_id','telephone','money','callbackurl'];
+
+        $sign = $signer($params,$names);
+        $params['sign'] = $sign;
+
+        [$succ,$xml] = rbridge\RBridgeFactory::instance()->add('gy', $params);
+    }
+
+    public function testGyQuery()
+    {
+        $signer = function ($params,$names)
+        {
+            $key = '57ccb90f02ad5d5b099f518f8afb2c19';
+            $body = '';
+            foreach ($names as $name) {
+                $val = $params[$name] ?? '';
+                $body .= $val;
+            }
+            $body .= $key;
+
+            $sign = strtoupper(md5($body));
+            return $sign;
+        };
+
+        $params = [
+            'userid' => 10234,
+            'request_id' => '5a095fd33955c4ef941f04e9307c4845',
+        ];
+        $names = ['userid','request_id'];
+
+        $sign = $signer($params,$names);
+        $params['sign'] = $sign;
+
+        $ret = rbridge\RBridgeFactory::instance()->query('gy', $params);
+    }
+
+    public function testGyBalance()
+    {
+        $signer = function ($params,$names)
+        {
+            $key = '57ccb90f02ad5d5b099f518f8afb2c19';
+            $body = '';
+            foreach ($names as $name) {
+                $val = $params[$name] ?? '';
+                $body .= $val;
+            }
+            $body .= $key;
+
+            $sign = strtoupper(md5($body));
+            return $sign;
+        };
+
+        $params = [
+            'userid' => 10234
+        ];
+        $names = ['userid'];
+
+        $sign = $signer($params,$names);
+        $params['sign'] = $sign;
+
+        $ret = rbridge\RBridgeFactory::instance()->balance('gy', $params);
+    }
+
+
+    public function testXML()
+    {
+        $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><root></root>');
+        $ar2xml = function ($obj, $array)
+        {
+            foreach ($array as $k => $v)
+            {
+                if(is_numeric($k))
+                    $k = 'item' . $k;
+                if(is_array($v)){
+                    $node = $obj->addChild($k);
+                    arrayToXml($node, $v);
+                }else{
+                    $obj->addChild($k, htmlspecialchars($v));
+                }
+            }
+        };
+
+        $params = [
+            'userid' => 10234,
+            'request_id' => $this->make_sn(),
+            'telephone' => 13911129867,
+            'money' => 50,
+            'callbackurl' => 'https://api.mhigh.cn/racc/callback/testcb.php'
+        ];
+
+        self::arrayToXml($xml,$params);
+
+        $val = $xml->asXML();
+
+    }
+
+    public static function arrayToXml($obj, $array)
+    {
+
+        foreach ($array as $k => $v)
+        {
+            if (is_numeric($k))
+                $k = 'item' . $k;
+            if (is_array($v)) {
+                $node = $obj->addChild($k);
+                arrayToXml($node, $v);
+            } else {
+                $obj->addChild($k, htmlspecialchars($v));
+            }
+        }
+    }
 }