Преглед изворни кода

add lingzh provider riying

ayHaru пре 4 година
родитељ
комит
ef7af78aa0

+ 29 - 0
data/config/lingzh/refill.ini.php

@@ -305,6 +305,34 @@ $fensheng_phone = ['name' => 'fensheng', 'store_id' => 45, 'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$riying_phone = ['name' => 'riying', 'store_id' => 49, 'qualitys' => '5',
+    'amount' => [
+        10 => [
+            ['goods_id' => 79, 'price' => 9.2, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ],
+        20 => [
+            ['goods_id' => 80, 'price' => 18.4, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ],
+        30 => [
+            ['goods_id' => 81, 'price' => 27.6, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ],
+        50 => [
+            ['goods_id' => 82, 'price' => 46, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ],
+        100 => [
+            ['goods_id' => 83, 'price' => 92, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ],
+        200 => [
+            ['goods_id' => 84, 'price' => 184, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ],
+        300 => [
+            ['goods_id' => 85, 'price' => 276, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ],
+        500 => [
+            ['goods_id' => 86, 'price' => 460, 'quality' => 5, 'card_type' => 'chinamobile,chinaunicom,chinatelecom'],
+        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
 $phone_providers = [
     ['name' => 'baizeyd', 'cfg' => $baizeyd, 'opened' => true, 'sort' => 1],
     ['name' => 'aming', 'cfg' => $aming_phone, 'opened' => true, 'sort' => 1],
@@ -318,5 +346,6 @@ $phone_providers = [
     ['name' => 'legou', 'cfg' => $legou_phone],
     ['name' => 'feiniao', 'cfg' => $feiniao_phone],
     ['name' => 'fensheng', 'cfg' => $fensheng_phone],
+    ['name' => 'riying', 'cfg' => $riying_phone],
     ];
 $config['phone_providers'] = $phone_providers;

+ 2 - 1
helper/fcgisrv/LZRAccServer.php

@@ -28,7 +28,8 @@ class LZRAccServer extends BaseServer
             'callback/lingzh/baizeyd.php','callback/lingzh/aming.php','callback/lingzh/binghc.php',
             'callback/lingzh/ruishun.php','callback/lingzh/wuchen.php','callback/lingzh/yibao.php',
             'callback/lingzh/amingyd.php','callback/lingzh/chuka.php','callback/lingzh/amingjd.php',
-            'callback/lingzh/legou.php'  ,'callback/lingzh/feiniao.php', 'callback/lingzh/fensheng.php'
+            'callback/lingzh/legou.php'  ,'callback/lingzh/feiniao.php', 'callback/lingzh/fensheng.php',
+            'callback/lingzh/riying.php'
         ];
 
         $this->setExFiles($exfiles);

+ 52 - 0
helper/refill/api/lingzh/riying/RefillCallBack.php

@@ -0,0 +1,52 @@
+<?php
+
+
+namespace refill\riying;
+
+require_once(BASE_HELPER_RAPI_PATH . '/riying/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)
+    {
+        $content  = config::UserId . $params['SysOrderId'] . $params['OrderId'] . $params['State'] . $params['Timestamp'] . config::KEY;
+        return md5($content);
+    }
+
+
+    public function notify($params)
+    {
+        $status = intval($params['State']);
+        $order_sn = $params['OrderId'];
+        $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'];
+        
+        $data['official_sn'] = strtolower($params['VoucherContent']) == 'null' ? '' : $params['VoucherContent'];
+
+        if ($status === 4) {
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 5) {
+            return [$order_id, false, false,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 109 - 0
helper/refill/api/lingzh/riying/RefillPhone.php

@@ -0,0 +1,109 @@
+<?php
+
+namespace refill\riying;
+
+require_once(BASE_HELPER_RAPI_PATH . '/riying/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 $card_type, int $amount, string $order_sn)
+    {
+        $params['OrderId'] = $order_sn;
+        $params['Account'] = $phone;
+        $params['Amount'] = $amount;
+        $params['ShopId'] = config::ShopId;
+        $params['UserId'] = config::UserId;
+        $params['Num'] = 1;
+        $params['ProductType'] = 1;
+        $params['Timestamp'] = $this->getMillisecond();
+        $params['IspTypeId'] = config::Product_type[$card_type];
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params)
+    {
+        $params = $this->req_params($card_no, $card_type, $amount, $params['order_sn']);
+        $sign = $this->sign($params);
+        $params['Sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params);
+        if (empty($resp)) {
+            return [false, '系统错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp ,true);
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            }
+            if($resp['Code'] == 10012) {
+                return [true, $resp['SysOrderId'], false];
+            }
+            return [false , $resp['Message'], false];
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['ShopId'] = config::ShopId;
+        $params['UserId'] = config::UserId;
+        $params['Timestamp'] = $this->getMillisecond();
+        $params['OrderId'] = $refill_info['ch_trade_no'];
+        $content = $params['ShopId'] . $params['UserId']. $params['OrderId'] . $params['Timestamp'] . config::KEY;
+        $params['Sign'] = md5($content);
+
+        $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'] == 4) {
+                $order_state = ORDER_STATE_SUCCESS;
+                $save['official_sn'] = strtolower($resp['VoucherContent']) == 'null' ? '' : $resp['VoucherContent'];
+                Model('refill_order')->edit($refill_info['order_id'], $save);
+            } elseif ($resp['Code'] == 5) {
+                $order_state = ORDER_STATE_CANCEL;
+            } elseif ($resp['Code'] == 0) {
+                $order_state = ORDER_STATE_SEND;
+            } else {
+                return [false, $resp['Message']];
+            }
+            return [true, $order_state];
+        }
+    }
+
+    private function sign($params)
+    {
+        $key = config::KEY;
+        $content  = $params['ShopId'] . $params['UserId'] . $params['ProductType'] . $params['OrderId'] . $params['Account'];
+        $content .= $params['Amount'] . $params['Num'] . $params['Timestamp'] . $key;
+        return md5($content);
+    }
+
+    /**
+     * 获取毫秒级别的时间戳
+     */
+    private static function getMillisecond()
+    {
+        //获取毫秒的时间戳
+        $time = explode ( " ", microtime () );
+        $time = $time[1] . ($time[0] * 1000);
+        $time2 = explode( ".", $time );
+        $time = $time2[0];
+        return $time;
+    }
+}

+ 20 - 0
helper/refill/api/lingzh/riying/config.php

@@ -0,0 +1,20 @@
+<?php
+
+
+namespace refill\riying;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'http://139.196.182.200:8080/order/v1.0/Pay.ashx';
+    const QUERY_URL = 'http://139.196.182.200:9001/v1.0/QueryOrder.ashx';
+
+    const UserId = 10050;
+    const KEY = 'c820c27903b4531c5be34de61c47a3ea';
+    const ShopId = 300017;
+    const Product_type = [
+        mtopcard\ChinaMobileCard => 0,
+        mtopcard\ChinaUnicomCard => 1,
+        mtopcard\ChinaTelecomCard => 2
+    ];
+}

BIN
helper/refill/api/lingzh/riying/日盈业务接口文档.docx


+ 5 - 0
helper/refill/api/lingzh/riying/账号.txt

@@ -0,0 +1,5 @@
+商户编号:10050
+登录账户:lzkjmc
+登录密码:hfmc123456
+密钥:c820c27903b4531c5be34de61c47a3ea
+后台查单地址http://139.196.182.200:8081/

+ 4 - 0
racc/callback/lingzh/riying.php

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

+ 11 - 1
test/TestRefill.php

@@ -332,7 +332,7 @@ class TestRefill extends TestCase
     public function testPrice()
     {
         $amounts = [10, 20, 30, 50, 100, 200, 300, 500];
-        $rate = 0.956;
+        $rate = 0.92;
         foreach ($amounts as $amount) {
             $price[] = $amount * $rate;
         }
@@ -429,6 +429,16 @@ class TestRefill extends TestCase
 //        }
     }
 
+    public function testRiyingPhone()
+    {
+        $providers = new refill\riying\RefillPhone([]);
+//        $resp = $providers->add(13699279618, 4, 30, ['order_sn' => $this->make_sn()]);
+        $resp = $providers->query(['ch_trade_no' => '2021041311120213187423105022']);
+        $data = '{"UserId":"10050","SysOrderId":"2021041311120213187423105022","OrderId":"15641618283518423567","State":"4","Timestamp":"1618283565746","VoucherType":"1","VoucherContent":"511009928000087852","Sign":"a6ec70a3ea42baae941528398c6d0a43"}';
+        $input = json_decode($data, true);
+//        refill\RefillFactory::instance()->notify('riying',$input);
+    }
+
     public function testYunlingPhone()
     {
         $providers = new refill\yunling\RefillPhone([]);