Browse Source

lingzhu provider amingjd add

ayHaru 4 years ago
parent
commit
fefdf18f93

+ 14 - 0
data/config/lingzh/refill.ini.php

@@ -158,6 +158,19 @@ $chuka_phone = ['name' => 'chuka', 'store_id' => 40,
     ],
     ],
     'official_sn' => true, 'refill_type' => 'api'];
     'official_sn' => true, 'refill_type' => 'api'];
 
 
+$amingjd_phone = ['name' => 'amingjd', 'store_id' => 41,
+    'amount' => [
+        30 => [['goods_id' => 55, 'price' => 28.5, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+            ['goods_id' => 55, 'price' => 28.8, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        50 => [['goods_id' => 56, 'price' => 47.5, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+            ['goods_id' => 56, 'price' => 48, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        100 => [['goods_id' => 53, 'price' => 95, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+            ['goods_id' => 53, 'price' => 96, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        200 => [['goods_id' => 54, 'price' => 190, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+            ['goods_id' => 54, 'price' => 192, 'quality' => 2, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 $phone_providers = [
     ['name' => 'baizeyd', 'cfg' => $baizeyd, 'opened' => true, 'sort' => 1],
     ['name' => 'baizeyd', 'cfg' => $baizeyd, 'opened' => true, 'sort' => 1],
     ['name' => 'aming', 'cfg' => $aming_phone, 'opened' => true, 'sort' => 1],
     ['name' => 'aming', 'cfg' => $aming_phone, 'opened' => true, 'sort' => 1],
@@ -167,5 +180,6 @@ $phone_providers = [
     ['name' => 'yibao', 'cfg' => $yibao_phone, 'opened' => true, 'sort' => 1],
     ['name' => 'yibao', 'cfg' => $yibao_phone, 'opened' => true, 'sort' => 1],
     ['name' => 'amingyd', 'cfg' => $amingyd_phone, 'opened' => true, 'sort' => 1],
     ['name' => 'amingyd', 'cfg' => $amingyd_phone, 'opened' => true, 'sort' => 1],
     ['name' => 'chuka', 'cfg' => $chuka_phone, 'opened' => true, 'sort' => 1],
     ['name' => 'chuka', 'cfg' => $chuka_phone, 'opened' => true, 'sort' => 1],
+    ['name' => 'amingjd', 'cfg' => $amingjd_phone],
     ];
     ];
 $config['phone_providers'] = $phone_providers;
 $config['phone_providers'] = $phone_providers;

+ 1 - 1
helper/fcgisrv/LZRAccServer.php

@@ -27,7 +27,7 @@ class LZRAccServer extends BaseServer
         $exfiles = [
         $exfiles = [
             'callback/lingzh/baizeyd.php','callback/lingzh/aming.php','callback/lingzh/binghc.php',
             'callback/lingzh/baizeyd.php','callback/lingzh/aming.php','callback/lingzh/binghc.php',
             'callback/lingzh/ruishun.php','callback/lingzh/wuchen.php','callback/lingzh/yibao.php',
             'callback/lingzh/ruishun.php','callback/lingzh/wuchen.php','callback/lingzh/yibao.php',
-            'callback/lingzh/amingyd.php','callback/lingzh/chuka.php'
+            'callback/lingzh/amingyd.php','callback/lingzh/chuka.php','callback/lingzh/amingjd.php'
         ];
         ];
 
 
         $this->setExFiles($exfiles);
         $this->setExFiles($exfiles);

+ 54 - 0
helper/refill/api/lingzh/amingjd/RefillCallBack.php

@@ -0,0 +1,54 @@
+<?php
+
+
+namespace refill\amingjd;
+
+require_once(BASE_HELPER_RAPI_PATH . '/amingjd/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'];
+        $content .= $params['status'] . config::KEY;
+        return md5($content);
+    }
+
+    //[$order_id, $success, $can_try, $need_handle]
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $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'];
+
+        if ($status === 1) {
+            Model('refill_order')->edit($order_id, $data);
+            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/api/lingzh/amingjd/RefillPhone.php

@@ -0,0 +1,106 @@
+<?php
+
+namespace refill\amingjd;
+
+require_once(BASE_HELPER_RAPI_PATH . '/amingjd/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['mchid'] = config::MCHID;
+        $params['tel'] = $phone;
+        $params['orderid'] = $order_sn;
+        $params['price'] = $amount;
+        $params['teltype'] = $this->phone_type($phone);
+        $params['timeout'] = 300;
+        $params['notify'] = config::NOTIFY_URL;
+        $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);
+        if ($resp === false) {
+            return [false, '系统错误', true];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if ($resp['code'] == 0) {
+                return [true, $resp['order_id'], false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    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);
+        if ($resp === false) {
+            return [false, '系统错误'];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if ($resp['code'] == 100) {
+                $order_state = -1;
+                if ($resp['status'] == 3) {
+                    $order_state = ORDER_STATE_SUCCESS;
+                    $save['official_sn'] = strtolower($resp['out_order_id']) == 'null' ? '' : $resp['out_order_id'];
+                    Model('refill_order')->edit($refill_info['order_id'], $save);
+                } elseif ($resp['status'] == 4) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($resp['status'] , [1 , 2])) {
+                    $order_state = ORDER_STATE_CANCEL;
+                }
+                if ($order_state == -1) {
+                    return [false, $resp['msg']];
+                }
+                return [true, $order_state];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $content  = $params['mchid'] . $params['tel'] . $params['price'] . $params['orderid'] . $params['teltype'] . $params['timeout'] . $params['notify'];
+        $content .= $params['time'] . $params['rand'] . config::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;
+        }
+    }
+}

+ 15 - 0
helper/refill/api/lingzh/amingjd/config.php

@@ -0,0 +1,15 @@
+<?php
+
+
+namespace refill\amingjd;
+
+
+class config
+{
+    const ORDER_URL = 'http://121.43.141.241:8082/api/telpay';
+    const QUERY_URL = 'http://121.43.141.241:8082/api/telpay/query';
+
+    const MCHID = 10003;
+    const KEY = '14d5ede552830bff5f25d6ae069aad12';
+    const NOTIFY_URL = BASE_SITE_URL . "/racc/callback/lingzh/amingjd.php";
+}

+ 4 - 0
racc/callback/lingzh/amingjd.php

@@ -0,0 +1,4 @@
+<?php
+
+refill\util::push_notify('amingjd',$_POST);
+echo ('success');

+ 10 - 0
test/TestRefill.php

@@ -276,6 +276,16 @@ class TestRefill extends TestCase
 //        refill\RefillFactory::instance()->notify('tonglu',$params);
 //        refill\RefillFactory::instance()->notify('tonglu',$params);
     }
     }
 
 
+    public function testAmingjd()
+    {
+//        $providers = new refill\amingjd\RefillPhone([]);
+//        $resp = $providers->add(13699279618, 5, 30, ['order_sn' => $this->make_sn()]);
+//        $resp = $providers->query(['order_sn' => '42301616475989518588']);
+        $body = '{"order_id":"83321616478215494884","mchid":"10003","tel":"13699279618","price":"30.00","sign":"01c49620c155a80bc43cecc2b1651868","status":"0","out_order_id":"0"}';
+        $params = json_decode($body , true);
+        refill\RefillFactory::instance()->notify('amingjd',$params);
+    }
+
     public function testPrice()
     public function testPrice()
     {
     {
         $amounts = [10,20,30,50,100,200,300,500];
         $amounts = [10,20,30,50,100,200,300,500];