Parcourir la source

xyz provider tonglu

ayHaru il y a 4 ans
Parent
commit
7bdc695430

+ 1 - 0
data/config/xyz/refill.ini.php

@@ -315,5 +315,6 @@ $phone_providers = [
     ['name' => 'lingzhdl', 'cfg' => $lingzhdl_phone],
     ['name' => 'tongy', 'cfg' => $tongy_phone],
     ['name' => 'weiyi', 'cfg' => $weiyi_phone],
+    ['name' => 'tonglu', 'cfg' => $tonglu_phone],
 ];
 $config['phone_providers'] = $phone_providers;

+ 56 - 0
helper/refill/api/xyz/tonglu/RefillCallBack.php

@@ -0,0 +1,56 @@
+<?php
+
+
+namespace refill\tonglu;
+
+require_once(BASE_HELPER_RAPI_PATH . '/tonglu/config.php');
+
+
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        $sign = $this->sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = json_encode($params) . config::KEY;
+        return strtoupper(md5($content));
+    }
+
+    //[$order_id, $success, $can_try, $need_handle]
+    public function notify($params)
+    {
+        $status = intval($params['order_status']);
+        $order_sn = $params['order_no'];
+        $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['order_cert_no']) == 'null' ? '' : $params['order_cert_no'];
+        $data['ch_trade_no'] = strtolower($params['order_id']) == 'null' ? '' : $params['order_id'];
+
+        if ($status === 3) {
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif (in_array($status , [4,5,6])) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 96 - 0
helper/refill/api/xyz/tonglu/RefillPhone.php

@@ -0,0 +1,96 @@
+<?php
+
+namespace refill\tonglu;
+
+require_once(BASE_HELPER_RAPI_PATH . '/tonglu/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['mch_id'] = config::MCH_ID;
+        $params['order_no'] = $order_sn;
+        $params['channel'] = 'hf';
+        $params['amount'] = $amount * 100;
+        $params['phone_no'] = $phone;
+        $params['provider_code'] = 'PDD';
+        $params['notify_url'] = config::NOTIFY_URL;
+        $params['time_expire'] = time() + 300;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params)
+    {
+        $params = $this->req_params($card_no, $amount, $params['order_sn']);
+        $sign = $this->sign($params);
+        $header = [
+            "sign: {$sign}",
+        ];
+        $params = json_encode($params);
+        $resp = http_post_data(config::ORDER_URL, $params , $header);
+        if ($resp === false) {
+            return [false, '系统错误', true];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if ($resp['state'] == 'ok') {
+                return [true, '', false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['order_no'] = $refill_info['order_sn'];
+        $params['mch_id'] = config::MCH_ID;
+        $params['channel'] = 'hf';
+        $sign = $this->sign($params);
+
+        $header = [
+            "sign: {$sign}",
+        ];
+        $params = json_encode($params);
+        $resp = http_post_data(config::QUERY_URL, $params , $header);
+        if ($resp === false) {
+            return [false, '系统错误'];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if($resp['state'] == 'ok') {
+                $order_state = -1;
+                $data = $resp['data'];
+                if ($data['order_status'] == 3) {
+                    $order_state = ORDER_STATE_SUCCESS;
+                    $save['official_sn'] = $data['order_cert_no'];
+                    Model('refill_order')->edit($refill_info['order_id'], $save);
+                } elseif (in_array($data['order_status'] , [4,5,6])) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($data['order_status'] , [-1,0,1,2])) {
+                    $order_state = ORDER_STATE_SEND;
+                }
+                if ($order_state == -1) {
+                    return [false, $resp['desc']];
+                }
+                return [true, $order_state];
+            }else{
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = json_encode($params) . config::KEY;
+        return strtoupper(md5($content));
+    }
+}

+ 16 - 0
helper/refill/api/xyz/tonglu/config.php

@@ -0,0 +1,16 @@
+<?php
+
+
+namespace refill\tonglu;
+
+
+class config
+{
+    const ORDER_URL = 'http://wg.guozipay.com/api/order/create';
+    const QUERY_URL = 'http://wg.guozipay.com/api/order/query';
+
+    const MCH_ID = '20210322';
+    const KEY = '9fcd301b7ce14a5e8c4908dba8679769';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/refill_tonglu.php";
+//    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/signature.php";
+}

+ 7 - 0
mobile/refill_tonglu.php

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

+ 32 - 0
test/TestRefill.php

@@ -254,6 +254,38 @@ class TestRefill extends TestCase
         $resp = $providers->add('18500608333', 5, 30, ['order_sn' => $this->make_sn()]);
     }
 
+    public function testWeiyiPhone()
+    {
+        $providers = new refill\weiyi\RefillPhone([]);
+//        $resp = $providers->add(18500608333, 5, 100, ['order_sn' => $this->make_sn()]);
+//        $resp = $providers->query(['order_sn' => '59031616396534854303']);
+//        $body = '{"userid":"8177b4b1d0254c0699bc","ordernum":"59031616396534854303","mobile":"18500608333","timestamp":"20210322150437","state":"3","desc":"%E5%A4%B1%E8%B4%A5%3A%E5%A4%B1%E8%B4%A5","sign":"1d412f956c041bf4454357b209c93df6"}';
+//        $params = json_decode($body , true);
+//        refill\RefillFactory::instance()->notify('weiyi',$params);
+    }
+
+    public function testTongluPhone()
+    {
+        $providers = new refill\tonglu\RefillPhone([]);
+//        $resp = $providers->add(18500608333, 5, 50, ['order_sn' => $this->make_sn()]);
+        $resp = $providers->query(['order_sn' => '22961616468561936356']);
+//        $body = '{"order_no":"22961616468561936356","order_status":"5","phone_no":"18500608333","amount":5000,"time_paid":1616468856287,"order_cert_no":"","paid":false,"order_id":"20210323966497008"}';
+//        $sign = '9E41F52F612D60EBB654B3A5D1E2F1E5';
+//        $params = json_decode($body , true);
+//        $params['sign'] = $sign;
+//        refill\RefillFactory::instance()->notify('tonglu',$params);
+    }
+
+    public function testPrice()
+    {
+        $amounts = [10,20,30,50,100,200,300,500];
+        $rate = 0.94;
+        foreach ($amounts as $amount){
+            $price[] = $amount * $rate;
+        }
+
+    }
+
     public function testWeisPhone()
     {
         $providers = new refill\weisyd\RefillPhone([]);