Kaynağa Gözat

chizeng jinxin

xiaoyu 3 yıl önce
ebeveyn
işleme
4a19a2b42c

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

@@ -2629,6 +2629,51 @@ $duojing_phone = ['name' => 'duojing', 'store_id' => 132, 'qualitys' => '2',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$chizeng_phone = ['name' => 'chizeng', 'store_id' => 133, 'qualitys' => '1',
+    'amount' => [
+//        10 => [
+//            ['goods_id' => 7147, 'price' => 9.51, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7147, 'price' => 9.45, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7147, 'price' => 9.49, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ],
+//        20 => [
+//            ['goods_id' => 7148, 'price' => 19.02, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7148, 'price' => 18.9, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7148, 'price' => 18.98, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ],
+        30 => [
+            ['goods_id' => 7149, 'price' => 28.53, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7149, 'price' => 28.35, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7149, 'price' => 28.47, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        50 => [
+            ['goods_id' => 7150, 'price' => 47.55, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7150, 'price' => 47.25, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7150, 'price' => 47.45, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        100 => [
+            ['goods_id' => 7151, 'price' => 95.1, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7151, 'price' => 94.5, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7151, 'price' => 94.9, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 7152, 'price' => 190.2, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 7152, 'price' => 189, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 7152, 'price' => 189.8, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+//        300 => [
+//            ['goods_id' => 7153, 'price' => 285.3, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7153, 'price' => 283.5, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7153, 'price' => 284.7, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ],
+//        500 => [
+//            ['goods_id' => 7154, 'price' => 475.5, 'quality' => 1, 'card_type' => 'chinamobile'],
+//            ['goods_id' => 7154, 'price' => 472.5, 'quality' => 1, 'card_type' => 'chinaunicom'],
+//            ['goods_id' => 7154, 'price' => 474.5, 'quality' => 1, 'card_type' => 'chinatelecom']
+//        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -2728,7 +2773,8 @@ $phone_providers = [
     ['name' => 'dashang', 'cfg' => $dashang_phone],
     ['name' => 'yuanta', 'cfg' => $yuanta_phone],
     ['name' => 'menggu_hf', 'cfg' => $menggu_hf_phone],
-    ['name' => 'duojing', 'cfg' => $duojing_phone]
+    ['name' => 'duojing', 'cfg' => $duojing_phone],
+    ['name' => 'chizeng', 'cfg' => $chizeng_phone]
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 50 - 0
helper/refill/api/xyz/chizeng/RefillCallBack.php

@@ -0,0 +1,50 @@
+<?php
+namespace refill\chizeng;
+
+require_once(BASE_HELPER_RAPI_PATH . '/chizeng/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = $this->sign($params);
+        if ($params['szVerifyString'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "szAgentId={$userid}&szOrderId={$params['szOrderId']}&szPhoneNum={$params['szPhoneNum']}&nDemo={$params['nDemo']}&fSalePrice={$params['fSalePrice']}";
+        $content .= "&nFlag={$params['nFlag']}&szKey={$key}";
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['nFlag']);
+        $order_sn = $params['szOrderId'];
+        $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['szRtnMsg']) == 'null' ? '' : $params['szRtnMsg'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 3) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 136 - 0
helper/refill/api/xyz/chizeng/RefillPhone.php

@@ -0,0 +1,136 @@
+<?php
+
+namespace refill\chizeng;
+
+require_once(BASE_HELPER_RAPI_PATH . '/chizeng/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['szAgentId'] = config::USER_ID;
+        $params['szOrderId'] = $order_sn;
+        $params['szPhoneNum'] = $phone;
+        $params['nMoney'] = $amount;
+        $params['nSortType'] = config::operator[$card_type];
+        $params['nProductClass'] = 1;
+        $params['nProductType'] = 1;
+        $params['szTimeStamp'] = date("Y-m-d H:i:s");
+        $params['szNotifyUrl'] = config::NOTIFY_URL;
+        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);
+
+        $sign = $this->sign($params);
+        $params['szVerifyString'] = $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);
+            $nRtn = intval($resp['nRtn']);
+            if (empty($resp)) {
+                return [false, '网络错误', true];
+            } elseif ($nRtn === 0) {
+                return [true, '', false];
+            } elseif (in_array($nRtn, config::ERR_NOS)) {
+                return [false, $resp['szRtnCode'], false];
+            } elseif (in_array($nRtn, [2050, 999])) {
+                $net_errno = "HTTP-{$nRtn}";
+                return [false, $resp['szRtnCode'], false];
+            } else {
+                $err = 998;
+                $net_errno = "HTTP-{$err}";
+                return [false, $resp['szRtnCode'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['szAgentId'] = config::USER_ID;
+        $params['szOrderId'] = $refill_info['order_sn'];
+        $key = config::KEY;
+        $content = "szAgentId={$params['szAgentId']}&szOrderId={$params['szOrderId']}&szKey={$key}";
+        $params['szVerifyString'] = 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 = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            }
+            $status = intval($resp['nRtn']);
+            if ($status === 5012) {
+                $updata['official_sn'] = $resp['szRtnMsg'];
+                Model('refill_order')->edit($refill_info['order_id'], $updata);
+                $order_state = ORDER_STATE_SUCCESS;
+            } elseif ($status === 5013) {
+                $order_state = ORDER_STATE_CANCEL;
+            } elseif (in_array($status, [5011,5019])) {
+                $order_state = ORDER_STATE_SEND;
+            } else {
+                return [false, $status];
+            }
+            return [true, $order_state];
+        }
+    }
+
+    public function balance()
+    {
+        $params['szAgentId'] = config::USER_ID;
+        $key = config::KEY;
+        $content = "szAgentId={$params['szAgentId']}&szKey={$key}";
+        $params['szVerifyString'] = 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 = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            } elseif ($resp['nRtn'] == 0) {
+                return [true, $resp['fBalance']];
+            } else {
+                return [false, $resp['szRtnCode']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $userid = config::USER_ID;
+        $key = config::KEY;
+        $content = "szAgentId={$userid}&szOrderId={$params['szOrderId']}&szPhoneNum={$params['szPhoneNum']}&nMoney={$params['nMoney']}&nSortType={$params['nSortType']}";
+        $content .= "&nProductClass={$params['nProductClass']}&nProductType={$params['nProductType']}&szTimeStamp={$params['szTimeStamp']}&szKey={$key}";
+        return md5($content);
+    }
+}

+ 20 - 0
helper/refill/api/xyz/chizeng/api.txt

@@ -0,0 +1,20 @@
+正式环境:
+
+话费下单地址:http://120.27.219.88:10186/plat/api/old/submitorder
+
+
+查询地址:http://120.27.219.88:10186/plat/api/old/queryorder
+
+
+查询余额地址:http://120.27.219.88:10186/plat/api/old/queryBalance
+
+
+
+ID:200017
+秘钥:dd514d9c1c954f2b90d7faf25e2a7747
+
+
+对接文档地址:https://docs.qq.com/doc/DWkV1VkxQVk13eEtQ
+
+账号:yezi
+密码: 123456

+ 26 - 0
helper/refill/api/xyz/chizeng/config.php

@@ -0,0 +1,26 @@
+<?php
+
+
+namespace refill\chizeng;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://120.27.219.88:10186/plat/api/old/submitorder';
+    const QUERY_URL= 'http://120.27.219.88:10186/plat/api/old/queryorder';
+    const BALANCE_URL= 'http://120.27.219.88:10186/plat/api/old/queryBalance';
+
+    const USER_ID= '200017';
+    const KEY = 'dd514d9c1c954f2b90d7faf25e2a7747';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_chizeng.php";
+    const operator = [
+        mtopcard\ChinaMobileCard  => 1,
+        mtopcard\ChinaUnicomCard  => 2,
+        mtopcard\ChinaTelecomCard => 3
+    ];
+    const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
+
+    const ERR_NOS = [
+        1000,1001,1003,1004,2001,2002,2003,2020,2021,1006,2030,3003
+    ];
+}

+ 70 - 0
helper/refill/api/xyz/jinxin/RefillCallBack.php

@@ -0,0 +1,70 @@
+<?php
+namespace refill\jinxin;
+
+require_once(BASE_HELPER_RAPI_PATH . '/jinxin/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        unset($input['supplierNo']);
+        $sign = $this->sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            if(false === $this->check_empty($val)) {
+                $content .= "{$key}={$val}&";
+            }
+        }
+        $key = config::KEY;
+        $content .= "appKey={$key}";
+
+        return strtoupper(md5($content));
+    }
+
+    protected function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['requestId'];
+        $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) {
+            Model('refill_order')->edit($order_id, ['official_sn' =>$params['supplierNo'] ]);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 2) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 150 - 0
helper/refill/api/xyz/jinxin/RefillPhone.php

@@ -0,0 +1,150 @@
+<?php
+
+namespace refill\jinxin;
+
+require_once(BASE_HELPER_RAPI_PATH . '/jinxin/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['userId'] = config::USER_ID;
+        $params['timeStamp'] = date("Y-m-d H:i:s");
+        $params['rechargeNo'] = $phone;
+        $params['rechargeAmount'] = $amount;
+        $params['supplier'] = config::operator[$card_type];
+        $params['goodsType'] = 1;
+        $params['rechargeType'] = 11;
+        $params['requestId'] = $order_sn;
+        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);
+
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+        $params = json_encode($params);
+
+        $resp = http_post_data(config::ORDER_URL, $params , 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'] === '0000') {
+                return [true, $resp['data']['orderNo'], false];
+            } elseif ($resp['code'] === '9999') {
+                $net_errno = '9999';
+                return [false, $resp['msg'], false];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['userId'] = config::USER_ID;
+        $params['timeStamp'] = date("Y-m-d H:i:s");
+        $params['requestId'] = $refill_info['order_sn'];
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+        $params = json_encode($params);
+
+        $resp = http_post_data(config::QUERY_URL, $params , config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            }
+            if($resp['code'] === '0000')
+            {
+                $status = intval($resp['data']['status']);
+                if ($status === 1) {
+                    Model('refill_order')->edit($refill_info['order_id'], ['official_sn' => $resp['data']['supplierNo']]);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 2) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($status, [0])) {
+                    $order_state = ORDER_STATE_SEND;
+                }else {
+                    return [false, $status];
+                }
+                return [true, $order_state];
+            }
+            elseif($resp['code'] == '0005' && (time() - $refill_info['commit_time'] >= 180))
+            {
+                return [true, ORDER_STATE_NOEXIST];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['supplierId'] = config::USER_ID;
+        $params['timeStamp'] = date("Y-m-d H:i:s");
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+        $params = json_encode($params);
+
+        $resp = http_post_data(config::BALANCE_URL, $params , 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['code'] == '0000')
+            {
+                return [true,$resp['data']['balance']];
+            }
+            else
+            {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $content = '';
+        ksort($params);
+        foreach ($params as $key => $val){
+            if(false === $this->check_empty($val)) {
+                $content .= "{$key}={$val}&";
+            }
+        }
+        $key = config::KEY;
+        $content .= "appKey={$key}";
+
+        return strtoupper(md5($content));
+    }
+}

+ 8 - 0
helper/refill/api/xyz/jinxin/account.txt

@@ -0,0 +1,8 @@
+userId:137
+登录帐号:yezi123456
+登录密码:123456
+密钥:LRygb652kqpt2JoEe5KohdaWLf2YmPdn
+登录地址:http://39.106.26.90:8125/
+提交订单:http://39.106.26.90:8125/api/external/submitOrder
+订单查询:http://39.106.26.90:8125/api/external/queryOrder
+余额查询:http://39.106.26.90:8125/api/external/queryBalance

+ 23 - 0
helper/refill/api/xyz/jinxin/config.php

@@ -0,0 +1,23 @@
+<?php
+
+
+namespace refill\jinxin;
+
+use mtopcard;
+class config
+{
+    //回调地址需在上游配置
+    const ORDER_URL = 'http://39.106.26.90:8125/api/external/submitOrder';
+    const QUERY_URL= 'http://39.106.26.90:8125/api/external/queryOrder';
+    const BALANCE_URL= 'http://39.106.26.90:8125/api/external/queryBalance';
+
+    const USER_ID= '137';
+    const KEY = 'LRygb652kqpt2JoEe5KohdaWLf2YmPdn';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_jinxin.php";
+    const operator = [
+        mtopcard\ChinaMobileCard  => 1,
+        mtopcard\ChinaUnicomCard  => 2,
+        mtopcard\ChinaTelecomCard => 3
+    ];
+    const ExtHeaders = ['Content-Type: application/json'];
+}

+ 4 - 0
mobile/callback/refill_chizeng.php

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

+ 14 - 0
test/TestRefill.php

@@ -1068,6 +1068,20 @@ class TestRefill extends TestCase
 //        $resp = $providers->notify($params);
     }
 
+    public function testChizeng()
+    {
+//        $providers = $this->getProvider('chizeng');
+//        $resp = $providers->balance();
+//        $resp = $providers->add(18500608333, 5, 30, ['order_sn' => $this->make_sn()]);
+//        $resp = $providers->query(['order_sn' => '70391632388843650753']);
+
+        $body = '{"szOrderId":"70391632388843650753","fSalePrice":"28.35","szAgentId":"200017","nFlag":"3","szVerifyString":"784d7c138783265d4f64b943701712ff","szPhoneNum":"18500608333","szRtnMsg":"","nDemo":"30"}';
+        $params = json_decode($body, true);
+        $providers = $this->getProvider('chizeng','RefillCallBack');
+        $ret = $providers->verify($params);
+        $resp = $providers->notify($params);
+    }
+
     public function testAmingjd()
     {
 //        $providers = new refill\amingjd\RefillPhone([]);