Browse Source

yezi binyu

xiaoyu 2 years ago
parent
commit
1ee75e9128

+ 16 - 0
helper/refill/api/xyz/binyu/API信息.txt

@@ -0,0 +1,16 @@
+测试环境对接参数如下
+mch_id:3
+secret_key:01a02f930f28c87b1ed4669d315d3bfb
+直冲下单地址:
+https://phone.shanghaibinyu.top/api/charge
+订单查询地址:
+https://phone.shanghaibinyu.top/api/query
+余额查询地址:
+https://phone.shanghaibinyu.top/api/balance
+
+对接文档:
+https://docs.qq.com/doc/DZU9xSUhXYVBNRXhj
+
+地址:https://phone.shanghaibinyu.top/merchant/main
+duoyiyou01
+123456

+ 42 - 0
helper/refill/api/xyz/binyu/RefillCallBack.php

@@ -0,0 +1,42 @@
+<?php
+namespace refill\binyu;
+
+require_once(BASE_HELPER_RAPI_PATH . '/binyu/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['signature']);
+        $sign = config::sign($input);
+        if ($params['signature'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public function notify($params)
+    {
+        $status = $params['order_status'];
+        $order_sn = $params['customer_order_no'];
+        $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
+        if (empty($order_info)) {
+            return [false, false, false, false, ''];
+        }
+        $order_id = $order_info['order_id'];
+
+        if ($status === 'success') {
+            $official_sn = strtolower($params['serial_number']) == 'null' ? '' : $params['serial_number'];
+            $data['official_sn'] = $official_sn;
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true, $official_sn];
+        } elseif ($status === 'fail') {
+            return [$order_id, false, true, true, ''];
+        } else {
+            return [$order_id, false, false, false, ''];
+        }
+    }
+}

+ 129 - 0
helper/refill/api/xyz/binyu/RefillPhone.php

@@ -0,0 +1,129 @@
+<?php
+
+namespace refill\binyu;
+
+require_once(BASE_HELPER_RAPI_PATH . '/binyu/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, int $card_type, string $order_sn)
+    {
+        $params['mch_id'] = config::MCH_ID;
+        $params['timestamp'] = date("Y-m-d H:i:s");
+        $params['account'] = $phone;
+        $params['account_type'] = 1;
+        $params['par_value'] = $amount;
+        $params['customer_order_no'] = $order_sn;
+        $params['notify_url'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $amount, $card_type, $params['order_sn']);
+        $sign = config::sign($params);
+        $params['signature'] = $sign;
+
+        $params = json_encode($params);
+        $resp = http_post_data(config::ORDER_URL, $params , config::ExtHeaders, $net_errno);
+
+        if (empty($resp)) {
+            return [false, '系统错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif ($resp['code'] === 200) {
+                return [true, '', false];
+            } elseif (in_array($resp['code'], [1004, 5000], true)) {
+                $net_errno = "HTTP-{$resp['code']}";
+                return [false, $resp['msg'], true];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['mch_id'] = config::MCH_ID;
+        $params['timestamp'] = date("Y-m-d H:i:s");
+        $params['customer_order_no'] = $refill_info['order_sn'];
+        $sign = config::sign($params);
+        $params['signature'] = $sign;
+
+        $params = json_encode($params);
+        $resp = http_post_data(config::QUERY_URL, $params , config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误', ''];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误', ''];
+            }
+            elseif ($resp['code'] === 200)
+            {
+                $offical_sn = '';
+                $status = $resp['result']['order_status'];
+                if ($status === 'success') {
+                    $offical_sn = $resp['result']['serial_number'];
+                    $updata['official_sn'] = $offical_sn;
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 'fail') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 'recharging') {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $status, $offical_sn];
+                }
+                return [true, $order_state, $offical_sn];
+            }
+            else {
+                return [false, $resp['msg'], ''];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['mch_id'] = config::MCH_ID;
+        $params['timestamp'] = date("Y-m-d H:i:s");
+        $sign = config::sign($params);
+        $params['signature'] = $sign;
+
+        $params = json_encode($params);
+        $resp = http_post_data(config::BALANCE_URL, $params , config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误'];
+            } elseif ($resp['code'] === 200) {
+                return [true, $resp['result']['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+}

+ 41 - 0
helper/refill/api/xyz/binyu/config.php

@@ -0,0 +1,41 @@
+<?php
+namespace refill\binyu;
+
+class config
+{
+    //https://docs.qq.com/doc/DZU9xSUhXYVBNRXhj
+    const ORDER_URL = 'https://phone.shanghaibinyu.top/api/charge';
+    const QUERY_URL = 'https://phone.shanghaibinyu.top/api/query';
+    const BALANCE_URL = 'https://phone.shanghaibinyu.top/api/balance';
+
+    const MCH_ID = '3';
+    const SECRET_KEY = '01a02f930f28c87b1ed4669d315d3bfb';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_binyu.php";
+
+    const ExtHeaders = ['Content-Type: application/json'];
+
+    public static function sign($params)
+    {
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            if(self::check_empty($value) === false) {
+                $content .= "{$key}={$value}&";
+            }
+        }
+        $content .= 'secret_key=' . config::SECRET_KEY;
+        return md5(md5($content));
+    }
+
+    public static function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+}

+ 7 - 0
mobile/callback/refill_binyu.php

@@ -0,0 +1,7 @@
+<?php
+
+$content = $_SERVER['post_content'];
+$input = json_decode($content,true) ?? [];
+refill\util::push_notify('binyu',$input);
+
+echo 'success';

+ 14 - 0
test/TestRefill.php

@@ -3306,6 +3306,20 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
         $resp = $provider->notify($params);
     }
     }
 
 
+    public function testBinyu()
+    {
+        $provider = $this->getProvider('binyu');
+        $resp = $provider->balance();
+//        $resp = $provider->add(15811535608, 4, 100, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '30431682320503722891']);
+
+//        $body = '{"order_status":"success","account":"15811535608","account_type":1,"product_id":10000,"price":"100.0000","customer_order_no":"30431682320503722891","serial_number":"1682320511733","signature":"b8f29e6e7c9e2cc9f93267efdf9c0b54"}';
+//        $params = json_decode($body, true);
+//        $provider = $this->getProvider('binyu', 'RefillCallBack');
+//        $ret = $provider->verify($params);
+//        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     public function testAmingjd()
     {
     {
 //        $provider = new refill\amingjd\RefillPhone([]);
 //        $provider = new refill\amingjd\RefillPhone([]);