Explorar el Código

add provider afandeng

HARUHARU hace 4 años
padre
commit
d521c7d686

+ 4 - 0
admin/control/merchant.php

@@ -851,6 +851,10 @@ class merchantControl extends SystemControl
         $phone_items = $name_val_row($phone_items);
         $phone_inserts = $match($phones,$phone_items);
 
+        if(!in_array('afandeng' , $phone_items)) {
+            $mod_prov->insert(['name' => 'afandeng' , 'type' => 2]);
+        }
+
         $inserter($mod_prov,1,$oil_inserts);
         $inserter($mod_prov,2,$phone_inserts);
     }

+ 12 - 2
data/config/prod/refill.ini.php

@@ -155,7 +155,7 @@ $weit_phone = ['name' => 'weit', 'store_id' => 18, 'card_type' => ['chinaunicom'
         300 => ['goods_id' => 6335, 'price' => 285],
         500 => ['goods_id' => 6336, 'price' => 475]], 'official_sn' => true, 'refill_type' => 'api'];
 
-$afand_phone = ['name' => 'afand', 'store_id' => 26, 'card_type' => ['chinamobile', 'chinaunicom', 'chinatelecom'],
+$afand_phone = ['name' => 'afand', 'store_id' => 26, 'card_type' => ['chinaunicom', 'chinatelecom'],
     'amount' => [
         30 => ['goods_id' => 6374, 'price' => 28.5],
         50 => ['goods_id' => 6375, 'price' => 47.5],
@@ -164,6 +164,15 @@ $afand_phone = ['name' => 'afand', 'store_id' => 26, 'card_type' => ['chinamobil
         300 => ['goods_id' => 6378, 'price' => 285],
         500 => ['goods_id' => 6379, 'price' => 475]], 'official_sn' => true, 'refill_type' => 'api'];
 
+$afandeng_phone = ['name' => 'afandeng', 'store_id' => 27, 'card_type' => ['chinamobile'],
+    'amount' => [
+        30 => ['goods_id' => 6380, 'price' => 28.5],
+        50 => ['goods_id' => 6381, 'price' => 47.5],
+        100 => ['goods_id' => 6382, 'price' => 95],
+        200 => ['goods_id' => 6383, 'price' => 190],
+        300 => ['goods_id' => 6384, 'price' => 285],
+        500 => ['goods_id' => 6385, 'price' => 475]], 'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
     ['name' => 'beixt', 'cfg' => $beixt_phone, 'opened' => false, 'sort' => 1],
     ['name' => 'bxtwt', 'cfg' => $bxtwt_phone, 'opened' => false, 'sort' => 2],
@@ -173,5 +182,6 @@ $phone_providers = [
     ['name' => 'yifa', 'cfg' => $yifa_phone, 'opened' => false, 'sort' => 5],
     ['name' => 'jiec', 'cfg' => $jiec_phone, 'opened' => false, 'sort' => 1],
     ['name' => 'weit', 'cfg' => $weit_phone, 'opened' => false, 'sort' => 1],
-    ['name' => 'afand', 'cfg' => $afand_phone, 'opened' => false, 'sort' => 1]];
+    ['name' => 'afand', 'cfg' => $afand_phone, 'opened' => false, 'sort' => 1],
+    ['name' => 'afandeng', 'cfg' => $afandeng_phone, 'opened' => false, 'sort' => 1]];
 $config['phone_providers'] = $phone_providers;

+ 2 - 1
helper/fcgi_server.php

@@ -31,7 +31,8 @@ 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','refill_tianx.php','refill_afand.php'
+            'bridge_shr.php','refill_weit.php','refill_tianx.php','refill_afand.php',
+            'refill_afandeng.php'
         ];
         $path = BASE_ROOT_PATH . '/mobile/';
         $file = str_replace($path,'',$file);

+ 3 - 0
helper/refill/RefillFactory.php

@@ -77,6 +77,9 @@ require_once(BASE_HELPER_PATH . '/refill/tianx/RefillCallBack.php');
 require_once(BASE_HELPER_PATH . '/refill/afand/RefillPhone.php');
 require_once(BASE_HELPER_PATH . '/refill/afand/RefillCallBack.php');
 
+require_once(BASE_HELPER_PATH . '/refill/afandeng/RefillPhone.php');
+require_once(BASE_HELPER_PATH . '/refill/afandeng/RefillCallBack.php');
+
 use Log;
 use mtopcard;
 use QueueClient;

+ 55 - 0
helper/refill/afandeng/RefillCallBack.php

@@ -0,0 +1,55 @@
+<?php
+
+
+namespace refill\afandeng;
+
+require_once(BASE_HELPER_PATH . '/refill/afandeng/config.php');
+
+
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = $this->sign($params);
+        if ($params['signstr'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = $params['code'] . $params['tradeNoThird'] .$params['msg'] . $params['tradeNo'] . config::KEY;
+        if(empty($params['tradeNo'])) {
+            $content = $params['code'] . $params['tradeNoThird'] .$params['msg'] . config::KEY;
+        }
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['code']);
+        $order_sn = $params['tradeNoThird'];
+        $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['tradeNo']) == 'null' ? '' : $params['tradeNo'];
+
+        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];
+        }
+    }
+}

+ 83 - 0
helper/refill/afandeng/RefillPhone.php

@@ -0,0 +1,83 @@
+<?php
+
+namespace refill\afandeng;
+
+require_once(BASE_HELPER_PATH . '/refill/afandeng/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['merchantId'] = config::MCHID;
+        $params['orderType'] = 1;
+        $params['mobile'] = $phone;
+        $params['tradeNoThird'] = $order_sn;
+        $params['amount'] = sprintf("%.2f" , $amount);
+        $params['notifyUrl'] = config::NOTIFY_URL;
+
+        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['signstr'] = $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'] == 200) {
+                return [true, $resp['body']['tradeNoSelf']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['merchantId'] = config::MCHID;
+        $params['tradeNoThird'] = $refill_info['order_sn'];
+        $content = $params['merchantId'] . $params['tradeNoThird'] . config::KEY;
+        $params['signstr'] = md5($content);
+        $resp = http_request(config::QUERY_URL, $params , 'GET' , false);
+        if ($resp === false) {
+            return [false, '系统错误'];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            $order_state = '';
+            if ($resp['code'] == 200) {
+                $order_state = ORDER_STATE_SUCCESS;
+            } elseif ($resp['code'] == 604) {
+                $order_state = ORDER_STATE_CANCEL;
+            } elseif ($resp['code'] == 603){
+                $order_state = ORDER_STATE_SEND;
+            }
+            if (empty($order_state)) {
+                return [false, $resp['msg']];
+            }
+            return [true, $order_state];
+        }
+    }
+
+    private function sign($params)
+    {
+        $key = config::KEY;
+        $content = $params['merchantId'] . $params['orderType'] . $params['mobile'] . $params['tradeNoThird'] . $params['amount'] . $params['notifyUrl'] . $key;
+        return md5($content);
+    }
+}

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

@@ -0,0 +1,16 @@
+<?php
+
+
+namespace refill\afandeng;
+
+
+class config
+{
+    const ORDER_URL = 'http://8.135.117.151:8124/supply/order/orderCheck';
+    const QUERY_URL = 'http://8.135.117.151:8124/supply/order/getSupplyOrderStatus';
+
+    const MCHID = 131;
+    const KEY = '4356f096d6ff947da4918e40bedc444e';
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/refill_afandeng.php";
+    const ExtHeaders = ['ContentType: application/x-www-form-urlencoded;charset=utf-8'];
+}

+ 9 - 0
mobile/refill_afandeng.php

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

+ 6 - 0
test/TestRefill.php

@@ -114,6 +114,12 @@ class TestRefill extends TestCase
         }
     }
 
+    public function testAfandengPhone()
+    {
+        $providers = new refill\afandeng\RefillPhone([]);
+        $resp = $providers->add(13699279618, 4, 30, ['order_sn' => $this->make_sn()]);
+    }
+
     public function testYifaPhone()
     {
         $providers = new refill\yifa\RefillPhone([]);