mirror of
				https://gitee.com/technical-laohu/mpay.git
				synced 2025-11-04 08:43:42 +08:00 
			
		
		
		
	插件开发模版更新
This commit is contained in:
		@@ -282,7 +282,7 @@ class PayController
 | 
			
		||||
        $payclient_path = "\\payclient\\{$payclient_name}";
 | 
			
		||||
        $Payclient = new $payclient_path($config);
 | 
			
		||||
        // 获取支付明细
 | 
			
		||||
        $records = $Payclient->payQuery($query);
 | 
			
		||||
        $records = $Payclient->getOrderInfo($query);
 | 
			
		||||
        if ($records) {
 | 
			
		||||
            // 提交收款记录
 | 
			
		||||
            $upres = $Mpay->upRecords($records, $aid);
 | 
			
		||||
 
 | 
			
		||||
@@ -49,7 +49,7 @@ return array(
 | 
			
		||||
  array(
 | 
			
		||||
    'platform' => 'ysepay',
 | 
			
		||||
    'name' => '小Y经营',
 | 
			
		||||
    'class_name' => 'Ysepay',
 | 
			
		||||
    'class_name' => 'YsePay',
 | 
			
		||||
    'price' => '99.00',
 | 
			
		||||
    'describe' => '为商户和消费者提供安全、便捷、高效的支付产品与服务助力商户提升运营效率,实现数字化运营',
 | 
			
		||||
    'website' => 'https://xym.ysepay.com/',
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@ class PayClass
 | 
			
		||||
    // 验证码接口
 | 
			
		||||
    private $captcha_path = '/saas_merchant_management/public/captcha';
 | 
			
		||||
 | 
			
		||||
    function __construct($config)
 | 
			
		||||
    function __construct(array $config)
 | 
			
		||||
    {
 | 
			
		||||
        $this->username = $config['username'];
 | 
			
		||||
        $this->password = $config['password'];
 | 
			
		||||
@@ -35,18 +35,18 @@ class PayClass
 | 
			
		||||
        // 检查token/cookie目录
 | 
			
		||||
        $dir_path = runtime_path() . "token/{$this->pay_type}/";
 | 
			
		||||
        if (!is_dir($dir_path)) {
 | 
			
		||||
            if (!mkdir($dir_path, 755, true)) echo '目录创建失败';
 | 
			
		||||
            if (!mkdir($dir_path, 755, true)) echo '创建token/cookie目录失败';
 | 
			
		||||
        }
 | 
			
		||||
        // token/cookie文件路径
 | 
			
		||||
        $this->token_path = $dir_path . md5($this->username . $this->password . __CLASS__) . '.json';
 | 
			
		||||
        $this->cookie_path = $dir_path . md5($this->username . $this->password . __CLASS__) . '.txt';
 | 
			
		||||
        // 检查token文件
 | 
			
		||||
        if (!file_exists($this->token_path)) {
 | 
			
		||||
            file_put_contents($this->token_path, \json_encode(['token' => 'ok', 'update_time' => date('Y-m-d H:i:s')]));
 | 
			
		||||
            file_put_contents($this->token_path, json_encode(['token' => 'ok', 'update_time' => date('Y-m-d H:i:s')]));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    // 获取订单信息
 | 
			
		||||
    public function getOrderInfo(array $query)
 | 
			
		||||
    public function getOrderInfo(array $query): array
 | 
			
		||||
    {
 | 
			
		||||
        $order_list = $this->queryOrder($query);
 | 
			
		||||
        $orders = [];
 | 
			
		||||
@@ -82,7 +82,7 @@ class PayClass
 | 
			
		||||
        if ($result['code'] === 0) {
 | 
			
		||||
            $order_list = $result['data']['list'];
 | 
			
		||||
        } else {
 | 
			
		||||
            // 重试2次
 | 
			
		||||
            // 重试3次
 | 
			
		||||
            if ($times < 3) {
 | 
			
		||||
                $this->updateToken();
 | 
			
		||||
                $order_list = $this->queryOrder($query, $times + 1);
 | 
			
		||||
@@ -137,12 +137,13 @@ class PayClass
 | 
			
		||||
            $this->saveToken($data['data']);
 | 
			
		||||
            return true;
 | 
			
		||||
        } else {
 | 
			
		||||
            // 重试2次
 | 
			
		||||
            // 重试3次
 | 
			
		||||
            $is_login = false;
 | 
			
		||||
            if ($times < 3) {
 | 
			
		||||
                $is_login = false;
 | 
			
		||||
                $is_login = $this->login($times + 1);
 | 
			
		||||
                return $is_login;
 | 
			
		||||
            }
 | 
			
		||||
            return $is_login;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    // 更新token
 | 
			
		||||
@@ -162,7 +163,7 @@ class PayClass
 | 
			
		||||
    private function saveToken($data)
 | 
			
		||||
    {
 | 
			
		||||
        $token = $data['token'];
 | 
			
		||||
        file_put_contents($this->token_path, ['token' => $token, 'update_time' => date('Y-m-d H:i:s')]);
 | 
			
		||||
        file_put_contents($this->token_path, json_encode(['token' => $token, 'update_time' => date('Y-m-d H:i:s')]));
 | 
			
		||||
    }
 | 
			
		||||
    // 解析验证码
 | 
			
		||||
    private function getCaptchaInfo(string $image = '', string $typeid = '3'): string
 | 
			
		||||
 
 | 
			
		||||
@@ -1,41 +1,113 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace payclient;
 | 
			
		||||
 | 
			
		||||
class ShouQianBa
 | 
			
		||||
{
 | 
			
		||||
    // 收款平台
 | 
			
		||||
    private $pay_type = 'sqbpay';
 | 
			
		||||
    // 收款平台账号
 | 
			
		||||
    private $username;
 | 
			
		||||
    // 平台登陆密码
 | 
			
		||||
    private $password;
 | 
			
		||||
    // token保存路径
 | 
			
		||||
    private $token_path;
 | 
			
		||||
    private $host = 'https://web-platforms-msp.shouqianba.com';
 | 
			
		||||
    private $login = '/api/login/ucUser/login';
 | 
			
		||||
    private $find_transactions = '/api/transaction/findTransactions';
 | 
			
		||||
    private $refresh_token = '/api/login/ucUser/refreshToken';
 | 
			
		||||
    // Cookie保存路径
 | 
			
		||||
    private $cookie_path;
 | 
			
		||||
    // 当前时间戳
 | 
			
		||||
    private $now;
 | 
			
		||||
    // 收款平台网站
 | 
			
		||||
    private $payhost = 'https://web-platforms-msp.shouqianba.com';
 | 
			
		||||
    // 用户登陆接口
 | 
			
		||||
    private $login_path = '/api/login/ucUser/login';
 | 
			
		||||
    // 订单查询接口
 | 
			
		||||
    private $order_query_path = '/api/transaction/findTransactions';
 | 
			
		||||
    // 刷新Token接口
 | 
			
		||||
    private $refresh_token_path = '/api/login/ucUser/refreshToken';
 | 
			
		||||
 | 
			
		||||
    function __construct($config)
 | 
			
		||||
    function __construct(array $config)
 | 
			
		||||
    {
 | 
			
		||||
        $this->username = $config['username'];
 | 
			
		||||
        $this->password = $config['password'];
 | 
			
		||||
        // 检查token目录
 | 
			
		||||
        $dir_path = runtime_path() . 'token/sqbpay';
 | 
			
		||||
        $this->password = md5($config['password']);
 | 
			
		||||
        $this->now = time();
 | 
			
		||||
        // 检查token/cookie目录
 | 
			
		||||
        $dir_path = runtime_path() . "token/{$this->pay_type}/";
 | 
			
		||||
        if (!is_dir($dir_path)) {
 | 
			
		||||
            if (!mkdir($dir_path, 755, true)) {
 | 
			
		||||
                echo '目录创建失败';
 | 
			
		||||
            }
 | 
			
		||||
            if (!mkdir($dir_path, 755, true)) echo '创建token/cookie目录失败';
 | 
			
		||||
        }
 | 
			
		||||
        $this->token_path = $dir_path . '/' . md5($this->username . $this->password . 'sqbpay') . '.json';
 | 
			
		||||
        // token/cookie文件路径
 | 
			
		||||
        $this->token_path = $dir_path . md5($this->username . $this->password . __CLASS__) . '.json';
 | 
			
		||||
        $this->cookie_path = $dir_path . md5($this->username . $this->password . __CLASS__) . '.txt';
 | 
			
		||||
        // 检查token文件
 | 
			
		||||
        if (!file_exists($this->token_path)) {
 | 
			
		||||
            // 失效Token刷新
 | 
			
		||||
            $token_info = ['token' => 'Y2FjZmRiMi04MjRjLTQ2NDgtYTU0Ny1lNzg2MDllMTQ1ZTI6MTcxOTQ1Mzg0MzU3OTozNjAwMDAw.txcnX60Za8', 'expire_time' => 1719453843579];
 | 
			
		||||
            file_put_contents($this->token_path, json_encode($token_info));
 | 
			
		||||
            file_put_contents($this->token_path, json_encode(['token' => 'ok', 'update_time' => date('Y-m-d H:i:s')]));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    // 登陆账号
 | 
			
		||||
    private function login(): array
 | 
			
		||||
    // 获取订单信息
 | 
			
		||||
    public function getOrderInfo(array $query): array
 | 
			
		||||
    {
 | 
			
		||||
        $order_list = $this->queryOrder($query);
 | 
			
		||||
        $orders = [];
 | 
			
		||||
        if (!$order_list) return $orders;
 | 
			
		||||
        $payways = [2 => 'alipay', 3 => 'wxpay'];
 | 
			
		||||
        foreach ($order_list as $value) {
 | 
			
		||||
            $order = [];
 | 
			
		||||
            // 平台订单流水号
 | 
			
		||||
            $order['order_no'] = $value['order_sn'];
 | 
			
		||||
            // 支付类型
 | 
			
		||||
            $order['payway'] = $payways[$value['payway']];
 | 
			
		||||
            // 收款金额
 | 
			
		||||
            $order['price'] = (float)($value['original_amount'] / 100);
 | 
			
		||||
            // 收款渠道(二维码编号)
 | 
			
		||||
            $order['channel'] = $value['terminal_device_fingerprint'];
 | 
			
		||||
            // 添加到订单列表
 | 
			
		||||
            $orders[] = $order;
 | 
			
		||||
        }
 | 
			
		||||
        return $orders;
 | 
			
		||||
    }
 | 
			
		||||
    // 查询订单
 | 
			
		||||
    private function queryOrder(array $query, $times = 0): array
 | 
			
		||||
    {
 | 
			
		||||
        // 查询订单列表
 | 
			
		||||
        $token = $this->getToken();
 | 
			
		||||
        $url = $this->payhost . $this->order_query_path . '?client_version=7.0.0&token=' . $token;
 | 
			
		||||
        $header = ['Content-Type: application/json;charset=UTF-8'];
 | 
			
		||||
        $new_query = $this->getOrderQuery($query);
 | 
			
		||||
        $res = $this->getHttpResponse($url, $header, json_encode($new_query));
 | 
			
		||||
        $result = json_decode($res, true);
 | 
			
		||||
        // 检查订单信息
 | 
			
		||||
        $order_list = [];
 | 
			
		||||
        if ($result['code'] === 50000) {
 | 
			
		||||
            $order_list = $result['data']['records'];
 | 
			
		||||
        } else {
 | 
			
		||||
            // 重试1次
 | 
			
		||||
            if ($times < 1) {
 | 
			
		||||
                $this->updateToken();
 | 
			
		||||
                $order_list = $this->queryOrder($query, $times + 1);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return $order_list;
 | 
			
		||||
    }
 | 
			
		||||
    // 构建订单查询数组信息
 | 
			
		||||
    private function getOrderQuery(array $query): array
 | 
			
		||||
    {
 | 
			
		||||
        $new_query = $query;
 | 
			
		||||
        $now = $this->now;
 | 
			
		||||
        $begin_time = (int)(($now - 175) . mt_rand(100, 999));
 | 
			
		||||
        $end_time = (int)($now . mt_rand(100, 999));
 | 
			
		||||
        $query['date_start'] = $begin_time;
 | 
			
		||||
        $query['date_end'] = $end_time;
 | 
			
		||||
        return $new_query;
 | 
			
		||||
    }
 | 
			
		||||
    // 登陆账号
 | 
			
		||||
    private function login($times = 0): bool
 | 
			
		||||
    {
 | 
			
		||||
        $url = $this->payhost . $this->login_path;
 | 
			
		||||
        $user_info = [
 | 
			
		||||
            "username" => $this->username,
 | 
			
		||||
            "password" => md5($this->password),
 | 
			
		||||
            "password" => $this->password,
 | 
			
		||||
            "uc_device" => [
 | 
			
		||||
                "device_type" => 2,
 | 
			
		||||
                "default_device" => 0,
 | 
			
		||||
@@ -46,100 +118,50 @@ class ShouQianBa
 | 
			
		||||
                "device_brand" => "Chrome"
 | 
			
		||||
            ]
 | 
			
		||||
        ];
 | 
			
		||||
        $header = [
 | 
			
		||||
            'Content-Type:application/json;charset=UTF-8',
 | 
			
		||||
            'Host:web-platforms-msp.shouqianba.com',
 | 
			
		||||
            'Origin:https://s.shouqianba.com',
 | 
			
		||||
            'Referer:https://s.shouqianba.com/login',
 | 
			
		||||
        ];
 | 
			
		||||
        $url = $this->host . $this->login;
 | 
			
		||||
        $header = ['Content-Type:application/json;charset=UTF-8', 'Host:web-platforms-msp.shouqianba.com', 'Origin:https://s.shouqianba.com', 'Referer:https://s.shouqianba.com/login'];
 | 
			
		||||
        $res = $this->getHttpResponse($url, $header, json_encode($user_info));
 | 
			
		||||
        $arr_res = json_decode($res, true);
 | 
			
		||||
        $mchUserTokenInfo = $arr_res['data']['mchUserTokenInfo'];
 | 
			
		||||
        $token_info = [];
 | 
			
		||||
        $token_info['token'] = $mchUserTokenInfo['token'];
 | 
			
		||||
        $token_info['expire_time'] = $mchUserTokenInfo['expire_time'];
 | 
			
		||||
        // 保存登陆token
 | 
			
		||||
        file_put_contents($this->token_path, json_encode($token_info));
 | 
			
		||||
        // 返回新token
 | 
			
		||||
        return $token_info;
 | 
			
		||||
        $data = json_decode($res, true);
 | 
			
		||||
        if ($data['code'] === 50000 && $data['data']['code'] === 50000) {
 | 
			
		||||
            // 保存token
 | 
			
		||||
            $this->saveToken($data['data']['mchUserTokenInfo']);
 | 
			
		||||
            return true;
 | 
			
		||||
        } else {
 | 
			
		||||
            // 重试2次
 | 
			
		||||
            $is_login = false;
 | 
			
		||||
            if ($times < 2) {
 | 
			
		||||
                $is_login = $this->login($times + 1);
 | 
			
		||||
                return $is_login;
 | 
			
		||||
            }
 | 
			
		||||
            return $is_login;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    // 更新token
 | 
			
		||||
    private function updateToken(): bool
 | 
			
		||||
    {
 | 
			
		||||
        $token = $this->getToken();
 | 
			
		||||
        $url = $this->payhost . $this->refresh_token_path . '?token=' . $token;
 | 
			
		||||
        $header = ["Authorization:Bearer {$token}"];
 | 
			
		||||
        $res = $this->getHttpResponse($url, $header, true);
 | 
			
		||||
        $data = json_decode($res, true);
 | 
			
		||||
        if ($data['data']['status'] === 0) {
 | 
			
		||||
            // 登陆刷新Token
 | 
			
		||||
            $this->login();
 | 
			
		||||
        } else {
 | 
			
		||||
            $this->saveToken($data['data']);
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
    // 获取token
 | 
			
		||||
    private function getToken(): string
 | 
			
		||||
    {
 | 
			
		||||
        $token_info_find = json_decode(file_get_contents($this->token_path), true);
 | 
			
		||||
        // 有效期判断
 | 
			
		||||
        $expire_time = intval($token_info_find['expire_time'] / 1000);
 | 
			
		||||
        $token = '';
 | 
			
		||||
        if ($expire_time - time() < 600) {
 | 
			
		||||
            // 刷新token
 | 
			
		||||
            $url = $this->host . $this->refresh_token . '?token=' . $token_info_find['token'];
 | 
			
		||||
            $header = ["Authorization:Bearer {$token_info_find['token']}"];
 | 
			
		||||
            $res = $this->getHttpResponse($url, $header, true);
 | 
			
		||||
            $arr_res = json_decode($res, true);
 | 
			
		||||
            if ($arr_res['data']['status'] === 0) {
 | 
			
		||||
                // 登陆更新token
 | 
			
		||||
                $token = ($this->login())['token'];
 | 
			
		||||
            } else {
 | 
			
		||||
                $token = $arr_res['data']['token'];
 | 
			
		||||
                $token_info = [];
 | 
			
		||||
                $token_info['token'] = $token;
 | 
			
		||||
                $token_info['expire_time'] = $arr_res['data']['expire_time'];
 | 
			
		||||
                // 保存Token
 | 
			
		||||
                file_put_contents($this->token_path, json_encode($token_info));
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            $token = $token_info_find['token'];
 | 
			
		||||
        }
 | 
			
		||||
        return $token;
 | 
			
		||||
        $token_info = json_decode(file_get_contents($this->token_path), true);
 | 
			
		||||
        return $token_info['token'];
 | 
			
		||||
    }
 | 
			
		||||
    // 接口客户端
 | 
			
		||||
    public function payQuery(array $query): array
 | 
			
		||||
    // 保存token
 | 
			
		||||
    private function saveToken($data)
 | 
			
		||||
    {
 | 
			
		||||
        $token = $this->getToken();
 | 
			
		||||
        if ($token) {
 | 
			
		||||
            $url = $this->host . $this->find_transactions . '?client_version=7.0.0&token=' . $token;
 | 
			
		||||
            $header = ['Content-Type: application/json;charset=UTF-8'];
 | 
			
		||||
            // 构建订单查询
 | 
			
		||||
            $now = time();
 | 
			
		||||
            $begin_time = ($now - 175) * 1000;
 | 
			
		||||
            $end_time = $now * 1000;
 | 
			
		||||
            $query['date_start'] = $begin_time;
 | 
			
		||||
            $query['date_end'] = $end_time;
 | 
			
		||||
            // 查询订单列表
 | 
			
		||||
            $res_order = $this->getHttpResponse($url, $header, json_encode($query));
 | 
			
		||||
            $arr_res = json_decode($res_order, true);
 | 
			
		||||
            $list = [];
 | 
			
		||||
            if ($arr_res['code'] === 50000) {
 | 
			
		||||
                $list = $arr_res['data']['records'];
 | 
			
		||||
            }
 | 
			
		||||
            // 重构订单流水,返回数组
 | 
			
		||||
            $moneyList = [];
 | 
			
		||||
            if ($list) {
 | 
			
		||||
                $order_no = [];
 | 
			
		||||
                $payway = [];
 | 
			
		||||
                $price = [];
 | 
			
		||||
                $channel = [];
 | 
			
		||||
                $payways = [2 => 'alipay', 3 => 'wxpay'];
 | 
			
		||||
                foreach ($list as $value) {
 | 
			
		||||
                    // 平台订单流水号
 | 
			
		||||
                    $order_no[] = $value['order_sn'];
 | 
			
		||||
                    // 支付类型
 | 
			
		||||
                    $payway[] = $payways[$value['payway']];
 | 
			
		||||
                    // 收款金额
 | 
			
		||||
                    $price[] = $value['original_amount'] / 100;
 | 
			
		||||
                    // 收款渠道(二维码编号)
 | 
			
		||||
                    $channel[] = $value['terminal_device_fingerprint'];
 | 
			
		||||
                }
 | 
			
		||||
                $moneyList['order_no'] = $order_no;
 | 
			
		||||
                $moneyList['payway'] = $payway;
 | 
			
		||||
                $moneyList['price'] = $price;
 | 
			
		||||
                $moneyList['channel'] = $channel;
 | 
			
		||||
            }
 | 
			
		||||
            return $moneyList;
 | 
			
		||||
        } else {
 | 
			
		||||
            return [];
 | 
			
		||||
        }
 | 
			
		||||
        $token = $data['token'];
 | 
			
		||||
        file_put_contents($this->token_path, json_encode(['token' => $token, 'update_time' => date('Y-m-d H:i:s')]));
 | 
			
		||||
    }
 | 
			
		||||
    // 请求外部资源
 | 
			
		||||
    private function getHttpResponse($url, $header = [], $post = null, $timeout = 10)
 | 
			
		||||
@@ -148,11 +170,13 @@ class ShouQianBa
 | 
			
		||||
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
 | 
			
		||||
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 | 
			
		||||
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
 | 
			
		||||
        curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie_path);
 | 
			
		||||
        curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_path);
 | 
			
		||||
        if ($header) {
 | 
			
		||||
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
 | 
			
		||||
        } else {
 | 
			
		||||
            $httpheader[] = "Accept: */*";
 | 
			
		||||
            $httpheader[] = "Accept-Language: zh-CN,zh;q=0.8";
 | 
			
		||||
            $httpheader[] = "Accept-Language: zh-CN,zh;q=0.9";
 | 
			
		||||
            $httpheader[] = "Connection: close";
 | 
			
		||||
            curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							@@ -1 +1 @@
 | 
			
		||||
{"code":0,"msg":"没有新订单"}
 | 
			
		||||
{"code":1,"msg":"\u67091\u4e2a\u65b0\u8ba2\u5355","orders":[{"id":36315,"pid":1001,"aid":7,"cid":7,"patt":1}]}
 | 
			
		||||
		Reference in New Issue
	
	Block a user