소스 검색

add phone provider tianx

HARUHARU 4 년 전
부모
커밋
5af7b675c5

+ 6 - 0
data/config/prod/refill.ini.php

@@ -124,6 +124,12 @@ $bjbyd_phone = ['name' => 'bjbyd', 'store_id' => 24, 'card_type' => ['chinamobil
         200 => ['goods_id' => 6370, 'price' => 191]],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$tianx_phone = ['name' => 'tianx', 'store_id' => 25, 'card_type' => ['chinamobile', 'chinaunicom', 'chinatelecom'],
+    'amount' => [50 => ['goods_id' => 6371, 'price' => 46.5],
+        100 => ['goods_id' => 6372, 'price' => 93],
+        200 => ['goods_id' => 6373, 'price' => 186]],
+    'refill_type' => 'api'];
+
 $yifa_phone = ['name' => 'yifa', 'store_id' => 16, 'card_type' => ['chinamobile'],
     'amount' => [30 => ['goods_id' => 6318, 'price' => 28.65],
         50 => ['goods_id' => 6319, 'price' => 47.75],

+ 1 - 1
helper/fcgi_server.php

@@ -31,7 +31,7 @@ class fcgi_server
             'refill_tianjt.php','refill_suhctm.php','refill_suhcpdd.php','refill_gftd.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','refill_weit.php'
+            'bridge_shr.php','refill_weit.php','refill_tianx.php'
         ];
         $path = BASE_ROOT_PATH . '/mobile/';
         $file = str_replace($path,'',$file);

+ 3 - 0
helper/refill/RefillFactory.php

@@ -71,6 +71,9 @@ require_once(BASE_HELPER_PATH . '/refill/weit/RefillCallBack.php');
 require_once(BASE_HELPER_PATH . '/refill/bjbyd/RefillPhone.php');
 require_once(BASE_HELPER_PATH . '/refill/bjbyd/RefillCallBack.php');
 
+require_once(BASE_HELPER_PATH . '/refill/tianx/RefillPhone.php');
+require_once(BASE_HELPER_PATH . '/refill/tianx/RefillCallBack.php');
+
 use Log;
 use mtopcard;
 use QueueClient;

+ 52 - 0
helper/refill/tianx/RefillCallBack.php

@@ -0,0 +1,52 @@
+<?php
+
+
+namespace refill\tianx;
+
+require_once(BASE_HELPER_PATH . '/refill/tianx/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['order_id'] . $params['out_order_id'] . config::MCHID . $params['tel'] . $params['price'] . $params['pay_type'] . $params['status'] . config::KEY;
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['code']);
+        $order_sn = $params['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['out_order_id']) == 'null' ? '' : $params['out_order_id'];
+        Model('refill_order')->edit($order_id, $data);
+
+        if ($status === 100) {
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 0) {
+            return [$order_id, false, false,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 93 - 0
helper/refill/tianx/RefillPhone.php

@@ -0,0 +1,93 @@
+<?php
+
+namespace refill\tianx;
+
+require_once(BASE_HELPER_PATH . '/refill/tianx/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['price'] = $order_sn;
+        $params['mchid'] = config::MCHID;
+        $params['orderid'] = $amount;
+        $params['notify_url'] = config::NOTIFY_URL;
+        $params['teltype'] = $this->phone_type($phone);
+        $params['timeout'] = 180;
+        $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'] == 1) {
+                return [true, $resp['data']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['orderid'] = $refill_info['order_sn'];
+        $params['mchid'] = config::MCHID;
+        $content = $params['mchid'] . $params['orderid'] . config::KEY;
+        $params['sign'] = md5($content);
+        $resp = http_request(config::QUERY_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['order_id']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $key = config::KEY;
+        $content  = $params['mchid'] . $params['tel'] . $params['price'] . $params['orderid'] . $params['teltype'] . $params['timeout'] . $params['notify'];
+        $content .= $params['time'] . $params['rand'] . $key;
+        return md5($content);
+    }
+
+    private function phone_type($phone)
+    {
+        $card_type = mtopcard\card_type($phone);
+
+        if ($card_type == mtopcard\ChinaMobileCard) {
+            return 0;
+        } elseif ($card_type == mtopcard\ChinaUnicomCard) {
+            return 1;
+        } elseif ($card_type == mtopcard\ChinaTelecomCard) {
+            return 2;
+        }
+    }
+}

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

@@ -0,0 +1,16 @@
+<?php
+
+
+namespace refill\tianx;
+
+
+class config
+{
+    const ORDER_URL = 'http://8.136.183.28:8082/api/telpay';
+    const QUERY_URL = 'http://8.136.183.28:8082/api/telpay/query';
+
+    const MCHID = 10129;
+    const KEY = '13deaf699da2d81bf9ca2c15a0d1c171';
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/refill_tianx.php";
+    const ExtHeaders = ['Content-Type: application/x-www-form-urlencoded'];
+}

+ 9 - 0
mobile/refill_tianx.php

@@ -0,0 +1,9 @@
+<?php
+
+//捷充的回调接口
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
+
+refill\RefillFactory::instance()->notify('tianx',$_POST);
+
+echo ('success');
+