浏览代码

rbridge youjun

xiaoyu 2 年之前
父节点
当前提交
8cceacc81d

+ 4 - 1
helper/rbridge/fulu/readme.txt

@@ -10,4 +10,7 @@ http://console.open.fulu.com/
 
 公司:北京趣带娃科技有限公司
 账号:15136908757
-密码:qudaiwa123
+密码:qudaiwa123
+
+
+https://www.xyzshops.cn/mobile/bridge/fulu.php

+ 159 - 0
helper/rbridge/youjun/Bridge.php

@@ -0,0 +1,159 @@
+<?php
+
+namespace rbridge\youjun;
+
+require_once(BASE_HELPER_PATH . '/rbridge/youjun/config.php');
+
+use rbridge\IBridge;
+use refill;
+use Log;
+use StatesHelper;
+
+class Bridge implements IBridge
+{
+    public function add($params)
+    {
+        if(StatesHelper::fetch_state('bridge')) {
+            include (BASE_HELPER_PATH . '/rbridge/youjun/product.php');
+        }
+
+        $dispatcher = function ($product_num)
+        {
+            global $youjun_product;
+            if(empty($youjun_product)) return [config::DEFAULT_MCHID,[]];
+
+            foreach ($youjun_product as $mchid => $product_infos)
+            {
+                if(array_key_exists($product_num, $product_infos)) {
+                    $card_types = $product_infos[$product_num];
+                    return [$mchid,$card_types];
+                }
+            }
+
+            return [config::DEFAULT_MCHID,[]];
+        };
+
+        $params = $this->aes_decrypt($params);
+        if (empty($params)) {
+            return [false, '数据解密失败'];
+        }
+        $json_str = json_encode($params);
+        Log::record("youjun add params: {$json_str}", Log::DEBUG);
+
+        $SupProductId = $params['SupProductId'];
+        [$mchid,$mch_card_types] = $dispatcher($SupProductId);
+        $chargeType = intval($params['OrderType']);
+
+        //订单类型:1话费 2流量 3卡密 4直充,
+        if (!in_array($chargeType, [1, 3, 4], true)) {
+            return [false, '订单类型不支持'];
+        }
+
+        Model('merchant_query')->add_info($mchid, $params['Id'], json_encode($params));
+        $mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $mchid]);
+        $userid = intval($mchinfo['admin_id']);
+
+        $order_time = time();
+        $mch_order = $params['Id'];
+        $card_no = $params['ChargeAccount'];
+        $input = [ 'mchid' => $mchid,
+            'buyer_id' => $userid,
+            'amount' => $params['SupProductFaceValue'],
+            'card_no' => $card_no,
+            'mch_order' => $mch_order,
+            'mch_card_types' => $mch_card_types,
+            'notify_url' => config::MCH_NOTIFY_URL,
+            '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);
+
+        $state = refill\util::push_add($input);
+        if ($state === true) {
+            Log::record("youjun::Bridge refill::util::push_add success mchid={$mchid} mch_order={$mch_order} state={$state}",Log::DEBUG);
+            return [true, '提交成功'];
+        } else {
+            refill\util::del_queue_order($mchid,$mch_order);
+            Model('refill_order')->del_detail($mchid,$mch_order);
+            Log::record("youjun::Bridge refill::util::push_add error mchid={$mchid} mch_order={$mch_order} state={$state}",Log::DEBUG);
+            return [false, '提交失败'];
+        }
+    }
+
+    public function notify($params)
+    {
+        $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}",
+        ];
+
+        $body = json_encode($body, JSON_UNESCAPED_UNICODE);
+        $body = $this->aes_encrypt($body);
+        $reqData['PostData'] = $body;
+        $reqData = json_encode($reqData, JSON_UNESCAPED_UNICODE);
+
+        $resp = http_post_data(config::ORDER_COMPLETE_URL, $reqData, $header, $net_errno);
+        if (empty($resp)) {
+            Log::record("回调下游,请求超时 mchid = {$mchid} mch_order = {$mch_ordersn}", Log::ERR);
+            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)
+    {
+        $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'];
+        }
+
+        return $body;
+    }
+
+    private function aes_encrypt($data) {
+        $str_padded = $data;
+        if (strlen($str_padded) % 16) {
+            $str_padded = str_pad($str_padded,strlen($str_padded) + 16 - strlen($str_padded) % 16, "\0");
+        }
+        $data =  openssl_encrypt($str_padded, 'AES-128-CBC', config::KEY, OPENSSL_NO_PADDING, config::AES_IV);
+        return base64_encode($data);
+    }
+
+    //AES-128-ECB解密  data 字符串
+    private function aes_decrypt($data) {
+        $encrypted = base64_decode($data);
+        $params = openssl_decrypt($encrypted, 'AES-128-CBC', config::KEY, OPENSSL_NO_PADDING, config::AES_IV);
+        return json_decode(trim($params), true);
+    }
+}

+ 23 - 0
helper/rbridge/youjun/config.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace rbridge\youjun;
+
+class config
+{
+    const DEFAULT_MCHID = 10319;
+    const MCH_KEY  = '';
+    const MCH_NOTIFY_URL = 'youjun';
+
+    const AES_IV = '1111111111111111';
+    const KEY   = 'LiJqfCbI%mqny3mD';
+    const USER_ID = '8d91fd4c-2309-4949-9676-6c20084d57cd';
+
+    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,
+    ];
+}
+

+ 17 - 0
helper/rbridge/youjun/product.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace rbridge\youjun;
+
+global $youjun_product;
+$youjun_product = [
+    10319 => [
+        //移动
+        506122366 => [4, 5, 6],
+        505045388 => [4, 5, 6],
+        509984818 => [4, 5, 6],
+        503711825 => [4, 5, 6],
+        505659723 => [4, 5, 6],
+        503633222 => [4, 5, 6],
+    ],
+];
+

+ 25 - 0
helper/rbridge/youjun/readme.txt

@@ -0,0 +1,25 @@
+福禄开放平台我要供货教程-客户版 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/
+
+福禄-酉俊
+账号:13916932570
+密码:youjun131419
+
+UserId:
+8d91fd4c-2309-4949-9676-6c20084d57cd
+UserKey:
+LiJqfCbI%mqny3mD
+aesIV=1111111111111111
+
+503633222 移动话费- 500
+505659723 移动话费- 300
+503711825 移动话费- 200
+509984818 移动话费- 100
+505045388 移动话费- 50
+506122366 移动话费- 30
+
+
+https://www.xyzshops.cn/mobile/bridge/youjun.php

+ 11 - 0
mobile/bridge/youjun.php

@@ -0,0 +1,11 @@
+<?php
+
+require_once(BASE_CORE_PATH . '/framework/function/http.php');
+require_once(BASE_HELPER_PATH . '/rbridge/RBridgeFactory.php');
+
+
+$content = $_SERVER['post_content'];
+
+[$ret, $message] = rbridge\RBridgeFactory::instance()->add('youjun',$content);
+Log::record("youjun rbridge add result : {$ret}, message : {$message}", Log::DEBUG);
+echo 'ok';