xiaoyu 3 年之前
父節點
當前提交
243a27304a

+ 9 - 0
helper/refill/api/xyz/huoli/API信息.txt

@@ -0,0 +1,9 @@
+平台地址:http://v3.biyingniao.com/
+商户账号:18511780488
+商户密码:123456
+
+appkey:expzye
+appSecret:d6f1f8ba1fd8f050d83e65f069bd5d1c
+
+接口文档
+https://www.showdoc.com.cn/1107597888225869/7829958226183111

+ 45 - 0
helper/refill/api/xyz/huoli/RefillCallBack.php

@@ -0,0 +1,45 @@
+<?php
+namespace refill\huoli;
+
+require_once(BASE_HELPER_RAPI_PATH . '/huoli/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)
+    {
+        $app_key = config::APP_KEY;
+        $content = "app_key={$app_key}&out_trade_no={$params['out_trade_no']}&status={$params['status']}";
+        $content .= config::APP_SECRET;
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $order_sn = $params['out_trade_no'];
+        $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'];
+        $status = intval($params['status']);
+        if ($status === 2) {
+            return [$order_id, true, false, true];
+        } elseif ($status === 1) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 98 - 0
helper/refill/api/xyz/huoli/RefillPhone.php

@@ -0,0 +1,98 @@
+<?php
+namespace refill\huoli;
+
+require_once(BASE_HELPER_RAPI_PATH . '/huoli/config.php');
+
+use refill;
+use Log;
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $phone, int $amount, string $order_sn)
+    {
+        $params['out_trade_no'] = "$order_sn";
+        $params['phone'] = "$phone";
+        $params['way'] = 6;
+        $params['amount'] = "$amount";
+        return $params;
+    }
+
+    private function createHeader(): array
+    {
+        $time = time();
+        $sign = $this->sign($time);
+        return [
+            'app-key:'.config::APP_KEY,
+            'sign:'.$sign,
+            't:'.$time,
+            'v:'.config::Version,
+            'Content-Type: application/json;charset=UTF-8'
+        ];
+    }
+
+    public function add($card_no, $card_type, $amount, $input, &$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $amount, $input['order_sn']);
+
+        $params = json_encode($params);
+        $header = $this->createHeader();
+        $resp = http_post_data(config::ORDER_URL, $params , $header, $net_errno);
+
+        if (empty($resp)) {
+            return [false, '系统错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            $code = $resp['code'];
+
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif ($code === 0) {
+                return [true, $resp['data']['order_no'], false];
+            } else {
+                return [false, $resp['message'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        return [false, '不支持单个订单查询 '];
+    }
+
+    public function balance()
+    {
+        $header = $this->createHeader();
+        $resp = http_request(config::BALANCE_URL, [], 'GET', false, $header);
+
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            $code = $resp['code'];
+
+            if (empty($resp)) {
+                return [false, '系统错误'];
+            } elseif ($code === 0) {
+                return [true, $resp['data']['amount']];
+            } else {
+                return [false, $resp['message']];
+            }
+        }
+    }
+
+    private function sign($time)
+    {
+        $content = config::Version . config::APP_SECRET . $time . config::APP_SECRET;
+        return md5($content);
+    }
+}

+ 15 - 0
helper/refill/api/xyz/huoli/config.php

@@ -0,0 +1,15 @@
+<?php
+namespace refill\huoli;
+
+class config
+{
+    //回调地址 需在上游后台配置
+    const ORDER_URL = 'https://v3.biyingniao.com/api/v3/resource/phone/create';
+    const QUERY_URL = 'https://v3.biyingniao.com/api/v3/equity/order/list';
+    const BALANCE_URL = 'https://v3.biyingniao.com/api/v3/goods/brand_coupon/amount';
+
+    const APP_KEY = 'expzye';
+    const APP_SECRET = 'd6f1f8ba1fd8f050d83e65f069bd5d1c';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_huoli.php";
+    const Version = '3.0';
+}

+ 1 - 1
helper/refill/api/xyz/lexiang/account.txt

@@ -1,4 +1,4 @@
-http://buy.mallka.cc/ 
+http://buy.mallka.cc/
 YEZI
 123456
 

+ 5 - 0
mobile/callback/refill_huoli.php

@@ -0,0 +1,5 @@
+<?php
+
+$content = $_SERVER['post_content'] ?? [];
+$input = json_decode($content,true);
+refill\util::push_notify('huoli',$input);

+ 15 - 1
test/TestRefill.php

@@ -1880,7 +1880,7 @@ class TestRefill extends TestCase
     {
         $provider = $this->getProvider('jianjiao');
 //        $resp = $provider->balance();
-        $resp = $provider->add(136992796, 4, 50, ['order_sn' => $this->make_sn()]);
+        $resp = $provider->add(13699279618, 4, 50, ['order_sn' => $this->make_sn()]);
 //        $resp = $provider->query(['order_sn' => '14481646204704630736']);
 
 //        $body = '{"order_id":"22030215052639807","out_order_id":"14481646204704630736","status":3,"mobile":"13699279618","amount":50,"app_key":"3l6kd2yqsvcwftij","official_sn":"","timestamp":1646205722,"sign":"db77f48b8964b74e9c5e44fa9b3dcf49"}';
@@ -1890,6 +1890,20 @@ class TestRefill extends TestCase
 //        $resp = $provider->notify($params);
     }
 
+    public function testHuoli()
+    {
+//        $provider = $this->getProvider('huoli');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(13699279618, 4, 50, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '89741646294399883574']);
+
+        $body = '{"app_key":"expzye","out_trade_no":"89741646294399883574","sign":"24adfe57f5ada22db154d4ed4b4b8e5f","status":2}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('huoli','RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);