瀏覽代碼

add yifa api

stanley-king 4 年之前
父節點
當前提交
e07d27a0b4

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

@@ -94,6 +94,6 @@ $phone_providers = [
     ['name' => 'beixt', 'cfg' => $beixt_phone, 'opened' => false, 'sort' => 1],
     ['name' => 'bxtwt', 'cfg' => $bxtwt_phone, 'opened' => false, 'sort' => 2],
     ['name' => 'bjb', 'cfg' => $bjb_phone, 'opened' => false, 'sort' => 2],
-    ['name' => 'yifa', 'cfg' => $yifa_phone, 'opened' => false, 'sort' => 5],
-    ['name' => 'jiec', 'cfg' => $jiec_phone, 'opened' => true, 'sort' => 1]];
+    ['name' => 'yifa', 'cfg' => $yifa_phone, 'opened' => true, 'sort' => 5],
+    ['name' => 'jiec', 'cfg' => $jiec_phone, 'opened' => false, 'sort' => 1]];
 $config['phone_providers'] = $phone_providers;

+ 1 - 1
helper/fcgi_server.php

@@ -30,7 +30,7 @@ class fcgi_server
             'signature.php',
             '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_zzx.php','refill_inner.php','refill_jiec.php','refill_yifa.php',
             'bridge_shr.php'
         ];
         $path = BASE_ROOT_PATH . '/mobile/';

+ 15 - 22
helper/refill/yifa/RefillCallBack.php

@@ -13,44 +13,33 @@ class RefillCallBack implements refill\IRefillCallBack
     public function verify($params): bool
     {
         $sign = $this->sign($params);
-        if ($params['sgn'] == $sign) {
+        if ($params['sign'] == $sign) {
             return true;
         } else {
             return false;
         }
     }
 
-    private function check_empty($value)
-    {
-        if (!isset($value))
-            return true;
-        if ($value === null)
-            return true;
-        if (trim($value) === "")
-            return true;
-
-        return false;
-    }
-
     private function sign($params)
     {
         ksort($params);
 
         $app_secret = config::APP_SECRET;
-        $body = $app_secret;
-        foreach ($params as $k => $v) {
-            if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
-                $body .= "{$k}{$v}";
+        $content = $app_secret;
+        foreach ($params as $key => $val)
+        {
+            if(empty($val)){
+                continue;
             }
+            $content .= "{$key}{$val}";
         }
-
-        $body .= "&key=" . $app_secret;
-        return strtoupper(md5($body));
+        $content .= $app_secret;
+        return strtoupper(md5($content));
     }
 
     public function notify($params)
     {
-        $status = intval($params['status']);
+        $status = $params['status'];
         $order_sn = $params['coder_order_sn'];
         $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
         if (empty($order_info)) {
@@ -63,8 +52,12 @@ class RefillCallBack implements refill\IRefillCallBack
 
         if ($status === 'success') {
             return [$order_id, true, false,true,true];
-        } elseif ($status === 2) {
+        }
+        elseif ($status === 'fail') {
             return [$order_id, false, true,true,true];
         }
+        else {
+            return [$order_id, false, false,false];
+        }
     }
 }

+ 15 - 11
helper/refill/yifa/RefillPhone.php

@@ -17,6 +17,7 @@ class RefillPhone extends refill\IRefillPhone
     {
         $params['app_id'] = config::APP_ID;
         $params['nonce_str'] = strtoupper($this->createNoncestr());
+
         $params['timestamp'] = time();
         $params['order_sn'] = $order_sn;
         $params['phone'] = $phone;
@@ -30,21 +31,23 @@ class RefillPhone extends refill\IRefillPhone
         $order_sn = $params['order_sn'];
         $params = $this->req_params($card_no,$amount,$order_sn);
         $sign = $this->sign($params);
-        $params['sgn'] = $sign;
-        $resp = http_post_data(config::ORDER_URL,json_encode($params),config::ExtHeaders);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL,$params,'POST',false,config::ExtHeaders);
         if($resp === false) {
             return [false,'系统错误'];
         }
-        else
-        {
-            if($resp['code'] == 10000 && $resp['message'] == 'SUCCESS') {
-                return [true,''];
-            }
-            else {
-                return [false,$resp[1]];
-            }
+
+        $resp = json_decode($resp,true);
+        if($resp['code'] == 10000 && $resp['message'] == 'SUCCESS') {
+            $result = $resp['result'];
+            return [true,$result['order_sn']];
+        }
+        else {
+            return [false,$resp['message']];
         }
     }
+
     public function query($refill_info)
     {
 
@@ -65,8 +68,9 @@ class RefillPhone extends refill\IRefillPhone
 
     private function sign($params)
     {
-        $app_secret = config::APP_SECRET;
         ksort($params);
+
+        $app_secret = config::APP_SECRET;
         $content = $app_secret;
         foreach ($params as $key => $val)
         {

+ 0 - 1
helper/refill/yifa/config.php

@@ -10,6 +10,5 @@ class config
     const APP_ID= 'e4a61b2acf1119c72c1ed9b61781494e';
     const APP_SECRET = '97a4f0c19b4b34578df4a65b5daddf50b7cb9ba02d3690d015f747a5feef1381';
     const NOTIFY_URL = "https://www.xyzshops.cn/mobile/refill_yifa.php";
-    const API_IP = NET_IP;
     const ExtHeaders = ['Accept:application/json;charset=UTF-8;'];
 }

+ 3 - 1
mobile/refill_yifa.php

@@ -2,7 +2,9 @@
 
 require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
 
-refill\RefillFactory::instance()->notify('yifa',$_POST);
+$content = $_SERVER['post_content'];
+$input = json_decode($content,true);
+refill\RefillFactory::instance()->notify('yifa',$input);
 
 echo ('success');
 

+ 5 - 6
test/TestRefill.php

@@ -87,6 +87,11 @@ class TestRefill extends TestCase
         $resp = $providers->add(18500608333, 5, 100, ['order_sn' => $this->make_sn()]);
     }
 
+    public function testYifaPhone(){
+        $providers = new refill\yifa\RefillPhone([]);
+        $resp = $providers->add(15120035568, 5, 100, ['order_sn' => $this->make_sn()]);
+    }
+
     public function testXcQuery(){
         $providers = new refill\xc\RefillPhone([]);
         $refill_info = ['order_sn' => 950663423236726632 , 'ch_trade_no' => 499 , 'card_no' => 	1000111200005252927	];
@@ -99,12 +104,6 @@ class TestRefill extends TestCase
         $resp = $providers->query($refill_info);
     }
 
-    public function testYifaPhone()
-    {
-        $providers = new refill\yifa\RefillPhone([]);
-        $resp = $providers->add(1000111100021211884, 4, 100, ['order_sn' => $this->make_sn()]);
-    }
-
     public function testSaihuOil()
     {
         $providers = new refill\saihu\RefillOil([]);