xiaoyu 2 jaren geleden
bovenliggende
commit
4ee3f4eb09

+ 6 - 0
data/config/yl/refill.ini.php

@@ -7253,6 +7253,12 @@ $jiyemei_doubi = ['name' => 'jiyemei_doubi', 'store_id' => 173,'qualitys' => '1'
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$runpu = ['name' => 'runpu', 'store_id' => 261, 'qualitys' => '1',
+    'amount' => [
+        100 => [['goods_id' => 8169, 'price' => 99, 'quality' => 1, 'card_type' => 'third']],
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $third_providers = [
 //    ['name' => 'lingzhthird', 'cfg' => $lingzhthird],
 //    ['name' => 'jumithird', 'cfg' => $jumithird],

BIN
helper/refill/api/yl/runpu/12.27流量无票报价.xlsx


+ 48 - 0
helper/refill/api/yl/runpu/RefillCallBack.php

@@ -0,0 +1,48 @@
+<?php
+namespace refill\runpu;
+
+require_once(BASE_HELPER_RAPI_PATH . '/runpu/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)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "userid={$userid}&orderid={$params['orderid']}&sporderid={$params['sporderid']}&merchantsubmittime={$params['merchantsubmittime']}";
+        $content .= "&resultno={$params['resultno']}&key={$key}";
+        return strtoupper(md5($content));
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['resultno']);
+        $order_sn = $params['sporderid'];
+        $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 === 1) {
+            $data['official_sn'] = strtolower($params['remark1']) == 'null' ? '' : $params['remark1'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true];
+        } elseif ($status === 9) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 196 - 0
helper/refill/api/yl/runpu/RefillPhone.php

@@ -0,0 +1,196 @@
+<?php
+
+namespace refill\runpu;
+
+require_once(BASE_HELPER_RAPI_PATH . '/runpu/config.php');
+
+use refill;
+use Log;
+use mtopcard;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    public function goods($quality, int $amount, int $card_type, $regin_no, $other)
+    {
+        [$goods_id, $price] = parent::goods($quality, $amount, $card_type, $regin_no, $other);
+        if ($goods_id <= 0) return [0, 0];
+
+        $store_id = $this->mStoreID;
+        $pcode = $other['product_code'];
+        $thrid_refill = Model('thrid_refill');
+        $product = $thrid_refill->getProviderProduct($store_id, $goods_id, $pcode);
+        if (empty($product)) {
+            Log::record("cannot find provider's produce where name={$this->mName}, goods_id = {$goods_id} pcode={$pcode}", Log::ERR);
+            return [0, 0];
+        } else {
+            return [$goods_id, ncPriceFormat($product['channel_amount'])];
+        }
+    }
+
+    private function getProductCode($goods_id, $sys_pcode)
+    {
+        $thrid_refill = Model('thrid_refill');
+        $store_id = $this->mStoreID;
+        $product = $thrid_refill->getProviderProduct($store_id, $goods_id, $sys_pcode);
+        if (empty($product)) {
+            return false;
+        } else {
+            return $product['channel_code'];
+        }
+    }
+
+    private function req_params(int $phone, int $amount, $card_type, string $order_sn, $channel_code)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['productid'] = $channel_code;
+        $params['price'] = config::Amounts[$channel_code];
+        $params['num'] = 1;
+        $params['mobile'] = $phone;
+        $params['spordertime'] = date("YmdHis");
+        $params['sporderid'] = $order_sn;
+        $params['back_url'] = config::NOTIFY_URL;
+        $params['paytype'] = config::operator[$card_type];
+
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $order_sn = $params['order_sn'];
+        $goods_id = intval($params['goods_id']);
+        $channel_code = $this->getProductCode($goods_id, $params['product_code']);
+        if(empty($channel_code)) {
+            return [false, '产品有误', false];
+        }
+
+        [$validate, $card_type, $regin_no, $isTransfer, $card_state, $black] = mtopcard\valid_phone($card_no);
+
+        $params = $this->req_params($card_no, $amount, $card_type, $order_sn, $channel_code);
+        if(empty($params['price'])) {
+            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 = $this->xmlToArray($resp);
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            }
+
+            $resultno = $resp['resultno'];
+            if (in_array($resultno, ['0', '2'], true)) {
+                return [true, $resp['orderid'], false];
+            } elseif (in_array($resultno, config::ERR_NOS, true)) {
+                return [false, $resultno, false];
+            } elseif ($resultno === '9999' || $resultno === '5006') {
+                $net_errno = "HTTP-{$resultno}";
+                return [false, $resultno, true];
+            } else {
+                //未知结果码
+                $err = 998;
+                $net_errno = "HTTP-{$err}";
+                return [false, $resultno, true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['userid'] = config::USER_ID;
+        $params['sporderid'] = $refill_info['order_sn'];
+        $key = config::KEY;
+        $content = "userid={$params['userid']}&sporderid={$params['sporderid']}&key={$key}";
+        $params['sign'] = strtoupper(md5($content));
+
+        $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = $this->xmlToArray($resp);
+            if (empty($resp))
+            {
+                return [false, '网络错误'];
+            }
+            else
+            {
+                $resultno = $resp['resultno'];
+                if ($resultno === '1') {
+                    $updata['official_sn'] = $resp['remark1'];
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($resultno === '9') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($resultno, ['0','2'], true)) {
+                    $order_state = ORDER_STATE_SEND;
+                } elseif ($resultno === '5007' && (time() - $refill_info['commit_time'] > 600)) {
+                    $order_state = ORDER_STATE_NOEXIST;
+                } else {
+                    return [false, $resultno];
+                }
+
+                return [true, $order_state];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['userid'] = config::USER_ID;
+        $key = config::KEY;
+        $content = "userid={$params['userid']}&key={$key}";
+        $params['sign'] = strtoupper(md5($content));
+
+        $resp = http_request(config::BALANCE_URL, $params, 'POST', false, config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = $this->xmlToArray($resp);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            } elseif ($resp['resultno'] === '1') {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['resultno']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "userid={$userid}&productid={$params['productid']}&price={$params['price']}&num={$params['num']}&mobile={$params['mobile']}&spordertime={$params['spordertime']}";
+        $content .= "&sporderid={$params['sporderid']}&key={$key}";
+        return strtoupper(md5($content));
+    }
+
+    public function xmlToArray($xml)
+    {
+        $replace_str = str_replace(' ','','encoding="gb2312"');
+        $xml = mb_convert_encoding($xml,"UTF-8","gb2312");
+        $xml = str_replace($replace_str, "encoding='utf-8'", $xml);
+        return refill\util::xmlToArray($xml);
+    }
+}

+ 48 - 0
helper/refill/api/yl/runpu/config.php

@@ -0,0 +1,48 @@
+<?php
+
+
+namespace refill\runpu;
+
+use mtopcard;
+class config
+{
+    //http://www.firstsup.net/showdoc
+    const ORDER_URL = 'http://123.57.216.254:9086/onlinepay.do';
+    const QUERY_URL= 'http://123.57.216.254:9086/searchpay.do';
+    const BALANCE_URL = 'http://123.57.216.254:9086/searchbalance.do';
+
+    const USER_ID= '10005984';
+    const KEY = 'z26Stz8XXyQx7bFyZbr6RxPBekepA3fy';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_runpu.php";
+
+    const operator = [
+        mtopcard\ChinaMobileCard  => 'yd',
+        mtopcard\ChinaUnicomCard  => 'lt',
+        mtopcard\ChinaTelecomCard => 'dx'
+    ];
+    const ERR_NOS = [
+        '5001','5002','5003','5004','5005','5008','5009','5010','5011','5012'
+    ];
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;'];
+
+    const Amounts = [
+        '17639' => 5,
+        '17148' => 7,
+        '17291' => 12,
+        '17293' => 16,
+        '17294' => 30,
+        '30000001650' => 24,
+        '15009' => 20,
+        '30000002330' => 55,
+        '17595' => 80,
+
+        '30000001473' => 10,
+        '30000001474' => 10,
+        '30000001475' => 30,
+
+        '15585' => 15,
+        '15587' => 30,
+        '17621' => 60,
+        '17479' => 80,
+    ];
+}

+ 9 - 0
helper/refill/api/yl/runpu/对接文档.txt

@@ -0,0 +1,9 @@
+后台登录地址:http://123.57.216.254:7080/
+登录名:BJYLWP
+初始密码:SUP123456
+
+用户编号:10005984
+密钥:z26Stz8XXyQx7bFyZbr6RxPBekepA3fy
+充值地址:http://123.57.216.254:9086/onlinepay.do
+查询地址:http://123.57.216.254:9086/searchpay.do
+余额地址:http://123.57.216.254:9086/searchbalance.do

BIN
helper/refill/api/yl/runpu/流量通信充值接口.docx


+ 4 - 0
mobile/callback/refill_runpu.php

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

+ 19 - 1
test/TestRefillYl.php

@@ -914,10 +914,28 @@ class TestRefillYl extends TestCase
         $provider = $this->getProvider('yuewen');
         $resp = $provider->balance();
     }
-    
+
     public function testGuochuang_nation_sec()
     {
         $provider = $this->getProvider('guochuang_nation_sec');
         $resp = $provider->balance();
     }
+
+    public function testRunpu()
+    {
+//        $provider = $this->getProvider('runpu');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(18500608333, 5, 7, [
+//            'order_sn' => $this->make_sn(),
+//            'goods_id' => 7000,
+//            'product_code' => 'XYZ100751'
+//        ]);
+//        $resp = $provider->query(['order_sn' => '21861672134398761461']);
+
+        $body = '{"orderid":"HGL22122717463974142","sporderid":"21861672134398761461","userid":"10005984","merchantsubmittime":"20221227174731","resultno":"1","parvalue":"7","remark1":"","payno":"","fundbalance":"-6.44","sign":"F185CE579EDCB76F2A2991F7E58EF66C"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('runpu', 'RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+    }
 }