فهرست منبع

xyz lechong_hihh

xiaoyu 2 سال پیش
والد
کامیت
18a90b34e7

+ 51 - 0
helper/refill/api/xyz/lechong_high/RefillCallBack.php

@@ -0,0 +1,51 @@
+<?php
+namespace refill\lechong_high;
+
+require_once(BASE_HELPER_RAPI_PATH . '/lechong_high/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)
+    {
+        $agentcode = config::AgentCode;
+        $key = config::KEY;
+        $content = "{$params['sellerid']}{$agentcode}{$params['account']}{$params['value']}{$params['payvalue']}{$params['voucher']}{$params['createtime']}{$params['endtime']}";
+        $content .= "{$params['state']}{$params['remark']}{$params['time']}{$key}";
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['state']);
+        $order_sn = $params['sellerid'];
+        $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 === 2) {
+            $data['official_sn'] = strtolower($params['voucher']) == 'null' ? '' : $params['voucher'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif (in_array($status, [4,-11])) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 141 - 0
helper/refill/api/xyz/lechong_high/RefillPhone.php

@@ -0,0 +1,141 @@
+<?php
+
+namespace refill\lechong_high;
+
+require_once(BASE_HELPER_RAPI_PATH . '/lechong_high/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, int $card_type, string $order_sn)
+    {
+        $params['agentcode'] = config::AgentCode;
+        $params['sellerid'] = $order_sn;
+        $params['account'] = base64_encode($phone);
+        $params['code'] = config::operator[$card_type][$amount];
+        $params['num'] = 1;
+        $params['value'] = $amount;
+        $params['notifyurl'] = config::NOTIFY_URL;
+        $params['remark'] = '';
+        $params['time'] = date("YmdHis");
+
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $order_sn = $params['order_sn'];
+        $params = $this->req_params($card_no, $amount, $card_type, $order_sn);
+        if(empty($params['code'])) {
+            return [false, '商品编号有误', false];
+        }
+        $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];
+            }
+            $recode = $resp['recode'];
+            if($recode == 's100') {
+                return [true, '', false];
+            } elseif (in_array($recode, ['s115', 's116'])) {
+                $net_errno = "HTTP-{$recode}";
+                return [false, $resp['msg'], true];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['agentcode'] = config::AgentCode;
+        $params['sellerid'] = $refill_info['order_sn'];
+        $params['time'] = date("YmdHis");
+        $key = config::KEY;
+        $body = "{$params['agentcode']}{$params['sellerid']}{$params['time']}{$key}";
+        $params['sign'] = md5($body);
+
+        $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            } elseif ($resp['recode'] == 'q100') {
+                $state = intval($resp['state']);
+                if ($state === 2) {
+                    $updata['official_sn'] = $resp['voucher'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif (in_array($state,[4,-11])) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } else {
+                    $order_state = ORDER_STATE_SEND;
+                }
+                return [true, $order_state];
+            } elseif ($resp['recode'] == 'q106' && (time() - $refill_info['commit_time'] >= 600)){
+                return [true, ORDER_STATE_NOEXIST];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['agentcode'] = config::AgentCode;
+        $params['time'] = date("YmdHis");
+        $key = config::KEY;
+        $body = "{$params['agentcode']}{$params['time']}{$key}";
+        $params['sign'] = md5($body);
+
+        $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            } elseif ($resp['recode'] == 'b100') {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $agentcode = config::AgentCode;
+        $key = config::KEY;
+        $content = "{$agentcode}{$params['sellerid']}{$params['account']}{$params['code']}{$params['num']}{$params['value']}{$params['notifyurl']}{$params['remark']}";
+        $content .= "{$params['time']}{$key}";
+        return md5($content);
+    }
+}

+ 20 - 0
helper/refill/api/xyz/lechong_high/account.txt

@@ -0,0 +1,20 @@
+接口文档:http://121.196.177.34/api/web/#/2
+
+登陆地址:http://121.196.177.34:1012/agent/login
+接口地址:http://121.196.177.34:1012/
+下单地址:http://121.196.177.34:1012/api/md5/submitorder
+余额查询地址:http://121.196.177.34:1012/api/md5/getbalance
+订单查询地址:http://121.196.177.34:1012/api/md5/queryorder
+注册地址:http://121.196.177.34:1012/agent/login
+
+
+商户编号:202210131253
+秘钥:A388AB4D691A474903084D7E0B9A5F57
+
+账号:椰子高价
+密码:yezi131419
+http://121.196.177.34:1012/agent/login
+
+HUAFEI_YIDONG_QUANGUO_50_DJ 50元
+HUAFEI_YIDONG_QUANGUO_100_DJ 100元
+HUAFEI_YIDONG_QUANGUO_200_DJ 200元

+ 25 - 0
helper/refill/api/xyz/lechong_high/config.php

@@ -0,0 +1,25 @@
+<?php
+
+
+namespace refill\lechong_high;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://121.196.177.34:1012/api/md5/submitorder';
+    const QUERY_URL= 'http://121.196.177.34:1012/api/md5/queryorder';
+    const BALANCE_URL= 'http://121.196.177.34:1012/api/md5/getbalance';
+
+    const AgentCode= '202210131253';
+    const KEY = 'A388AB4D691A474903084D7E0B9A5F57';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_lechong_high.php";
+
+    const operator = [
+        mtopcard\ChinaMobileCard  => [
+            50 => 'HUAFEI_YIDONG_QUANGUO_50_DJ',
+            100 => 'HUAFEI_YIDONG_QUANGUO_100_DJ',
+            200 => 'HUAFEI_YIDONG_QUANGUO_200_DJ'
+        ],
+    ];
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+}

+ 4 - 0
mobile/callback/refill_lechong_high.php

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

+ 14 - 0
test/TestRefill.php

@@ -2666,6 +2666,20 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testLechong_high()
+    {
+//        $provider = $this->getProvider('lechong_high');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(15811535608, 4, 50, ['order_sn' => $this->make_sn(), 'regin_no' => 15]);
+//        $resp = $provider->query(['order_sn' => '99381665639827584183']);
+
+        $body = '{"sellerid":"99381665639827584183","agentcode":"202210131253","account":"MTU4MTE1MzU2MDg=","value":"50","payvalue":"48.5000","voucher":"","createtime":"20221013134453","endtime":"20221013134722","state":"4","remark":"","time":"20221013135258","sign":"2e81793ab79297aae39e668c3dfa1a33"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('lechong_high', 'RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);