Quellcode durchsuchen

椰子对接椰林分省通道

zhaoming vor 1 Jahr
Ursprung
Commit
c540ccdaf7

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

@@ -9682,6 +9682,18 @@ $nanjingpushang_hf_phone = ['name' => 'nanjingpushang_hf', 'store_id' => 365, 'q
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$yezifensheng_phone = ['name' => 'yezifensheng', 'store_id' => 370, 'qualitys' => '1',
+    'amount' => [
+//        10 => [['goods_id' => 8910, 'price' => 10, 'quality' => 1, 'card_type' => 'chinatelecom']],
+//        20 => [['goods_id' => 8911, 'price' => 20, 'quality' => 1, 'card_type' => 'chinatelecom']],
+//        30 => [['goods_id' => 8912, 'price' => 30, 'quality' => 1, 'card_type' => 'chinamobile, chinatelecom']],
+        50 => [['goods_id' => 8913, 'price' => 50, 'quality' => 1, 'card_type' => 'chinamobile, chinatelecom']],
+        100 => [['goods_id' => 8914, 'price' => 100, 'quality' => 1, 'card_type' => 'chinamobile, chinatelecom']],
+        200 => [['goods_id' => 8915, 'price' => 200, 'quality' => 1, 'card_type' => 'chinamobile, chinatelecom']],
+//        300 => [['goods_id' => 8916, 'price' => 300, 'quality' => 1, 'card_type' => 'chinatelecom']],
+//        500 => [['goods_id' => 8917, 'price' => 500, 'quality' => 1, 'card_type' => 'chinatelecom']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
 
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_p hone],
@@ -9975,6 +9987,7 @@ $phone_providers = [
     ['name' => 'wangxin', 'cfg' => $wangxin_phone],
     ['name' => 'xunyuan', 'cfg' => $xunyuan_phone],
     ['name' => 'nanjingpushang_hf', 'cfg' => $nanjingpushang_hf_phone],
+    ['name' => 'yezifensheng', 'cfg' => $yezifensheng_phone],
 ];
 $config['phone_providers'] = $phone_providers;
 

+ 20 - 0
helper/refill/api/xyz/yezifensheng/API.MD

@@ -0,0 +1,20 @@
+## 椰子分省通道
+> 椰子 -> 椰林
+
+## 椰林机构
+- 机构ID:10384
+- 机构账号:yezifensheng
+- 机构密码:xyoiu_909c
+- KEY:682240597a865cfba5214a0c8477bd76
+
+## 分省配置
+- 面额:50-200
+- 折扣:默认无折扣
+- 分省:椰林-云天分省中配置的所有分省
+
+## 店铺信息
+- ID:370
+- 账号:yezifensheng
+- 密码:yezifensheng67890
+## 参考 
+> yelin_hf

+ 76 - 0
helper/refill/api/xyz/yezifensheng/RefillCallBack.php

@@ -0,0 +1,76 @@
+<?php
+namespace refill\yezifensheng;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yezifensheng/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;
+        }
+    }
+
+    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)
+    {
+        ksort($params);
+
+        $body = "";
+        $i = 0;
+        foreach ($params as $k => $v) {
+            if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
+                if ($i == 0) {
+                    $body .= "{$k}" . "=" . urlencode($v);
+                } else {
+                    $body .= "&" . "{$k}" . "=" . urlencode($v);
+                }
+                $i++;
+            }
+        }
+
+        $body .= "&key=".config::KEY;
+        return md5($body);
+    }
+
+    public function notify($params)
+    {
+        $status = $params['state'];
+        $order_sn = $params['order_sn'];
+        $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 === 'SUCCESS') {
+            $data['ch_trade_no'] = $params['trade_no'];
+            $data['official_sn'] = strtolower($params['official_sn']) == 'null' ? '' : $params['official_sn'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 'CANCEL') {
+            Model('refill_order')->edit($order_id, ['ch_trade_no' => $params['trade_no']]);
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 175 - 0
helper/refill/api/xyz/yezifensheng/RefillPhone.php

@@ -0,0 +1,175 @@
+<?php
+
+namespace refill\yezifensheng;
+
+require_once(BASE_HELPER_RAPI_PATH . '/yezifensheng/config.php');
+
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    public function goods($quality, int $amount, int $card_type, $regin_no, $other): array
+    {
+        [$goods_id, $price] = parent::goods($quality, $amount, $card_type, $regin_no, $other);
+        if($goods_id <= 0) return [0,0];
+        $key = "{$card_type}-{$amount}-{$regin_no}";
+        $price = config::Price[$key];
+        if (empty($price)) {
+            Log::record("channel cannot find price where name={$this->mName}, goods_id = {$goods_id} card_type={$card_type} amount={$amount} regin_no={$regin_no}", Log::ERR);
+            return [0, 0];
+        } else {
+            return [$goods_id, ncPriceFormat($price)];
+        }
+    }
+
+    private function req_params(int $phone, int $amount, string $order_sn): array
+    {
+        $params['act'] = 'refill';
+        $params['op'] = 'add';
+        $params['mchid'] = config::MCH_ID;
+        $params['cardno'] = $phone;
+        $params['amount'] = $amount;
+        $params['order_sn'] = $order_sn;
+        $params['notifyurl'] = config::NOTIFY_URL;
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
+    {
+        $params = $this->req_params($card_no, $amount, $params['order_sn']);
+        $sign = $this->sign($params);
+        $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'] === 200) {
+                return [true, '', false];
+            } else {
+                return [false, $resp['message'], false];
+            }
+        }
+    }
+
+    public function query($refill_info): array
+    {
+        $params['act'] = 'refill';
+        $params['op'] = 'query';
+        $params['mchid'] = config::MCH_ID;
+        $params['order_sn'] = $refill_info['order_sn'];
+        $params['sign'] = $this->sign($params);
+
+        $resp = http_request(config::ORDER_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'] === 200)
+            {
+                $data = $resp['datas'];
+                if ($data['order_state'] == '40') {
+                    $save['ch_trade_no'] = $data['trade_no'];
+                    $save['official_sn'] = strtolower($resp['official_sn']) == 'null' ? '' : $resp['official_sn'];
+                    Model('refill_order')->edit($refill_info['order_id'], $save);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($data['order_state'] === '0') {
+                    Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $data['trade_no']]);
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($data['order_state'], ['10', '20', '30', '50'], true)) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $resp['message']];
+                }
+                return [true, $order_state];
+            }
+            elseif ($resp['code'] === 202 && (time() - $refill_info['commit_time'] >= 600))
+            {
+                return [true, ORDER_STATE_NOEXIST];
+            }
+            else
+            {
+                return [false, $resp['message']];
+            }
+        }
+    }
+
+    public function balance(): array
+    {
+        $params['act'] = 'refill';
+        $params['op'] = 'balance';
+        $params['mchid'] = config::MCH_ID;
+        $params['sign'] = $this->sign($params);
+
+        $resp = http_request(config::ORDER_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'] === 200) {
+                return [true, $resp['datas']['balance']];
+            } else {
+                return [false, $resp['message']];
+            }
+        }
+    }
+
+    protected function check_empty($value): bool
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function sign($params): string
+    {
+        ksort($params);
+
+        $body = "";
+        $i = 0;
+        foreach ($params as $k => $v) {
+            if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
+                if ($i == 0) {
+                    $body .= "{$k}" . "=" . urlencode($v);
+                } else {
+                    $body .= "&" . "{$k}" . "=" . urlencode($v);
+                }
+                $i++;
+            }
+        }
+
+        $body .= "&key=".config::KEY;
+
+        return md5($body);
+    }
+}

+ 55 - 0
helper/refill/api/xyz/yezifensheng/config.php

@@ -0,0 +1,55 @@
+<?php
+
+namespace refill\yezifensheng;
+
+class config
+{
+    const ORDER_URL = 'https://ylapi.xyzshops.cn/mobile/index.php';
+
+    const MCH_ID = 10384;
+    const KEY = '682240597a865cfba5214a0c8477bd76';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_yezifensheng.php";
+
+    //key格式 卡类型-面值-regin_no
+    const Price = [
+        // 移动
+        "4-50-12" => 50, "4-100-12" => 100, "4-200-12" => 200,//安徽 12
+        "4-50-1" => 50, "4-100-1" => 100, "4-200-1" => 200,//北京 1
+        "4-50-22" => 50, "4-100-22" => 100, "4-200-22" => 200,//重庆 22
+        "4-50-13" => 50, "4-100-13" => 100, "4-200-13" => 200,//福建 13
+        "4-50-28" => 50, "4-100-28" => 100, "4-200-28" => 200,//甘肃 28
+        "4-50-19" => 50, "4-100-19" => 100, "4-200-19" => 200,//广东 19
+        "4-50-20" => 50, "4-100-20" => 100, "4-200-20" => 200,//广西 20
+        "4-50-24" => 50, "4-100-24" => 100, "4-200-24" => 200,//贵州 24
+        "4-50-3" => 50, "4-100-3" => 100, "4-200-3" => 200,//河北 3
+        "4-50-8" => 50, "4-100-8" => 100, "4-200-8" => 200,//黑龙江 8
+        "4-50-16" => 50, "4-100-16" => 100, "4-200-16" => 200,//河南 16
+        "4-50-17" => 50, "4-100-17" => 100, "4-200-17" => 200,//湖北 17
+        "4-50-18" => 50, "4-100-18" => 100, "4-200-18" => 200,//湖南 18
+        "4-50-10" => 50, "4-100-10" => 100, "4-200-10" => 200,//江苏 10
+        "4-50-14" => 50, "4-100-14" => 100, "4-200-14" => 200,//江西 14
+        "4-50-6" => 50, "4-100-6" => 100, "4-200-6" => 200,//辽宁 6
+        "4-50-30" => 50, "4-100-30" => 100, "4-200-30" => 200,//宁夏 30
+        "4-50-29" => 50, "4-100-29" => 100, "4-200-29" => 200,//青海 29
+        "4-50-15" => 50, "4-100-15" => 100, "4-200-15" => 200,//山东 15
+        "4-50-9" => 50, "4-100-9" => 100, "4-200-9" => 200,//上海 9
+        "4-50-27" => 50, "4-100-27" => 100, "4-200-27" => 200,//陕西 27
+        "4-50-23" => 50, "4-100-23" => 100, "4-200-23" => 200,//四川 23
+        "4-50-31" => 50, "4-100-31" => 100, "4-200-31" => 200,//新疆 31
+        "4-50-25" => 50, "4-100-25" => 100, "4-200-25" => 200,//云南 25
+        "4-50-11" => 50, "4-100-11" => 100, "4-200-11" => 200,//浙江 11
+
+        //电信
+        "6-50-12" => 50, "6-100-12" => 100, "6-200-12" => 200,//安徽 12
+        "6-50-1" => 50, "6-100-1" => 100, "6-200-1" => 200,//北京 1
+        "6-50-19" => 50, "6-100-19" => 100, "6-200-19" => 200,//广东 19
+        "6-50-17" => 50, "6-100-17" => 100, "6-200-17" => 200,//湖北 17
+        "6-50-18" => 50, "6-100-18" => 100, "6-200-18" => 200,//湖南 18
+        "6-50-10" => 50, "6-100-10" => 100, "6-200-10" => 200,//江苏 10
+        "6-50-15" => 50, "6-100-15" => 100, "6-200-15" => 200,//山东 15
+        "6-50-9" => 50, "6-100-9" => 100, "6-200-9" => 200,//上海 9
+        "6-50-23" => 50, "6-100-23" => 100, "6-200-23" => 200,//四川 23
+        "6-50-31" => 50, "6-100-31" => 100, "6-200-31" => 200,//新疆 31
+        "6-50-11" => 50, "6-100-11" => 100, "6-200-11" => 200,//浙江 11
+    ];
+}

+ 4 - 0
mobile/callback/refill_yezifensheng.php

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

+ 5 - 0
test/TestRefill.php

@@ -5606,6 +5606,11 @@ class TestRefill extends TestCase
         $s3 = $extractOfficialSn('【中国石化】您尾号为869682的加油卡于09月18日 17时21分充值成功,金额200元,订单号:1623091817214688');
     }
 
+    public function testYezifensheng_Balance()
+    {
+        $provider = $this->getProvider('yezifensheng');
+        [$succ, $val] = $provider->balance();
+    }
 }
 
 //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test