HARUHARU 4 роки тому
батько
коміт
b806565857

+ 1 - 1
helper/fcgi_server.php

@@ -31,7 +31,7 @@ class fcgi_server
             'refill_suhc.php','refill_suhctm.php','refill_suhcpdd.php',
             'refill_beixt.php','refill_bxtwt.php','refill_bjb.php','refill_xyz.php',
             'refill_zzx.php','refill_inner.php','refill_jiec.php','refill_yifa.php',
-            'bridge_shr.php'
+            'bridge_shr.php','refill_weit.php'
         ];
         $path = BASE_ROOT_PATH . '/mobile/';
         $file = str_replace($path,'',$file);

+ 3 - 0
helper/refill/RefillFactory.php

@@ -58,6 +58,9 @@ require_once(BASE_HELPER_PATH . '/refill/jiec/RefillCallBack.php');
 require_once(BASE_HELPER_PATH . '/refill/xc/RefillPhone.php');
 require_once(BASE_HELPER_PATH . '/refill/xc/RefillCallBack.php');
 
+require_once(BASE_HELPER_PATH . '/refill/weit/RefillPhone.php');
+require_once(BASE_HELPER_PATH . '/refill/weit/RefillCallBack.php');
+
 use Log;
 use mtopcard;
 use QueueClient;

+ 53 - 0
helper/refill/weit/RefillCallBack.php

@@ -0,0 +1,53 @@
+<?php
+
+
+namespace refill\weit;
+
+require_once(BASE_HELPER_PATH . '/refill/weit/config.php');
+
+
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = $this->sign($params);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = $params['mchid'] . $params['pt_order_id'] . $params['mch_order_id'] . $params['op_order_id'] . $params['tel'] . $params['price'] . $params['pay_type'] . $params['status'] . config::KEY;
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['mch_order_id'];
+        $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['op_order_id']) == 'null' ? '' : $params['op_order_id'];
+        $data['ch_trade_no'] = strtolower($params['pt_order_id']) == 'null' ? '' : $params['pt_order_id'];
+        Model('refill_order')->edit($order_id, $data);
+
+        if ($status === 1) {
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 0) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 106 - 0
helper/refill/weit/RefillPhone.php

@@ -0,0 +1,106 @@
+<?php
+
+namespace refill\weit;
+
+require_once(BASE_HELPER_PATH . '/refill/weit/config.php');
+
+use refill;
+use Log;
+use mtopcard;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $phone, int $amount, string $order_sn)
+    {
+        $params['tel'] = $phone;
+        $params['mch_order_id'] = $order_sn;
+        $params['mchid'] = config::MCH_ID;
+        $params['price '] = $amount;
+        $params['notify'] = config::NOTIFY_URL;
+        $params['teltype'] = $this->phone_type($phone);
+        $params['timeout'] = 50;
+        $params['time'] = time();
+        $params['rand'] = rand(100000,999999);
+        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);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params , 'POST'  , false , config::ExtHeaders);
+        if ($resp === false) {
+            return [false, '系统错误'];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if ($resp['code'] == 0) {
+                return [true, $resp['pt_order_id']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['mchid'] = config::MCH_ID;
+        $params['mch_order_id'] = $refill_info['order_sn'];
+        $params['pt_order_id'] = $refill_info['ch_trade_no'];
+        $params['op_order_id '] = $refill_info['official_sn'];
+        $params['tel'] = $refill_info['card_no'];
+        $params['time '] = time();
+        $params['rand'] = rand(100000,999999);
+        $content = $params['mchid'] . $params['pt_order_id'] . $params['mch_order_id'] . $params['op_order_id'] . $params['tel'] . $params['time'] . $params['rand'] . config::KEY;
+        $params['sign'] = md5($content);
+        $resp = http_request(config::QUERY_URL, $params , 'POST');
+        if ($resp === false) {
+            return [false, '系统错误'];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if ($resp['code'] == 0) {
+                if ($resp['data']['status'] == 1) {
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($resp['data']['status'] == 0) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($resp['data']['status'] == 2){
+                    $order_state = ORDER_STATE_SEND;
+                }
+                if (empty($order_state)) {
+                    return [false, $resp['data']];
+                }
+                return [true, $order_state];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $key = config::KEY;
+        $content = $params['mchid'] . $params['tel'] . $params['mch_order_id'] . $params['price'] . $params['teltype'] . $params['timeout'] . $params['notify'] . $params['time'];
+        $content .= $params['rand'] . $key;
+        return md5($content);
+    }
+    private function phone_type($phone)
+    {
+        $card_type = mtopcard\card_type($phone);
+
+        if ($card_type == mtopcard\ChinaMobileCard) {
+            return 2;
+        } elseif ($card_type == mtopcard\ChinaUnicomCard) {
+            return 1;
+        } elseif ($card_type == mtopcard\ChinaTelecomCard) {
+            return 3;
+        }
+    }
+}

+ 16 - 0
helper/refill/weit/config.php

@@ -0,0 +1,16 @@
+<?php
+
+
+namespace refill\weit;
+
+
+class config
+{
+    const ORDER_URL = 'http://47.97.208.197/api/telpay';
+    const QUERY_URL = 'http://14.192.8.43/api/telpay/query';
+
+    const MCH_ID = 10014;
+    const KEY = 'f2962db97df033cac91e3f082dc342bf';
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/signature.php";
+    const ExtHeaders = ['Content-Type: application/x-www-form-urlencoded'];
+}

+ 10 - 0
mobile/refill_weit.php

@@ -0,0 +1,10 @@
+<?php
+
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
+
+$content = $_SERVER['post_content'];
+$input = json_decode($content,true);
+
+refill\RefillFactory::instance()->notify('weit',$input);
+
+echo ('success');

+ 6 - 0
test/TestRefill.php

@@ -94,6 +94,12 @@ class TestRefill extends TestCase
         $resp = $providers->add(15120035568, 5, 50, ['order_sn' => $this->make_sn()]);
     }
 
+    public function testWeitPhone()
+    {
+        $providers = new refill\weit\RefillPhone([]);
+        $resp = $providers->add(18500608333, 5, 30, ['order_sn' => $this->make_sn()]);
+    }
+
     public function testYifaCB()
     {
         $body = '{"app_id":"e4a61b2acf1119c72c1ed9b61781494e","nonce_str":"OQMEBRQWJGPKOWYUXDVPTNMLEQJHXFWG","timestamp":1610275083,"order_sn":"161027325773032634","coder_order_sn":"60641610273255214687","isp_order_sn":null,"phone":"15120035568","amount":"94.000","discount":"0.9400","create_time":"2021-01-10 18:07:42","recharge_time":"","status":"fail","channel_id":3,"sign":"47278AD74EFA7F5FC8DE3A6D362C409B"}';