ソースを参照

xyz yl yingdian_hf

xiaoyu 2 年 前
コミット
4f11186b57

+ 55 - 0
helper/refill/api/xyz/yingdian_hf/RefillCallBack.php

@@ -0,0 +1,55 @@
+<?php
+namespace refill\yingdian_hf;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yingdian_hf/config.php');
+
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        $sign = $this->sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        unset($params['proof']);
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            $content .= "{$key}=". urlencode($val) ."&";
+        }
+        $content .= "key=".config::KEY;
+
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = $params['state'];
+        $order_sn = $params['outTradeNo'];
+        $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'];
+        if ($status === 'SUCCESS') {
+            Model('refill_order')->edit($order_id, ['official_sn' => $params['proof'], 'ch_trade_no' => $params['orderNo']]);
+            return [$order_id, true, false, true];
+        } elseif ($status === 'FAIL') {
+            Model('refill_order')->edit($order_id, ['ch_trade_no' => $params['orderNo']]);
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 137 - 0
helper/refill/api/xyz/yingdian_hf/RefillPhone.php

@@ -0,0 +1,137 @@
+<?php
+
+namespace refill\yingdian_hf;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yingdian_hf/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $card_no, int $card_type, string $order_sn, int $amount)
+    {
+        $params['merchantId'] = config::MCH_ID;
+        $params['cardNo'] = $card_no;
+        $params['amount'] = $amount;
+        $params['outTradeNo'] = $order_sn;
+        $params['requestTime'] = $this->getMillisecond();
+        $params['notifyUrl'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $card_type, $params['order_sn'], $amount);
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $net_errno);
+        if (empty($resp)) {
+            return [false, '系统错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+
+            $resp = json_decode($resp ,true);
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif ($resp['code'] === 200) {
+                return [true, '', false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['type'] = 'query';
+        $params['merchantId'] = config::MCH_ID;
+        $params['outTradeNo'] = $refill_info['order_sn'];
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::QUERY_URL, $params);
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp))
+            {
+                return [false, '系统错误'];
+            }
+            elseif ($resp['code'] === 200)
+            {
+                $update['ch_trade_no'] = $resp['data']['orderNo'];
+                $status = $resp['data']['state'];
+                if ($status === 'SUCCESS') {
+                    $update['official_sn'] = $resp['data']['proof'];
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 'FAIL') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 'PENDING') {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $status];
+                }
+                Model('refill_order')->edit($refill_info['order_id'], $update);
+
+                return [true, $order_state];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['type'] = 'balance';
+        $params['merchantId'] = config::MCH_ID;
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::BALANCE_URL, $params);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if ($resp['code'] === 200) {
+                return [true, $resp['data']['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            $content .= "{$key}=". urlencode($val) ."&";
+        }
+        $content .= "key=".config::KEY;
+
+        return md5($content);
+    }
+
+    private function getMillisecond()
+    {
+        $cur = microtime (true);
+        return intval($cur * 1000);
+    }
+}

+ 16 - 0
helper/refill/api/xyz/yingdian_hf/config.php

@@ -0,0 +1,16 @@
+<?php
+namespace refill\yingdian_hf;
+
+class config
+{
+    //https://www.showdoc.com.cn/1946422946762386/8847941177523161
+    const ORDER_URL = 'https://yd.khuo.net/api/merchant/recharge/phone';
+    const QUERY_URL = 'https://yd.khuo.net/api/merchant/recharge/queryOrder';
+    const BALANCE_URL = 'https://yd.khuo.net/api/merchant/recharge/queryBalance';
+
+    const MCH_ID = '10026';
+    const KEY = '0c0bc7069f2e4814a9b5a66bb3cbffc8';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_yingdian_hf.php";
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+
+}

+ 3 - 0
helper/refill/api/xyz/yingdian_hf/对接文档.txt

@@ -0,0 +1,3 @@
+商户号 10026
+秘钥 0c0bc7069f2e4814a9b5a66bb3cbffc8
+https://www.showdoc.com.cn/1946422946762386/8847941177523161

+ 55 - 0
helper/refill/api/yl/yingdian_hf/RefillCallBack.php

@@ -0,0 +1,55 @@
+<?php
+namespace refill\yingdian_hf;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yingdian_hf/config.php');
+
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        $sign = $this->sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        unset($params['proof']);
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            $content .= "{$key}=". urlencode($val) ."&";
+        }
+        $content .= "key=".config::KEY;
+
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = $params['state'];
+        $order_sn = $params['outTradeNo'];
+        $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'];
+        if ($status === 'SUCCESS') {
+            Model('refill_order')->edit($order_id, ['official_sn' => $params['proof'], 'ch_trade_no' => $params['orderNo']]);
+            return [$order_id, true, false, true];
+        } elseif ($status === 'FAIL') {
+            Model('refill_order')->edit($order_id, ['ch_trade_no' => $params['orderNo']]);
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 137 - 0
helper/refill/api/yl/yingdian_hf/RefillPhone.php

@@ -0,0 +1,137 @@
+<?php
+
+namespace refill\yingdian_hf;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yingdian_hf/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $card_no, int $card_type, string $order_sn, int $amount)
+    {
+        $params['merchantId'] = config::MCH_ID;
+        $params['cardNo'] = $card_no;
+        $params['amount'] = $amount;
+        $params['outTradeNo'] = $order_sn;
+        $params['requestTime'] = $this->getMillisecond();
+        $params['notifyUrl'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $card_type, $params['order_sn'], $amount);
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params, 'POST', false, config::ExtHeaders, $net_errno);
+        if (empty($resp)) {
+            return [false, '系统错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+
+            $resp = json_decode($resp ,true);
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif ($resp['code'] === 200) {
+                return [true, '', false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['type'] = 'query';
+        $params['merchantId'] = config::MCH_ID;
+        $params['outTradeNo'] = $refill_info['order_sn'];
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::QUERY_URL, $params);
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp))
+            {
+                return [false, '系统错误'];
+            }
+            elseif ($resp['code'] === 200)
+            {
+                $update['ch_trade_no'] = $resp['data']['orderNo'];
+                $status = $resp['data']['state'];
+                if ($status === 'SUCCESS') {
+                    $update['official_sn'] = $resp['data']['proof'];
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 'FAIL') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 'PENDING') {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $status];
+                }
+                Model('refill_order')->edit($refill_info['order_id'], $update);
+
+                return [true, $order_state];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['type'] = 'balance';
+        $params['merchantId'] = config::MCH_ID;
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::BALANCE_URL, $params);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if ($resp['code'] === 200) {
+                return [true, $resp['data']['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            $content .= "{$key}=". urlencode($val) ."&";
+        }
+        $content .= "key=".config::KEY;
+
+        return md5($content);
+    }
+
+    private function getMillisecond()
+    {
+        $cur = microtime (true);
+        return intval($cur * 1000);
+    }
+}

+ 16 - 0
helper/refill/api/yl/yingdian_hf/config.php

@@ -0,0 +1,16 @@
+<?php
+namespace refill\yingdian_hf;
+
+class config
+{
+    //https://www.showdoc.com.cn/1946422946762386/8847941177523161
+    const ORDER_URL = 'https://yd.khuo.net/api/merchant/recharge/phone';
+    const QUERY_URL = 'https://yd.khuo.net/api/merchant/recharge/queryOrder';
+    const BALANCE_URL = 'https://yd.khuo.net/api/merchant/recharge/queryBalance';
+
+    const MCH_ID = '10025';
+    const KEY = '4bebe17dcbde4889957cb0752f09f77a';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_yingdian_hf.php";
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+
+}

+ 3 - 0
helper/refill/api/yl/yingdian_hf/对接文档.txt

@@ -0,0 +1,3 @@
+商户号 10025
+秘钥 4bebe17dcbde4889957cb0752f09f77a
+https://www.showdoc.com.cn/1946422946762386/8847941177523161

+ 4 - 0
mobile/callback/refill_yingdian_hf.php

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

+ 14 - 0
test/TestRefill.php

@@ -2530,6 +2530,20 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testYingdian_hf()
+    {
+//        $provider = $this->getProvider('yingdian_hf');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(15811535608, 4, 50, ['order_sn' => $this->make_sn()]);
+//        $resp = $provider->query(['order_sn' => '95361663137380842711']);
+
+        $body = '{"amount":"50.0","cardNo":"15811535608","merchantId":"10026","orderNo":"20220914143618594153","outTradeNo":"95361663137380842711","requestTime":"2022-09-14 14:36:21","sign":"219f2f45298550c52a4a7e3b98b253a7","state":"FAIL"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('yingdian_hf', 'RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);

+ 6 - 0
test/TestRefillYl.php

@@ -830,4 +830,10 @@ class TestRefillYl extends TestCase
         $provider = $this->getProvider('dazhanggui_high');
         $resp = $provider->balance();
     }
+
+    public function testYingdian_hf()
+    {
+        $provider = $this->getProvider('yingdian_hf');
+        $resp = $provider->balance();
+    }
 }