zb727 il y a 1 an
Parent
commit
ecc3bc0dd4

+ 20 - 0
data/config/mh/refill.ini.php

@@ -40,6 +40,26 @@ $dixin_normal = ['name' => 'dixin_normal', 'store_id' => 377,'qualitys' => '1',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$dixin_slow = ['name' => 'dixin_slow', 'store_id' => 382,'qualitys' => '1',
+    'amount' => [
+        50 => [
+            ['goods_id' => 8951, 'price' => 46.75,'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8951, 'price' => 46.75, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8951, 'price' => 46.75,   'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        100 => [
+            ['goods_id' => 8952, 'price' => 93.50, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8952, 'price' => 93.50, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8952, 'price' => 93.50, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+        200 => [
+            ['goods_id' => 8953, 'price' => 187.0, 'quality' => 1, 'card_type' => 'chinamobile'],
+            ['goods_id' => 8953, 'price' => 187.0, 'quality' => 1, 'card_type' => 'chinaunicom'],
+            ['goods_id' => 8953, 'price' => 187.0, 'quality' => 1, 'card_type' => 'chinatelecom']
+        ],
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
 
 $suhu_normal = ['name' => 'suhu_normal', 'store_id' => 379,'qualitys' => '1',
     'amount' => [

+ 3 - 0
helper/refill/api/mh/dixin_slow/ReadMe.MD

@@ -0,0 +1,3 @@
+登陆地址:https://xin.baiopen.com/#/login?redirect=%2F404
+账号:15652921127
+初始密码:xl123456

+ 48 - 0
helper/refill/api/mh/dixin_slow/RefillCallBack.php

@@ -0,0 +1,48 @@
+<?php
+namespace refill\dixin_slow;
+
+require_once(BASE_HELPER_RAPI_PATH . '/dixin_slow/config.php');
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        $sign = config::sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    //[$order_id, $success, $can_try, $need_handle, $official_sn]
+    public function notify($params): array
+    {
+        $order_sn = $params['merchant_no'];
+        $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'];
+        $ch_trade_no = $params['order_no'];
+
+        $status = intval($params['recharge_status']);
+        if ($status === 3) {
+            $official_sn = $params['official_sn'] ?? '';
+            Model('refill_order')->edit($order_id, ['ch_trade_no' => $ch_trade_no,'official_sn' => $official_sn]);
+            return [$order_id, true, false, true, $official_sn];
+        }
+        elseif (in_array($status,[4,5])) {
+            Model('refill_order')->edit($order_id, ['ch_trade_no' => $ch_trade_no]);
+            return [$order_id, false, true, true, ''];
+        }
+        else {
+            return [$order_id, false, false, false, ''];
+        }
+    }
+}

+ 173 - 0
helper/refill/api/mh/dixin_slow/RefillPhone.php

@@ -0,0 +1,173 @@
+<?php
+
+namespace refill\dixin_slow;
+
+require_once(BASE_HELPER_RAPI_PATH . '/dixin_slow/config.php');
+
+use mtopcard;
+use refill;
+use Log;
+
+class RefillPhone extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function add_params(int $phone, int $amount, string $order_sn, int $card_type): array
+    {
+        $oper_getter = function ($card_type)
+        {
+            if($card_type == mtopcard\ChinaMobileCard) {
+                return 'YD';
+            }
+            elseif($card_type == mtopcard\ChinaUnicomCard) {
+                return 'LT';
+            }
+            elseif($card_type == mtopcard\ChinaTelecomCard) {
+                return 'DX';
+            }
+            else {
+                return false;
+            }
+        };
+
+        $operator = $oper_getter($card_type);
+        $sku_code = config::sku_code($card_type,$amount);
+
+        if($operator === false || empty($sku_code)) {
+            return [];
+        }
+
+        $params = [
+            'merchant_no' => $order_sn,
+            'sku_code' => $sku_code,
+            'format' =>  ['account' => $phone],
+            "format_type" => "common",
+            'notice_url' => config::NOTIFY_URL,
+            "uid" => "123456"
+        ];
+
+        $result = $this->method('create.order',$params);
+
+        return $result;
+    }
+
+    private function method($method,$data = [],$attach = '')
+    {
+        $param = [
+            'access_token' => config::ACCESS_TOKEN,
+            'once' => uniqid(),
+            'timestamp' => $this->getUnixTimestamp(),
+            'attach' => $attach,
+            'format' => 'JSON',
+            'sign_type' => 'MD5',
+            'version' => '1.0.0',
+            'method' => $method,
+            'data' => json_encode($data, 256),
+        ];
+        $param = array_merge($param, ['sign' => config::sign($param)]);
+        return $param;
+    }
+    private function getUnixTimestamp ()
+    {
+        list($s1, $s2) = explode(' ', microtime());
+        return (float)sprintf('%.0f',(floatval($s1) + floatval($s2)) * 1000);
+    }
+
+    //[$state, $errmsg, $neterr]
+    public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
+    {
+        $params = $this->add_params($card_no, $amount, $params['order_sn'],$card_type);
+        if(empty($params)) {
+            return [false, '提单参数不符合', false];
+        }
+
+        $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['merchant_no'] = $refill_info['order_sn'];  //sn码
+        $params = $this->method('query.order',$params);//查数据库情况,查询全部数据结构包括orderid
+        $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)
+            {
+                $val = $resp['data'][0];
+                $status = $val['recharge_status'];
+                $official_sn = '';//strtolower($val['official_sn']) == 'null' ? '' : $val['official_sn'];
+
+                //充值状态:1=待充值,2=充值中,3=充值完成,4=充值失败,5=运营商维护,8=部分到账
+                if ($status == '3') {
+                    $save['ch_trade_no'] = $val['order_no'];//平台的订单号
+                    $save['official_sn'] = $official_sn;
+                    Model('refill_order')->edit($refill_info['order_id'], $save);
+                    $order_state = ORDER_STATE_SUCCESS;
+                }
+                elseif (in_array($status,[4,5])) {
+                    Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $val['order_no']]);
+                    $order_state = ORDER_STATE_CANCEL;
+                }
+                else {
+                    $order_state = ORDER_STATE_SEND;
+                }
+
+                return [true, $order_state, $official_sn];
+            }
+            else
+            {
+                return [false, $resp['message'], ''];
+            }
+        }
+    }
+
+    public function balance(): array
+    {
+        $params = $this->method('query.balance',[]);
+        $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, ncPriceFormat($resp['data']['predict_money'])];
+            } else {
+                return [false, $resp['message']];
+            }
+        }
+    }
+}

+ 74 - 0
helper/refill/api/mh/dixin_slow/config.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace refill\dixin_slow;
+
+use mtopcard;
+
+class config
+{
+    const ACCESS_TOKEN = '406c0c33c27e18662a756b369a1074c1';
+    const KEY = 'a6573b34c420dc7304c4331672297f7d';
+    const ORDER_URL = 'https://m.baiopen.com/openapi/method';
+    const NOTIFY_URL = BASE_SITE_URL . "/racc/callback/mh/dixin_slow.php";
+    const IS_DEBUG = false;
+    private static $stStoreProducts = [
+        50  => [4 => 'G32540029294752736', 5 => 'G32540029294758742', 6 => 'G32540029294755739'],
+        100 => [4 => 'G32540029294753737', 5 => 'G32540029294759743', 6 => 'G32540029294756740'],
+        200 => [4 => 'G32540029294754738', 5 => 'G32540029294760744', 6 => 'G32540029294757741']
+    ];
+
+    public static function sign($params)
+    {
+        if (is_object($params)) { //对象转数组
+            $params = json_decode(json_encode($params), true);
+        }
+
+        $params['sign_key'] = config::KEY;
+        ksort($params);
+
+        $formatData = [];
+        foreach ($params as $k => $v) {
+            if (is_array($v) || is_object($v)) {
+                $v = json_encode($v, JSON_UNESCAPED_UNICODE);
+            }
+            if ((!empty($v) || (string)$v === '0') && $k != 'sign') {
+                $formatData[] = "$k=$v";
+            }
+        }
+        $signStr = implode('&', $formatData);
+
+        return md5($signStr);
+    }
+
+    public static function sku_code($card_type,$amount)
+    {
+        if(config::IS_DEBUG)
+        {
+            if($card_type === mtopcard\ChinaMobileCard)
+            {
+                switch ($amount)
+                {
+                    case 50:
+                        return 'G34707828905632832';
+                }
+            }
+            elseif($card_type === mtopcard\ChinaUnicomCard)
+            {
+                switch ($amount)
+                {
+                    case 50:
+                        return 'G34707828917408824';
+                }
+            }
+        }
+        else
+        {
+            if(array_key_exists($amount,self::$stStoreProducts)) {
+                if(array_key_exists($card_type,self::$stStoreProducts[$amount])) {
+                    return self::$stStoreProducts[$amount][$card_type];
+                }
+            }
+            return false;
+        }
+    }
+}

+ 133 - 0
helper/refill/api/mh/dixin_slow/demo.txt

@@ -0,0 +1,133 @@
+<?php
+
+
+namespace refill\dixin_normal;
+class demo
+{
+    //默认配置
+    protected $config = [
+        "access_token"          => "您的访问token",
+        "sign_key"          => "您的签名key",
+        'url'      =>'http://openapi.baishouopen.com/method',
+        'test_url'      =>'http://t.openapi.baishouopen.com/method',
+    ];
+
+    //使用
+    // $demo = new demo();
+    // $rs = $demo->method('maintain.region',[]);
+
+    // method
+    // create.order  创建订单
+    // query.order   查询订单
+    // 更多见文档 http://api.35kds.com/web/#/64?page_id=720
+
+    /**
+     * @var string 请求地址
+     */
+    protected $service;
+
+    /**
+     * demo constructor.
+     * @param bool $is_debug
+     */
+    public function __construct($is_debug=true)
+    {
+        $this->service = $is_debug?$this->config['test_url']:$this->config['url'];
+    }
+
+    /**
+     * @introduce 请求接口
+     * @param string $method 接口名称
+     * @param json $data 参数
+     * @param string $attach 透传参数
+     * @return bool|string
+     * @author yanglei
+     * @Date 2022/1/27
+     */
+    public function method($method,$data = [],$attach = ''){
+        $param = [
+            'access_token'        =>  $this->config['access_token'],
+            'once'        =>  uniqid() ,
+            'timestamp'  =>  time()*1000,
+            'attach'       =>  $attach,
+            'format'     =>  'JSON',
+            'sign_type'    =>  'MD5',
+            'version'       =>  '1.0.0',
+            'method'       =>  $method,
+            'data'       =>  json_encode($data,256),
+        ];
+        $param = array_merge($param,['sign'=>$this->sign($param,$this->config['sign_key'])]);
+        return $this->http($this->service,$param);
+    }
+
+    /**
+     * @introduce 获取13时间戳
+     * @return float
+     * @Date 2022/1/27
+     * @author yanglei
+     */
+    function getUnixTimestamp ()
+    {
+        list($s1, $s2) = explode(' ', microtime());
+        return (float)sprintf('%.0f',(floatval($s1) + floatval($s2)) * 1000);
+
+    }
+    /**
+     * 创建签名
+     * @param $params array|object 参与签名的数据
+     * @param $signKey string 签名key
+     * @return string
+     */
+    protected function sign($params, $signKey = '')
+    {
+        if (is_object($params)) { //对象转数组
+            $params = json_decode(json_encode($params), true);
+        }
+        if (!empty($signKey)) {
+            $params['sign_key'] = $signKey;
+        }
+        ksort($params);
+        $formatData = [];
+        foreach ($params as $k => $v) {
+            if (is_array($v) || is_object($v)) {
+                $v = json_encode($v,JSON_UNESCAPED_UNICODE);
+            }
+            if ((!empty($v) || (string)$v === '0') && $k != 'sign') {
+                $formatData[] = "$k=$v";
+            }
+        }
+        $signStr = implode('&', $formatData);
+        return strtoupper(md5($signStr));
+    }
+    /**
+     * @introduce http post请求
+     * @param $url string 请求地址
+     * @param $data array 参数
+     * @return bool|string
+     * @Date 2022/1/4
+     * @author yanglei
+     */
+    protected function http($url, $data){
+        $curl = curl_init(); // 启动一个CURL会话
+        curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
+        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // 对认证证书来源的检查
+        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在
+        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); // 模拟用户使用的浏览器
+        //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
+        //curl_setopt($curl, CURLOPT_AUTOREFERER, 1);    // 自动设置Referer
+        curl_setopt($curl, CURLOPT_POST, 1);             // 发送一个常规的Post请求
+        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);   // Post提交的数据包x
+        curl_setopt($curl, CURLOPT_TIMEOUT, 30);         // 设置超时限制 防止死循环
+        curl_setopt($curl, CURLOPT_HEADER, 0);           // 显示返回的Header区域内容
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);   // 获取的信息以文件流的形式返回
+
+        $tmpInfo = curl_exec($curl); // 执行操作
+        if(curl_errno($curl))
+        {
+            return false;//捕抓异常
+        }
+        curl_close($curl); // 关闭CURL会话
+        return $tmpInfo; // 返回数据
+
+    }
+}

+ 9 - 0
racc/callback/mh/dixin_slow.php

@@ -0,0 +1,9 @@
+<?php
+
+$content = $_SERVER['post_content'];
+Log::record("dixin_slow content=$content",Log::DEBUG);
+
+$input = json_decode($content,true);
+refill\util::push_notify('dixin_slow',$input);
+
+echo ('success');