xiaoyu 2 лет назад
Родитель
Сommit
6268f0b397

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

@@ -7069,6 +7069,19 @@ $xinruiheng_yd_phone = ['name' => 'xinruiheng_yd', 'store_id' => 259, 'qualitys'
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$wanxin_fs_phone = ['name' => 'wanxin_fs', 'store_id' => 260, 'qualitys' => '2',
+    'amount' => [
+        10 => [['goods_id' => 8151, 'price' => 10, 'quality' => 2, 'card_type' => 'chinamobile']],
+        20 => [['goods_id' => 8152, 'price' => 20, 'quality' => 2, 'card_type' => 'chinamobile']],
+        30 => [['goods_id' => 8153, 'price' => 30, 'quality' => 2, 'card_type' => 'chinamobile']],
+        50 => [['goods_id' => 8154, 'price' => 50, 'quality' => 2, 'card_type' => 'chinamobile']],
+        100 => [['goods_id' => 8155, 'price' => 100, 'quality' => 2, 'card_type' => 'chinamobile']],
+        200 => [['goods_id' => 8156, 'price' => 200, 'quality' => 2, 'card_type' => 'chinamobile']],
+        300 => [['goods_id' => 8157, 'price' => 300, 'quality' => 2, 'card_type' => 'chinamobile']],
+        500 => [['goods_id' => 8158, 'price' => 500, 'quality' => 2, 'card_type' => 'chinamobile']]
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -7285,6 +7298,7 @@ $phone_providers = [
     ['name' => 'yelin_dx', 'cfg' => $yelin_dx_phone],
     ['name' => 'qianqian_fs', 'cfg' => $qianqian_fs_phone],
     ['name' => 'xinruiheng_yd', 'cfg' => $xinruiheng_yd_phone],
+    ['name' => 'wanxin_fs', 'cfg' => $wanxin_fs_phone],
 
 ];
 $config['phone_providers'] = $phone_providers;

+ 46 - 0
helper/refill/api/xyz/wanxin_fs/RefillCallBack.php

@@ -0,0 +1,46 @@
+<?php
+namespace refill\wanxin_fs;
+require_once(BASE_HELPER_RAPI_PATH . '/wanxin_fs/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)
+    {
+        $signature = [config::KEY, $params['timestamp'], config::ACCOUNT];
+        sort($signature, SORT_STRING);
+        $signature = implode($signature);
+        return sha1($signature);
+    }
+
+    public function notify($params)
+    {
+        $status = $params['status'];
+        $order_sn = $params['consumerNo'];
+        $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 === '001') {
+            $data['official_sn'] = strtolower($params['voucherNo']) == 'null' ? '' : $params['voucherNo'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true];
+        } elseif (in_array($status,config::NotifyErrCodes, true)) {
+            return [$order_id, false, true, true];
+        } else {
+            return [$order_id, false, false, false];
+        }
+    }
+}

+ 174 - 0
helper/refill/api/xyz/wanxin_fs/RefillPhone.php

@@ -0,0 +1,174 @@
+<?php
+
+namespace refill\wanxin_fs;
+
+require_once(BASE_HELPER_RAPI_PATH . '/wanxin_fs/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)
+    {
+        [$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 $card_type, string $order_sn)
+    {
+        $params['account'] = config::ACCOUNT;
+        $params['consumerNo'] = $order_sn;
+        $params['mobile'] = $phone;
+        $params['ispCode'] = config::operator[$card_type];
+        $params['cbkUrl'] = config::NOTIFY_URL;
+        $params['timestamp'] = $this->get_millisecond();
+
+        return $params;
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        $regin_no = $params['regin_no'] ?? -1;
+        if($regin_no <= 0) {
+            return [false, '省份获取错误', false];
+        }
+        $params = $this->req_params($card_no, $card_type, $params['order_sn']);
+        $params['flowCode'] = config::ProductIDS[$card_type][$regin_no][$amount];
+        if (empty($params['flowCode'])) {
+            return [false, '产品编号错误', false];
+        }
+
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params, 'GET', 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['status'] === '001') {
+                return [true, $resp['orderNo'], false];
+            } else {
+                return [false, $resp['status'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['account'] = config::ACCOUNT;
+        $params['consumerNo'] = $refill_info['order_sn'];
+        $params['timestamp'] = $this->get_millisecond();
+        $params['sign'] = $this->sign($params);
+
+        $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, '系统错误'];
+            }
+
+            $status = $resp['status'];
+            if ($status === '001')
+            {
+                $order_state = ORDER_STATE_SUCCESS;
+                $save['official_sn'] = strtolower($resp['voucherNo']) == 'null' ? '' : $resp['voucherNo'];
+                Model('refill_order')->edit($refill_info['order_id'], $save);
+            }
+            elseif (in_array($status,config::QueryErrCodes, true))
+            {
+                if ($status === '026')
+                {
+                    //订单不存在状态,三小时内查询可失败,超过则返回充值中.不可以在下单后的同时立马发起查询,否则返回该状态处理为充值中,至少隔30秒以上再发起查询
+                    $commit_secs = time() - $refill_info['commit_time'];
+                    if ($commit_secs > 0 && $commit_secs <= 180) {
+                        return [false, '时长不足'];
+                    } elseif ($commit_secs > 180 && $commit_secs <= 10800) {
+                        $order_state = ORDER_STATE_NOEXIST;
+                    } else {
+                        $order_state = ORDER_STATE_SEND;
+                    }
+                }
+                else {
+                    $order_state = ORDER_STATE_CANCEL;
+                }
+            }
+            elseif ($status === '002') {
+                $order_state = ORDER_STATE_SEND;
+            }
+            else {
+                return [false, $status];
+            }
+
+            return [true, $order_state];
+        }
+    }
+
+    public function balance()
+    {
+        $params['account'] = config::ACCOUNT;
+        $params['timestamp'] = $this->get_millisecond();
+        $params['sign'] = $this->sign($params);
+
+        $resp = http_request(config::BALANCE_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['status'] === 'success') {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['descriptor']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $signature = [config::KEY, $params['timestamp'], config::ACCOUNT];
+        sort($signature, SORT_STRING);
+        $signature = implode($signature);
+        return sha1($signature);
+    }
+
+    /**
+     * 获取毫秒级别的时间戳
+     */
+    private function get_millisecond()
+    {
+        $cur = microtime (true);
+        return intval($cur * 1000);
+    }
+}

+ 43 - 0
helper/refill/api/xyz/wanxin_fs/config.php

@@ -0,0 +1,43 @@
+<?php
+
+
+namespace refill\wanxin_fs;
+use mtopcard;
+
+class config
+{
+    const ORDER_URL = 'http://47.98.232.225/flow-receiver/api/recharge/feecbk';
+    const QUERY_URL = 'http://47.98.232.225/flow-receiver/api/query/feecbk';
+    const BALANCE_URL = 'http://47.98.232.225/flow-receiver/api/balance/feecbk';
+    const NOTIFY_URL = BASE_SITE_URL . '/mobile/callback/refill_wanxin_fs.php';
+
+    const ACCOUNT = 'wxgyyj';
+    const KEY = '27d408f0537b4115b2644379f536a57b';
+    const operator = [
+        mtopcard\ChinaMobileCard  => 'CMCC',
+        mtopcard\ChinaUnicomCard  => 'CUCC',
+        mtopcard\ChinaTelecomCard => 'CTCC'
+    ];
+    const ProductIDS = [
+        mtopcard\ChinaMobileCard => [
+            //河南
+            16 => [
+                10 => 'CMCCYUr10r', 20 => 'CMCCYUr20r', 30 => 'CMCCYUr30r', 50 => 'CMCCYUr50r',
+                100 => 'CMCCYUr100r', 200 => 'CMCCYUr200r', 300 => 'CMCCYUr300r', 500 => 'CMCCYUr500r'
+            ]
+        ]
+    ];
+
+    const NotifyErrCodes = [
+        '003','004','005','006','007','008','015','016','017','018','019','020','021','022','023','025','027','028','098','099'
+    ];
+
+    const QueryErrCodes = [
+        '003','004','005','006','007','008','015','016','017','018','019','020','021','022','023','024','025','026','027','028','098','099'
+    ];
+
+    const Price = [
+        // 移动
+        "4-10-16" => 10.17, "4-20-16" => 20.34, "4-30-16" => 30.3, "4-50-16" => 49.975, "4-100-16" => 99.95, "4-200-16" => 199.9, "4-300-16" => 299.85, "4-500-16" => 499.75,//河南 16
+    ];
+}

+ 29 - 0
helper/refill/api/xyz/wanxin_fs/椰子.txt

@@ -0,0 +1,29 @@
+账号:wxgyyj
+密码:123456
+密钥:27d408f0537b4115b2644379f536a57b
+
+客户后台地址:http://47.98.232.225/flow-consumer/login.html
+
+
+下单地址
+http://47.98.232.225/flow-receiver/api/recharge/feecbk
+查询地址
+http://47.98.232.225/flow-receiver/api/query/feecbk
+余额查询地址
+http://47.98.232.225/flow-receiver/api/balance/feecbk
+
+
+请务必绑定我们回调IP:47.98.232.225
+
+产品编码可登录客户后台查看:个人信息>产品编码
+
+河南分省移动
+
+CMCCYUr10r    面值10
+CMCCYUr20r    面值20
+CMCCYUr30r    面值30
+CMCCYUr50r    面值50
+CMCCYUr100r    面值100
+CMCCYUr200r    面值200
+CMCCYUr300r    面值300
+CMCCYUr500r    面值500

BIN
helper/refill/api/xyz/wanxin_fs/话费API接口文档.docx


+ 4 - 0
mobile/callback/refill_wanxin_fs.php

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

+ 15 - 0
test/TestRefill.php

@@ -2720,6 +2720,21 @@ class TestRefill extends TestCase
         $resp = $provider->notify($params);
     }
 
+    public function testWanxin_fs()
+    {
+//        $provider = $this->getProvider('wanxin_fs');
+//        $resp = $provider->balance();
+//        $resp = $provider->add(15139608757, 4, 10, ['order_sn' => $this->make_sn(), 'regin_no' => 16]);
+//        $resp = $provider->query(['order_sn' => '87101667799056105168']);
+
+        $body = ' {"status":"020","orderNo":"F2211071331082216627","consumerNo":"87101667799056105168","mobile":"15139608757","voucherNo":"null","account":"wxgyyj","timestamp":"1667799069004","sign":"ee45c3c896d5e392d95858b913cd674c02fbfa5b"}';
+        $params = json_decode($body, true);
+        $provider = $this->getProvider('wanxin_fs', 'RefillCallBack');
+        $ret = $provider->verify($params);
+        $resp = $provider->notify($params);
+
+    }
+
     public function testAmingjd()
     {
 //        $provider = new refill\amingjd\RefillPhone([]);