xiaoyu %!s(int64=3) %!d(string=hai) anos
pai
achega
ab3960504d

+ 15 - 1
data/config/win/refill.ini.php

@@ -1730,6 +1730,19 @@ $moxj_new_phone = ['name' => 'moxj_new', 'store_id' => 97, 'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$kangkai_phone = ['name' => 'kangkai', 'store_id' => 98,'qualitys' => '5',
+    'amount' => [
+        10 => [['goods_id' => 6877, 'price' => 8.85, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        20 => [['goods_id' => 6878, 'price' => 17.7, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        30 => [['goods_id' => 6879, 'price' => 26.55, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        50 => [['goods_id' => 6880, 'price' => 44.25, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        100 => [['goods_id' => 6881, 'price' => 88.5, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        200 => [['goods_id' => 6882, 'price' => 177, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        300 => [['goods_id' => 6883, 'price' => 265.5, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        500 => [['goods_id' => 6884, 'price' => 442.5, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -1797,7 +1810,8 @@ $phone_providers = [
     ['name' => 'yuecheng', 'cfg' => $yuecheng_phone],
     ['name' => 'cangbukami', 'cfg' => $cangbukami_phone],
     ['name' => 'sialan', 'cfg' => $sialan_phone],
-    ['name' => 'moxj_new', 'cfg' => $moxj_new_phone]
+    ['name' => 'moxj_new', 'cfg' => $moxj_new_phone],
+    ['name' => 'kangkai', 'cfg' => $kangkai_phone]
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 15 - 1
data/config/xyz/refill.ini.php

@@ -1730,6 +1730,19 @@ $moxj_new_phone = ['name' => 'moxj_new', 'store_id' => 97, 'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$kangkai_phone = ['name' => 'kangkai', 'store_id' => 98,'qualitys' => '5',
+    'amount' => [
+        10 => [['goods_id' => 6877, 'price' => 8.85, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        20 => [['goods_id' => 6878, 'price' => 17.7, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        30 => [['goods_id' => 6879, 'price' => 26.55, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        50 => [['goods_id' => 6880, 'price' => 44.25, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        100 => [['goods_id' => 6881, 'price' => 88.5, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        200 => [['goods_id' => 6882, 'price' => 177, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        300 => [['goods_id' => 6883, 'price' => 265.5, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        500 => [['goods_id' => 6884, 'price' => 442.5, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -1797,7 +1810,8 @@ $phone_providers = [
     ['name' => 'yuecheng', 'cfg' => $yuecheng_phone],
     ['name' => 'cangbukami', 'cfg' => $cangbukami_phone],
     ['name' => 'sialan', 'cfg' => $sialan_phone],
-    ['name' => 'moxj_new', 'cfg' => $moxj_new_phone]
+    ['name' => 'moxj_new', 'cfg' => $moxj_new_phone],
+    ['name' => 'kangkai', 'cfg' => $kangkai_phone]
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 15 - 1
data/config/xyzadm/refill.ini.php

@@ -1730,6 +1730,19 @@ $moxj_new_phone = ['name' => 'moxj_new', 'store_id' => 97, 'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$kangkai_phone = ['name' => 'kangkai', 'store_id' => 98,'qualitys' => '5',
+    'amount' => [
+        10 => [['goods_id' => 6877, 'price' => 8.85, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        20 => [['goods_id' => 6878, 'price' => 17.7, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        30 => [['goods_id' => 6879, 'price' => 26.55, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        50 => [['goods_id' => 6880, 'price' => 44.25, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        100 => [['goods_id' => 6881, 'price' => 88.5, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        200 => [['goods_id' => 6882, 'price' => 177, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        300 => [['goods_id' => 6883, 'price' => 265.5, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        500 => [['goods_id' => 6884, 'price' => 442.5, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -1797,7 +1810,8 @@ $phone_providers = [
     ['name' => 'yuecheng', 'cfg' => $yuecheng_phone],
     ['name' => 'cangbukami', 'cfg' => $cangbukami_phone],
     ['name' => 'sialan', 'cfg' => $sialan_phone],
-    ['name' => 'moxj_new', 'cfg' => $moxj_new_phone]
+    ['name' => 'moxj_new', 'cfg' => $moxj_new_phone],
+    ['name' => 'kangkai', 'cfg' => $kangkai_phone]
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 79 - 0
helper/refill/api/xyz/kangkai/RefillCallBack.php

@@ -0,0 +1,79 @@
+<?php
+
+
+namespace refill\kangkai;
+
+require_once(BASE_HELPER_RAPI_PATH . '/kangkai/config.php');
+
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $signData['TaskID'] = $params['TaskID'];
+        $signData['Mobile'] = $params['Mobile'];
+        $signData['Status'] = $params['Status'];
+        $signData['ReportTime'] = $params['ReportTime'];
+        $signData['ReportCode'] = $params['ReportCode'];
+        $signData['OutTradeNo'] = $params['OutTradeNo'];
+
+        $sign = $this->sign($signData);
+        if ($params['Sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+    protected function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            if (false === $this->check_empty($val) && "@" != substr($val, 0, 1)) {
+                $val = urldecode($val);
+                $content .= "{$key}={$val}&";
+            }
+        }
+        $content = rtrim($content, '&');
+        $content .= config::ApiKey;
+
+        return md5($content);
+    }
+
+
+    public function notify($params)
+    {
+        $status = intval($params['Status']);
+        $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 === 4) {
+            $data['official_sn'] = strtolower($params['ReceiptNum']) == 'null' ? '' : $params['ReceiptNum'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 5) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 158 - 0
helper/refill/api/xyz/kangkai/RefillPhone.php

@@ -0,0 +1,158 @@
+<?php
+
+namespace refill\kangkai;
+
+require_once(BASE_HELPER_RAPI_PATH . '/kangkai/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $phone, string $order_sn)
+    {
+        $params['OutTradeNo'] = $order_sn;
+        $params['BackUrl'] = config::NOTIFY_URL;
+        $params['Account'] = config::Account;
+        $params['Mobile'] = $phone;
+
+        return $params;
+    }
+
+    public function getPackage($card_type, $amount)
+    {
+        $params['Account'] = config::Account;
+        $params['Type'] = config::operator[$card_type];
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::GET_PACKAGE_URL, $params, 'POST');
+        if (empty($resp)) {
+            return [false, '获取话费包错误:系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp ,true);
+
+            if (empty($resp))
+            {
+                return [false, '获取话费包错误:系统错误'];
+            }
+            elseif($resp['Code'] == 0)
+            {
+                $packages = $resp['Packages'];
+                $result = [];
+                foreach ($packages as $package) {
+                    $result[$package['Package']] = $package;
+                }
+
+                if (array_key_exists($amount, $result)) {
+                    return [true, $result[$amount]['Package']];
+                } else {
+                    return [false, '话费包额度不支持'];
+                }
+            }
+            else
+            {
+                return [false, "获取话费包错误:{$resp['Message']}."];
+            }
+        }
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $params['order_sn']);
+        [$result, $Package] = $this->getPackage($card_type, $amount);
+        if(empty($result)) {
+            return [false, $Package, false];
+        }
+        $params['Package'] = $Package;
+        $sign = $this->sign(['Account' => $params['Account'], 'Mobile' => $params['Mobile'], 'Package' => $Package]);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params, 'POST', false, [], $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'] == 0) {
+                return [true, $resp['TaskID'], false];
+            } elseif ($resp['Code'] == 999) {
+                $net_errno = "HTTP-999";
+                return [false, $resp['Message'], false];
+            } else {
+                return [false, $resp['Message'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['Account'] = config::Account;
+        $params['OutTradeNo'] = $refill_info['order_sn'];
+        $params['SendTime'] = date("Y-m-d");
+        $params['sign'] = $this->sign(['Account' => $params['Account']]);
+
+        $resp = http_request(config::QUERY_URL, $params, 'POST');
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp))
+            {
+                return [false, '系统错误'];
+            }
+            elseif ($resp['Code'] == 0)
+            {
+                $data = $resp['Reports'][0];
+                if ($data['Status'] == 4) {
+                    $order_state = ORDER_STATE_SUCCESS;
+                    $save['official_sn'] = strtolower($data['ReceiptNum']) == 'null' ? '' : $data['ReceiptNum'];
+                    Model('refill_order')->edit($refill_info['order_id'], $save);
+                } elseif (in_array($data['Status'], [3,5])) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($data['Status'] == 2) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $resp['Message']];
+                }
+
+                return [true, $order_state];
+            }
+            else
+            {
+                return [false, $resp['Message']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val) {
+            if (false === $this->check_empty($val) && "@" != substr($val, 0, 1)) {
+                $key = strtolower($key);
+                $content .= "{$key}={$val}&";
+            }
+        }
+        $content .= "key=" . config::ApiKey;
+
+        return md5($content);
+    }
+}

+ 14 - 0
helper/refill/api/xyz/kangkai/account.txt

@@ -0,0 +1,14 @@
+代理管理端:http://8.142.133.14:8081/
+
+代理客户端:http://8.142.133.14:8080/
+
+代理账号:18500608333
+
+密码:a123456(初始密码请及时修改)
+
+客户账号:18500608333
+
+密码:a123456(初始密码请及时修改)
+
+注:进入代理主机  添加白名单IP 绑定回调地址
+注:接口文档请登录代理客户端下载接口文档1.1版本

+ 22 - 0
helper/refill/api/xyz/kangkai/config.php

@@ -0,0 +1,22 @@
+<?php
+
+
+namespace refill\kangkai;
+
+use mtopcard;
+class config
+{
+    //885
+    const ORDER_URL = 'http://8.142.133.14:8080/telapi.aspx?v=H1.1&action=charge';
+    const QUERY_URL = 'http://8.142.133.14:8080/telapi.aspx?v=H1.1&action=queryReport';
+    const GET_PACKAGE_URL = 'http://8.142.133.14:8080/telapi.aspx?v=H1.1&action=getPackage';
+
+    const Account = '18500608333';
+    const ApiKey = '0fa1c183841942659d77747987230da3';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_kangkai.php";
+    const operator = [
+        mtopcard\ChinaMobileCard  => 1,
+        mtopcard\ChinaUnicomCard  => 2,
+        mtopcard\ChinaTelecomCard => 3
+    ];
+}

BIN=BIN
helper/refill/api/xyz/kangkai/商户话费充值协议(1.1).doc


+ 4 - 0
mobile/callback/refill_kangkai.php

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

+ 10 - 0
test/TestRefill.php

@@ -549,6 +549,16 @@ class TestRefill extends TestCase
         refill\RefillFactory::instance()->notify('moxj_new', $params);
     }
 
+    public function testKangkai()
+    {
+        $providers = new refill\kangkai\RefillPhone([]);
+//        $resp = $providers->add(18500608333, 5, 50, ['order_sn' => $this->make_sn()]);
+//        $resp = $providers->query(['order_sn' => '25431627898461762024']);
+        $body = '{"TaskID":"267459","Mobile":"18500608333","Status":"5","ReportTime":"2021-08-02T18:02:01.777","ReportCode":"7:","OutTradeNo":"25431627898461762024","Price":"44.2500","ReceiptNum":"","Sign":"f0934a621fd0b076373f77a9bf8d7051"}';
+        $params = json_decode($body, true);
+        refill\RefillFactory::instance()->notify('kangkai', $params);
+    }
+
     public function testAmingjd()
     {
 //        $providers = new refill\amingjd\RefillPhone([]);