Files
li 1b24994e74 feat: 后端全量更新 - 含所有本次需求
- Contract.php: 返回合约账户余额(balance_contract)
- My.php: 地址管理增加BTC/ETH
- AppContract.php: 一键平仓(closeall)
- AppProxy.php: 代理专属注册链接 + 分级权限(L1/L2)
- site.php: 手续费减半(0.018→0.009)
- agent_permission_setup.sql: 代理权限SQL
- crypto_news_crawler.py: 新闻自动采集脚本
2026-03-30 20:16:32 +08:00

112 lines
3.3 KiB
PHP
Executable File

<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\Config;
/**
* API校验接口
*/
class Authentication extends Api
{
// 无需登录的接口,*表示全部
protected $noNeedLogin = ['*'];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
/**
* 获取提币地址
*/
public function get_address()
{
$res = $this->request->get();
if(!isset($res['Signature']) || !isset($res['api_key'])){
$return = ['code'=>10001,'msg'=>'参数错误'];
return json_encode($return);
}
$sign1 = urlencode($res['Signature']);
//解密
$user_api = Db::name("app_api_key")->where("api_key",$res['api_key'])->find();
if(empty($user_api)){
$return = ['code'=>10002,'msg'=>'验签失败'];
return json_encode($return);
}
$data = [
'api_key' => $user_api['api_key'],
'method' => 'HmacSHA256',
'times' => $res['times'],
];
$str = $this->formatParameters($data, false);
$sign2 = urlencode(base64_encode(hash_hmac("sha256", $str, $user_api['secret_key'],TRUE)));
$return = ['sign2'=>$sign2,'sign1'=>$sign1];
if($sign2 == $sign1){
$address = Db::name("app_currency_user")->field("address,tron_address")->where("user_id",$user_api['user_id'])->where("curr_id",1)->find();
$return = ['code'=>200,'msg'=>'success','data'=>$address];
}
return json_encode($return);
// return json_encode($data);
}
public function test()
{
$data = [
'api_key' => "gih03i2a8x-id0ugpfrs-vt4rriioyz-lqszbm",
'method' => 'HmacSHA256',
'times' => date('Y-m-d/H:i:s', time()),
];
$sign = $this->getVerifySign($data);
//模拟解密
$arr = [];
parse_str($sign,$arr);
$user_api = Db::name("app_api_key")->where("api_key",$arr['api_key'])->find();
if(empty($user_api)){
$this->error("验签失败");
}
$data = [
'api_key' => $arr['api_key'],
'method' => 'HmacSHA256',
'times' => $arr['times'],
];
$str = $this->formatParameters($data, false);
$sign2 = urlencode(base64_encode(hash_hmac("sha256", $str, $user_api['secret_key'],TRUE)));
var_dump(urlencode($arr['Signature']),$sign2);
}
//数据组装
public function getVerifySign($data)
{
$string = $this->formatParameters($data, false);
$sign = urlencode(base64_encode(hash_hmac("sha256", $string, "phnp5ro5-0ds89uvbhw-c4siqgltt-imxp",TRUE)));
return $string.'&Signature='.$sign;
}
public function formatParameters($paraMap, $urlencode)
{
$buff = "";
ksort($paraMap);
foreach ($paraMap as $k => $v) {
if($k=="sign"){
continue;
}
if ($urlencode) {
$v = urlencode($v);
}
$buff .= $k . "=" . $v . "&";
}
$reqPar = '';
if (strlen($buff) > 0) {
$reqPar = substr($buff, 0, strlen($buff) - 1);
}
return $reqPar;
}
}