first commit
This commit is contained in:
187
app/common/service/JK8Services.php
Normal file
187
app/common/service/JK8Services.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
namespace app\common\service;
|
||||
|
||||
use think\Exception;
|
||||
|
||||
class Jk8Services
|
||||
{
|
||||
private $config = [];
|
||||
private $domain = '';
|
||||
private $accessId = '';
|
||||
private $token = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->config = config('jk8');
|
||||
$this->domain = config('jk8.domain');
|
||||
$this->accessId = config('jk8.access_id');
|
||||
$this->token = config('jk8.token');
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建请求参数
|
||||
* @param string $method
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
public function createParam(string $method, array $params): array
|
||||
{
|
||||
return [
|
||||
'module' => $method,
|
||||
'accessId' => $this->accessId,
|
||||
'accessToken' => $this->token,
|
||||
...$params,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
* @param string $username
|
||||
* @param string $nickname
|
||||
* @param string $referrerCode
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function register(string $username, string $nickname, string $referrerCode): string
|
||||
{
|
||||
$params = $this->createParam('/member/register', [
|
||||
'username' => $username,
|
||||
// 'name' => $nickname,
|
||||
'referrerCode' => $referrerCode,
|
||||
]);
|
||||
$result = doCurl($this->domain, $params);
|
||||
if (($result['status'] ?? '') === 'ERROR') {
|
||||
throw new Exception($result['data']['message'] ?? 'Remote API Error');
|
||||
}
|
||||
return $result['data']['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取促销列表
|
||||
* @param string $userId
|
||||
* @return array|mixed|null
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getPromotionList(string $userId): mixed
|
||||
{
|
||||
$params = $this->createParam('/users/getPromotionList', [
|
||||
'userId' => $userId,
|
||||
]);
|
||||
$result = doCurl($this->domain, $params);
|
||||
if (($result['status'] ?? '') === 'ERROR') {
|
||||
throw new Exception($result['data']['message'] ?? 'Remote API Error');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账
|
||||
* @param string $username
|
||||
* @return array|mixed|null
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setScore(string $username): mixed
|
||||
{
|
||||
$params = $this->createParam('/member/setScore', [
|
||||
'username' => $username,
|
||||
]);
|
||||
$result = doCurl($this->domain, $params);
|
||||
if (($result['status'] ?? '') === 'ERROR') {
|
||||
throw new Exception($result['data']['message'] ?? 'Remote API Error');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 存款
|
||||
* @param array $params 参数
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @throws GameException
|
||||
*/
|
||||
public function deposit(array $params): array
|
||||
{
|
||||
$auth = $this->auth($params);
|
||||
if (!$auth['status']) {
|
||||
throw new GameException($auth['message']);
|
||||
}
|
||||
$data = [
|
||||
'username' => $params['name'],
|
||||
'auth' => $auth['auth'],
|
||||
'amount' => $params['amount'],
|
||||
'currency' => 'MYR',
|
||||
'orderid' => $params['orderNo'],
|
||||
'redirect_url' => $this->returnUrl . '?orderNo='.$params['orderNo'],
|
||||
];
|
||||
return doFormCurl($this->domain . '/merchant/generate_orders',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 代付
|
||||
* @param array $params 参数
|
||||
* @throws GameException|Exception
|
||||
*/
|
||||
public function payout(array $params): array
|
||||
{
|
||||
$params['type'] = 'online';
|
||||
$auth = $this->auth($params);
|
||||
if (!$auth['status']) {
|
||||
throw new GameException($auth['message']);
|
||||
}
|
||||
$data = [
|
||||
'auth' => $auth['auth'],
|
||||
'amount' => $params['amount'],
|
||||
'currency' => 'MYR',
|
||||
'orderid' => $params['orderNo'],
|
||||
'bank_id' => $params['bankCode'],
|
||||
'holder_name' => $params['bankAccountName'],
|
||||
'account_no' => $params['bankAccountNo'],
|
||||
];
|
||||
return doFormCurl($this->domain . '/merchant/withdraw_orders',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证
|
||||
* @param array $params 参数
|
||||
* @throws Exception
|
||||
*/
|
||||
public function depositVerifySign(array $params)
|
||||
{
|
||||
$orderInfo = PlayerRechargeRecord::query()
|
||||
->where(['tradeno' => $params['order_id']])
|
||||
->first();
|
||||
if (empty($orderInfo)) {
|
||||
return false;
|
||||
}
|
||||
return MD5($this->config[$orderInfo['payment_method']]['secret_key'] . $params['order_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证
|
||||
* @param array $params 参数
|
||||
* @throws Exception
|
||||
*/
|
||||
public function withdrawalVerifySign(array $params)
|
||||
{
|
||||
return MD5($this->config['online']['secret_key'] . $params['order_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单查询
|
||||
* @param $orderNo
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function query($orderNo): array
|
||||
{
|
||||
$orderInfo = PlayerRechargeRecord::query()
|
||||
->where(['tradeno' => $orderNo])
|
||||
->first();
|
||||
$data = [
|
||||
'username' => $this->config[$orderInfo['payment_method']]['merchantId'],
|
||||
'id' => $orderNo,
|
||||
];
|
||||
return doFormCurl($this->domain . '/merchant/check_status',$data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user