增加api查询余额

This commit is contained in:
lingling 2025-02-20 21:00:55 +08:00
parent 74a8c2d512
commit 0b765fc968
8 changed files with 71 additions and 343 deletions

View File

@ -10,10 +10,13 @@ use support\Log;
*/ */
class PaymentNew class PaymentNew
{ {
public static function generate_encrypt_value($data, $secret_key)
protected static $secret_key = "sZ2wAfh1lMkxBVrlY4uZY8Fj92E4scFf";
protected static $ShopUserLongId = "776ae472-d4fc-435c-9639-be5763138d95";
protected static function generate_encrypt_value($data)
{ {
// 1. 过滤掉 EncryptValue 和值为 null 的参数 // 1. 过滤掉 EncryptValue 和值为 null 的参数
$filtered_data = array_filter($data, function($value, $key) { $filtered_data = array_filter($data, function ($value, $key) {
return $key !== 'EncryptValue' && $value !== null; return $key !== 'EncryptValue' && $value !== null;
}, ARRAY_FILTER_USE_BOTH); }, ARRAY_FILTER_USE_BOTH);
@ -36,10 +39,10 @@ class PaymentNew
// 移除最后一个多余的 & // 移除最后一个多余的 &
$param_str = rtrim($param_str, '&'); $param_str = rtrim($param_str, '&');
// 添加 HashKey // 添加 HashKey
$param_str .= "&HashKey=" . trim($secret_key); $param_str .= "&HashKey=" . trim(self::$secret_key);
// 输出拼接后的字符串以供调试(可选) // 输出拼接后的字符串以供调试(可选)
echo "Lowercase string: $param_str\n"; // echo "Lowercase string: $param_str\n";
// 4. 转换为小写 // 4. 转换为小写
$param_str = strtolower($param_str); $param_str = strtolower($param_str);
@ -54,21 +57,19 @@ class PaymentNew
/** /**
* 转账 * 转账
*/ */
public static function pushMoney($money, $payeeAccountName, $payeeAccountNumber, $payeeBankName,$orderId) public static function pushMoney($money, $payeeAccountName, $payeeAccountNumber, $payeeBankName, $orderId)
{ {
$secret_key = "sZ2wAfh1lMkxBVrlY4uZY8Fj92E4scFf";
$url = "https://mdf.hr5688.com/api/createPaymentOrder"; $url = "https://mdf.hr5688.com/api/createPaymentOrder";
$PaymentChannelId = 0; $PaymentChannelId = 0;
if($payeeBankName == "bKash"){ if ($payeeBankName == "bKash") {
$PaymentChannelId = 34; $PaymentChannelId = 34;
}else{ } else {
$PaymentChannelId = 35; $PaymentChannelId = 35;
} }
// Guzzle HTTP client // Guzzle HTTP client
$client = new Client(); $client = new Client();
var_dump(11111111111); // var_dump($orderId);
var_dump($orderId);
// 请求数据 // 请求数据
$payload = [ $payload = [
"Amount" => $money, "Amount" => $money,
@ -80,15 +81,13 @@ class PaymentNew
"PayeeIFSCCode" => "", "PayeeIFSCCode" => "",
"PaymentChannelId" => $PaymentChannelId, "PaymentChannelId" => $PaymentChannelId,
"ShopInformUrl" => "http://149.129.107.38", "ShopInformUrl" => "http://149.129.107.38",
"ShopOrderId" => $orderId."", "ShopOrderId" => $orderId . "",
"ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95" "ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95"
]; ];
var_dump($payload);
// 生成加密值 // 生成加密值
$encrypt_value = self::generate_encrypt_value($payload, $secret_key); $encrypt_value = self::generate_encrypt_value($payload);
var_dump($encrypt_value);
$payload["EncryptValue"] = $encrypt_value; $payload["EncryptValue"] = $encrypt_value;
var_dump($encrypt_value);
try { try {
// 发送 POST 请求 // 发送 POST 请求
$response = $client->post($url, [ $response = $client->post($url, [
@ -98,7 +97,6 @@ class PaymentNew
'Content-Type' => 'application/json', 'Content-Type' => 'application/json',
] ]
]); ]);
var_dump($response);
// 获取响应内容 // 获取响应内容
$responseBody = $response->getBody()->getContents(); $responseBody = $response->getBody()->getContents();
$httpCode = $response->getStatusCode(); $httpCode = $response->getStatusCode();
@ -106,13 +104,51 @@ class PaymentNew
if ($httpCode == 200) { if ($httpCode == 200) {
echo $responseBody; echo $responseBody;
} else { } else {
echo "Error: HTTP Code $httpCode\n"; Log::warning("请求支付api失败状态码:" . $httpCode . "responseBody:" . $responseBody);
echo $responseBody; echo $responseBody;
} }
return $responseBody; return $responseBody;
} catch (\GuzzleHttp\Exception\RequestException $e) { } catch (\GuzzleHttp\Exception\RequestException $e) {
echo "Request failed: " . $e->getMessage(); Log::warning("请求支付api失未知失败:" . $e->getMessage());
}
}
/**
* 查询商户余额
* 返回-1则是失败 其他是余额
*/
public static function shopGetBalance()
{
$url = "https://mdf.hr5688.com/api/shopGetBalance";
$payload = [
"CurrencyId" => 11,
"ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95"
];
$encrypt_value = self::generate_encrypt_value($payload);
$payload["EncryptValue"] = $encrypt_value;
$client = new Client();
try {
// 发送 POST 请求
$response = $client->post($url, [
'json' => $payload,
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
]
]);
// 获取响应内容
$responseBody = $response->getBody()->getContents();
$httpCode = $response->getStatusCode();
if ($httpCode == 200) {
return json_decode($responseBody)->AmountAvailable;
} else {
Log::warning("请求支付api失败状态码:" . $httpCode . "responseBody:" . $responseBody);
return -1;
}
} catch (\GuzzleHttp\Exception\RequestException $e) {
Log::warning("请求支付api失未知失败:" . $e->getMessage());
} }
} }
} }

View File

@ -81,11 +81,10 @@ class SendCode
return $responseData['status']; return $responseData['status'];
} }
if($responseData['code'] == 1){ if($responseData['code'] == 1){
Log::warning("token无效"); Log::warning("号商api token无效");
return 2; return 2;
} }
if($responseData['code'] == 2){ if($responseData['code'] == 2){
echo('2WS号不存在');
return 3; return 3;
} }
return -1; return -1;

View File

@ -2,6 +2,7 @@
namespace app\controller; namespace app\controller;
use App\Utils\API\PaymentNew;
use support\Request; use support\Request;
use App\Utils\ApiResponse; use App\Utils\ApiResponse;
@ -12,6 +13,7 @@ class IndexController
public function index(Request $request) public function index(Request $request)
{ {
var_dump(PaymentNew::shopGetBalance());
return response()->file(public_path() . '/index.html'); return response()->file(public_path() . '/index.html');
} }

View File

@ -55,9 +55,18 @@ class DashboardController
* 登录人数 注册人数 提款人数 默认今天 * 登录人数 注册人数 提款人数 默认今天
*/ */
$res = []; $res = [];
$res['user_total'] = User::count();
$res['register'] = User::where('f_id',0)->count(); // 获取今天的开始和结束时间
$res['inviteregistration'] =User::where('f_id','>',0)->count(); // 统计不同的 user_id 个数; $data = $request->post();
$startOfDay = $data['start_time']; // 今天的开始时间00:00:00
$endOfDay = $data['end_time']; // 今天的结束时间23:59:59
$login = User::whereBetween('login_time', [ $startOfDay, $endOfDay])->count();
$registration = User::whereBetween('created_at', [ \Carbon\Carbon::createFromTimestamp($startOfDay)->toDateTimeString(), \Carbon\Carbon::createFromTimestamp($endOfDay)->toDateTimeString()])->count();
$withdraw=Withdraw::whereBetween('createtime2', [ \Carbon\Carbon::createFromTimestamp($startOfDay)->toDateTimeString(), \Carbon\Carbon::createFromTimestamp($endOfDay)->toDateTimeString()])->count();;
$res['login']=$login;
$res['registration']=$registration;
$res['withdraw']=$withdraw;
return ApiResponse::success(200, $res); return ApiResponse::success(200, $res);
} }
} }

View File

@ -1,110 +0,0 @@
<?php
namespace app\model\app;
use support\Model;
/**
* @property integer $id ID (主键)
* @property string $title 标题
* @property string $content 内容 (包含 HTML)
* @property integer $status 状态 0禁用 1启用
* @property string $status_text 状态文本
* @property integer $createtime 创建时间
* @property integer $updatetime 更新时间
*/
class Announcement extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'announcements'; // 表名
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id'; // 主键
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true; // 不使用自动时间戳
/**
* 可以赋值字段
*
* @var array
*/
protected $fillable = [
'title',
'content',
'status',
'status_text',
'createtime',
'updatetime',
];
/**
* 字段类型
*
* @var array
*/
protected $casts = [
'createtime' => 'integer',
'updatetime' => 'integer',
'status' => 'integer',
];
/**
* 获取创建时间的格式化值
*
* @param mixed $value
* @return string
*/
public function getCreatetimeAttribute($value)
{
return date('Y-m-d H:i:s', $value);
}
/**
* 获取更新时间的格式化值
*
* @param mixed $value
* @return string
*/
public function getUpdatetimeAttribute($value)
{
return date('Y-m-d H:i:s', $value);
}
/**
* 获取状态文本
*
* @param mixed $value
* @return string
*/
public function getStatusTextAttribute($value)
{
return $value ?? '未设置';
}
}
/**
* CREATE TABLE `announcements` (
`id` INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY COMMENT 'ID (主键)',
`title` VARCHAR(255) NOT NULL COMMENT '标题',
`content` TEXT NOT NULL COMMENT '内容 (包含 HTML)',
`status` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '状态 0禁用 1启用',
`status_text` VARCHAR(255) DEFAULT NULL COMMENT '状态文本',
`createtime` INT(11) UNSIGNED NOT NULL COMMENT '创建时间',
`updatetime` INT(11) UNSIGNED DEFAULT NULL COMMENT '更新时间',
KEY `status` (`status`),
KEY `createtime` (`createtime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='公告表';
*/

View File

@ -1,179 +0,0 @@
<?php
namespace app\model\app;
use support\Model;
/**
* @property integer $id ID (主键)
* @property string $username 用户名
* @property string $invite_code 邀请码
* @property integer $is_active 是否激活
* @property string $login_ip 登录 IP
* @property string $join_ip 加入 IP
* @property integer $login_time 登录时间
* @property integer $prev_time 上次登录时间
* @property integer $status 状态 0正常 1禁用
* @property float $money 账户余额
* @property float $admin_money 管理员余额
* @property float $all_team_money 总团队余额
* @property float $task_income_money 任务收入
* @property integer $task_status 任务状态
* @property float $today_task_income 今日任务收入
* @property float $today_team_income 今日团队收入
* @property integer $growth_value 成长值
* @property integer $vip_id VIP ID
* @property float $withdraw_money 提现金额
* @property integer $f_id 上级ID
* @property integer $ff_id 二级上级ID
* @property integer $fff_id 三级上级ID
* @property integer $top_id 顶级ID
* @property string $path 路径
* @property string $remark 备注
* @property integer $createtime 创建时间
* @property integer $updatetime 更新时间
*/
class User extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'user_info'; // 表名
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id'; // 主键
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true; // 如果不需要自动维护创建和更新时间,可以将此设置为 false
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'username',
'invite_code',
'is_active',
'login_ip',
'join_ip',
'login_time',
'prev_time',
'status',
'money',
'admin_money',
'all_team_money',
'task_income_money',
'task_status',
'today_task_income',
'today_team_income',
'growth_value',
'vip_id',
'withdraw_money',
'f_id',
'ff_id',
'fff_id',
'top_id',
'path',
'remark',
'createtime',
'updatetime',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'money' => 'float',
'admin_money' => 'float',
'all_team_money' => 'float',
'task_income_money' => 'float',
'today_task_income' => 'float',
'today_team_income' => 'float',
'growth_value' => 'integer',
'withdraw_money' => 'float',
'createtime' => 'integer',
'updatetime' => 'integer',
'status' => 'integer',
];
/**
* 获取登录时间的格式化值
*
* @param mixed $value
* @return string
*/
public function getLoginTimeAttribute($value)
{
return date('Y-m-d H:i:s', $value);
}
/**
* 获取创建时间的格式化值
*
* @param mixed $value
* @return string
*/
public function getCreatetimeAttribute($value)
{
return date('Y-m-d H:i:s', $value);
}
/**
* 获取更新时间的格式化值
*
* @param mixed $value
* @return string
*/
public function getUpdatetimeAttribute($value)
{
return date('Y-m-d H:i:s', $value);
}
}
/**
* CREATE TABLE `users` (
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
`username` VARCHAR(255) NOT NULL COMMENT '用户名',
`invite_code` VARCHAR(255) NOT NULL COMMENT '邀请码',
`is_active` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否激活 (0:未激活, 1:已激活)',
`login_ip` VARCHAR(45) NOT NULL COMMENT '最后登录IP',
`join_ip` VARCHAR(45) NOT NULL COMMENT '注册IP',
`login_time` INT(11) NOT NULL COMMENT '最后登录时间 (Unix时间戳)',
`prev_time` INT(11) NOT NULL COMMENT '上次活动时间 (Unix时间戳)',
`status` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '状态 (1: 正常, 0: 禁用)',
`money` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '账户余额',
`admin_money` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '管理员账户余额',
`all_team_money` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '团队总金额',
`task_income_money` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '任务收入金额',
`task_status` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '任务状态 (0: 未完成, 1: 完成)',
`today_task_income` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '今天的任务收入',
`today_team_income` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '今天的团队收入',
`growth_value` INT(11) NOT NULL DEFAULT 0 COMMENT '成长值',
`vip_id` INT(11) NOT NULL DEFAULT 0 COMMENT 'VIP等级ID',
`withdraw_money` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '可提现金额',
`f_id` INT(11) NOT NULL DEFAULT 0 COMMENT '上一级用户ID',
`ff_id` INT(11) NOT NULL DEFAULT 0 COMMENT '上上级用户ID',
`fff_id` INT(11) NOT NULL DEFAULT 0 COMMENT '上上上级用户ID',
`top_id` INT(11) NOT NULL DEFAULT 0 COMMENT '最高层级ID',
`path` TEXT NOT NULL COMMENT '用户路径',
`remark` TEXT DEFAULT NULL COMMENT '备注',
`createtime` INT(11) NOT NULL COMMENT '创建时间 (Unix时间戳)',
`updatetime` INT(11) NOT NULL DEFAULT 0 COMMENT '更新时间 (Unix时间戳)',
PRIMARY KEY (`id`),
UNIQUE KEY `invite_code` (`invite_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户信息表';
*/

View File

@ -1,29 +0,0 @@
<?php
namespace app\model;
use support\Model;
class Test extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'test';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
}

View File

@ -94,7 +94,7 @@ class Task2
if ($status == 3) { if ($status == 3) {
// 如果账户不存在直接删除 // 如果账户不存在直接删除
// $value->delete(); // $value->delete();
Log::warning("账户不存在",$value->phone); Log::warning("ws 在第三方api不存在 ws号".$value->phone);
} }
// UserPhoneLogDao::setOnlineTimeByPhone($value->phone, $status, $currentTimestamp); // UserPhoneLogDao::setOnlineTimeByPhone($value->phone, $status, $currentTimestamp);
// $value->last_time = $currentTimestamp; // $value->last_time = $currentTimestamp;