Browse Source

piaoyi_ylyw

xiaoyu 2 years ago
parent
commit
c12c42d6f6

+ 34 - 0
data/config/xyz/refill.ini.php

@@ -8420,6 +8420,39 @@ $piaoyi_phone = ['name' => 'piaoyi', 'store_id' => 305, 'qualitys' => '3',
     ],
     ],
     'official_sn' => true, 'refill_type' => 'api'];
     'official_sn' => true, 'refill_type' => 'api'];
 
 
+$piaoyi_ylyw_phone = ['name' => 'piaoyi_ylyw', 'store_id' => 306, 'qualitys' => '3',
+    'amount' => [
+//        10 => [['goods_id' => 8528, 'price' => 10.36, 'quality' => 3, 'card_type' => 'chinaunicom']],
+//        20 => [['goods_id' => 8529, 'price' => 20.72, 'quality' => 3, 'card_type' => 'chinaunicom']],
+//        30 => [['goods_id' => 8530, 'price' => 31.08, 'quality' => 3, 'card_type' => 'chinamobile']],
+        50 => [
+            ['goods_id' => 8531, 'price' => 51.8, 'quality' => 3, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8531, 'price' => 51.8, 'quality' => 3, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8531, 'price' => 51.8, 'quality' => 3, 'card_type' => 'chinatelecom'],
+        ],
+        100 => [
+            ['goods_id' => 8532, 'price' => 103.6, 'quality' => 3, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8532, 'price' => 103.6, 'quality' => 3, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8532, 'price' => 103.6, 'quality' => 3, 'card_type' => 'chinatelecom'],
+        ],
+        200 => [
+            ['goods_id' => 8533, 'price' => 207.2, 'quality' => 3, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8533, 'price' => 207.2, 'quality' => 3, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8533, 'price' => 207.2, 'quality' => 3, 'card_type' => 'chinatelecom'],
+        ],
+        300 => [
+            ['goods_id' => 8534, 'price' => 310.8, 'quality' => 3, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8534, 'price' => 310.8, 'quality' => 3, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8534, 'price' => 310.8, 'quality' => 3, 'card_type' => 'chinatelecom'],
+        ],
+        500 => [
+            ['goods_id' => 8535, 'price' => 518, 'quality' => 3, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8535, 'price' => 518, 'quality' => 3, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8535, 'price' => 518, 'quality' => 3, 'card_type' => 'chinatelecom'],
+        ]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -8679,6 +8712,7 @@ $phone_providers = [
     ['name' => 'jiuyi', 'cfg' => $jiuyi_phone],
     ['name' => 'jiuyi', 'cfg' => $jiuyi_phone],
     ['name' => 'siyicheng', 'cfg' => $siyicheng_phone],
     ['name' => 'siyicheng', 'cfg' => $siyicheng_phone],
     ['name' => 'piaoyi', 'cfg' => $piaoyi_phone],
     ['name' => 'piaoyi', 'cfg' => $piaoyi_phone],
+    ['name' => 'piaoyi_ylyw', 'cfg' => $piaoyi_ylyw_phone],
 
 
 ];
 ];
 $config['phone_providers'] = $phone_providers;
 $config['phone_providers'] = $phone_providers;

+ 16 - 0
helper/refill/api/xyz/piaoyi_ylyw/API信息.txt

@@ -0,0 +1,16 @@
+接口文档:
+https://www.showdoc.com.cn/1231131675594800?page_id=6199048649200038
+接口地址在文档上有
+密码:123456
+
+账号登录地址:https://agent.cqpiaoyi.com/
+账号:ylyw
+密码:123456
+对接KEY:e6e07d56496f667322699964394faada
+
+
+绑定白名单:
+47.108.191.216
+47.108.191.235
+47.108.160.38
+47.108.193.136

+ 69 - 0
helper/refill/api/xyz/piaoyi_ylyw/RefillCallBack.php

@@ -0,0 +1,69 @@
+<?php
+namespace refill\piaoyi_ylyw;
+
+require_once(BASE_HELPER_RAPI_PATH . '/piaoyi_ylyw/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        $sign = $this->sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            if($this->check_empty($value) === false) {
+                $content .= "{$key}{$value}";
+            }
+        }
+        $content .= config::KEY;
+        return md5($content);
+    }
+
+    private 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['orderStatus']);
+        $order_sn = $params['outOrderNumber'];
+        $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
+        if (empty($order_info)) {
+            return [false, false, false, false, ''];
+        }
+
+        $order_id = $order_info['order_id'];
+        if ($status === 200) {
+            $official_sn = strtolower($params['brandOrderNumber']) == 'null' ? '' : $params['brandOrderNumber'];
+            $data['official_sn'] = $official_sn;
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true, $official_sn];
+        }
+        elseif ($status === 300) {
+            return [$order_id, false, true, true, ''];
+        }
+        else {
+            return [$order_id, false, false, false, ''];
+        }
+    }
+}

+ 154 - 0
helper/refill/api/xyz/piaoyi_ylyw/RefillPhone.php

@@ -0,0 +1,154 @@
+<?php
+
+namespace refill\piaoyi_ylyw;
+
+require_once(BASE_HELPER_RAPI_PATH . '/piaoyi_ylyw/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['agentName'] = config::agentName;
+        $params['chargeFace'] = $amount;
+        $params['chargeNumber'] = $phone;
+        $params['notifyUrl'] = config::NOTIFY_URL;
+        $params['outOrderNumber'] = $order_sn;
+        $params['productId'] = config::operator[$card_type];
+        $params['timestamp'] = $this->getMillisecond();
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $params = $this->req_params($card_no, $card_type, $amount, $params['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'] === 200) {
+                return [true, $resp['data']['orderNumber'], false];
+            } elseif ($resp['code'] === 500) {
+                $net_errno = "HTTP-{$resp['code']}";
+                return [false, $resp['msg'], true];
+            } else {
+                return [false, $resp['msg'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['agentName'] = config::agentName;
+        $params['outOrderNumber'] = $refill_info['order_sn'];
+        $params['timestamp'] = $this->getMillisecond();
+        $params['sign'] = $this->sign($params);
+
+        $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, '系统错误'];
+            }
+            elseif ($resp['code'] === 200)
+            {
+                $offical_sn = '';
+                $status = $resp['data']['orderStatus'];
+                if ($status === '200') {
+                    $offical_sn = $resp['data']['brandOrderNumber'];
+                    $updata['official_sn'] = $offical_sn;
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === '300') {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === '4') {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $status, $offical_sn];
+                }
+                return [true, $order_state, $offical_sn];
+            }
+            elseif ($resp['code'] === 3000 && (time() - $refill_info['commit_time'] >= 600))
+            {
+                return [true, ORDER_STATE_NOEXIST, ''];
+            }
+            else {
+                return [false, $resp['msg'], ''];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['agentName'] = config::agentName;
+        $params['timestamp'] = $this->getMillisecond();
+        $params['sign'] = $this->sign($params);
+        $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'] === 200) {
+                return [true, $resp['data']['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        ksort($params);
+        $content = '';
+        foreach ($params as $key => $value) {
+            if($this->check_empty($value) === false) {
+                $content .= "{$key}{$value}";
+            }
+        }
+        $content .= config::KEY;
+        return md5($content);
+    }
+
+    /**
+     * 获取毫秒级别的时间戳
+     */
+    private function getMillisecond()
+    {
+        $cur = microtime (true);
+        $cur = intval($cur * 1000);
+        return $cur;
+    }
+}

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

@@ -0,0 +1,22 @@
+<?php
+
+
+namespace refill\piaoyi_ylyw;
+
+use mtopcard;
+class config
+{
+    const ORDER_URL = 'https://agent.cqpiaoyi.com/prod-api/agent/apiOrderCredit/add';
+    const QUERY_URL = 'https://agent.cqpiaoyi.com/prod-api/agent/apiOrderCredit/get';
+    const BALANCE_URL = 'https://agent.cqpiaoyi.com/prod-api/agent/apiOrderCredit/balance';
+
+    const agentName = 'ylyw';
+    const KEY = 'e6e07d56496f667322699964394faada';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_piaoyi_ylyw.php";
+    const ExtHeaders = ['Content-Type: application/json'];
+    const operator = [
+        mtopcard\ChinaMobileCard => 1,
+        mtopcard\ChinaUnicomCard => 2,
+        mtopcard\ChinaTelecomCard => 3
+    ];
+}

+ 6 - 0
mobile/callback/refill_piaoyi_ylyw.php

@@ -0,0 +1,6 @@
+<?php
+$content = $_SERVER['post_content'];
+$input = json_decode($content,true);
+
+refill\util::push_notify('piaoyi_ylyw',$input);
+echo ('success');

+ 7 - 0
test/TestRefill.php

@@ -3210,6 +3210,13 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
         $resp = $provider->notify($params);
     }
     }
 
 
+    public function testPiaoyi_ylyw()
+    {
+        $provider = $this->getProvider('piaoyi_ylyw');
+        $resp = $provider->balance();
+
+    }
+
     public function testAmingjd()
     public function testAmingjd()
     {
     {
 //        $provider = new refill\amingjd\RefillPhone([]);
 //        $provider = new refill\amingjd\RefillPhone([]);