浏览代码

beixt helper add test update

ayHaru 4 年之前
父节点
当前提交
da8daf253f
共有 4 个文件被更改,包括 109 次插入0 次删除
  1. 26 0
      helper/refill/beixt/RefillCallBack.php
  2. 60 0
      helper/refill/beixt/RefillPhone.php
  3. 14 0
      helper/refill/beixt/config.php
  4. 9 0
      test/TestRefill.php

+ 26 - 0
helper/refill/beixt/RefillCallBack.php

@@ -0,0 +1,26 @@
+<?php
+
+
+namespace refill\beixt;
+
+use refill;
+
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+
+    public function verify($params) : bool
+    {
+        return true;
+    }
+
+    public function onOil($params)
+    {
+
+    }
+
+    public function onPhone($params)
+    {
+        // TODO: Implement onPhone() method.
+    }
+}

+ 60 - 0
helper/refill/beixt/RefillPhone.php

@@ -0,0 +1,60 @@
+<?php
+namespace refill\beixt;
+
+require_once(BASE_HELPER_PATH . '/refill/beixt/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone
+{
+    private function req_params(int $phone, int $amount ,string $order_sn)
+    {
+        $params['phone'] = $phone;
+        $params['product_id'] = $amount;
+        $params['tradeNo'] = $order_sn;
+        $params['notify_url'] = config::NOTIFY_URL;
+
+        return json_encode($params);
+    }
+
+    public function add($phone,$amount,$order_sn)
+    {
+        $params = $this->req_params($phone,$amount,$order_sn);
+        $time = time();
+        $api_user_name = config::API_USER_NAME;
+        $sign = $this->sign($time);
+
+        $header = [
+            'Content-Type: application/json',
+            "API-USER-NAME: {$api_user_name}",
+            "API-NAME: OrderCreate",
+            "API-TIMESTAMP: {$time}",
+            "API-SIGNATURE: {$sign}",
+        ];
+        $resp = http_post_data(config::REQUEST_URL,$params,$header);
+        if($resp === false) {
+            return [false,'系统错误'];
+        }
+        else
+        {
+            Log::record($resp,Log::DEBUG);
+            $resp = json_decode($resp,true);
+            if($resp['state'] == 0) {
+                return [true,$resp['data']];
+            }
+            else {
+                return [false,$resp['msg']];
+            }
+        }
+    }
+
+    private function sign($time)
+    {
+        $ip = config::API_IP;
+        $cert = config::API_CERT;
+        $content = $ip.$time.$cert;
+
+        return md5($content);
+    }
+}

+ 14 - 0
helper/refill/beixt/config.php

@@ -0,0 +1,14 @@
+<?php
+
+
+namespace refill\beixt;
+
+
+class config
+{
+    const REQUEST_URL = 'http://8.129.76.127/APIHfKc/v2/';
+    const API_USER_NAME= '2cf54e1fcd1944e102114c56cf9fe4ca';
+    const API_CERT = '2f889d471d2e34a8219dce36e51621c8';
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/signature.php";
+    const API_IP = '111.193.234.45';
+}

+ 9 - 0
test/TestRefill.php

@@ -14,6 +14,7 @@ require_once(BASE_CORE_PATH . '/framework/function/http.php');
 require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
 require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
 require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
 require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
 
 
+require_once(BASE_HELPER_PATH . '/refill/beixt/RefillPhone.php');
 class TestRefill extends TestCase
 class TestRefill extends TestCase
 {
 {
     public static function setUpBeforeClass(): void
     public static function setUpBeforeClass(): void
@@ -37,6 +38,14 @@ class TestRefill extends TestCase
         }
         }
     }
     }
 
 
+    public function testRefillPhone()
+    {
+        $providers = new \refill\beixt\RefillPhone();
+        $resp = $providers->add(18500608333,50,'200649600557718888');
+        //{"ack":"success","message":{"order_number":13281474,"charged_amount":"48.750","shipping_status":"5","shipping_status_desc":"未发货"}}
+        // content={"order_number":13281474,"shipping_status":1,"shipping_status_desc":"已发货","shipping_status_message":"","sign":"05863f9931ed69a70e456222f057dfdd","voucher":"110103307162012081746340295254","vouchertype":"","voucherurl":"","tradeNo":"200649600557718888"}
+    }
+
     public function testAddoil()
     public function testAddoil()
     {
     {
         $params = ['mchid' => 1,'cardno' => '1000111100021211884','amount' => "100","act"=>"refill","op"=>"addoil",
         $params = ['mchid' => 1,'cardno' => '1000111100021211884','amount' => "100","act"=>"refill","op"=>"addoil",