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: 新闻自动采集脚本
This commit is contained in:
Executable
+164
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use think\Db;
|
||||
use think\Config;
|
||||
use think\Loader;
|
||||
/**
|
||||
* 谷歌验证接口
|
||||
*/
|
||||
class Google extends Api
|
||||
{
|
||||
// 无需登录的接口,*表示全部
|
||||
protected $noNeedLogin = ['*'];
|
||||
// 无需鉴权的接口,*表示全部
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
public function index(){
|
||||
$salt = $this->request->get("token");
|
||||
$admin = Db::name("admin")->where("salt",$salt)->find();
|
||||
if(empty($admin)){
|
||||
echo "非法操作";exit;
|
||||
}
|
||||
if($admin['secret']){
|
||||
echo "请勿重复绑定";exit;
|
||||
}
|
||||
if($admin['secret_y'] && $admin['updatetime']>time()-600){
|
||||
import('lib.GoogleAuthenticator', EXTEND_PATH , '.php');
|
||||
$ga = new \PHPGangsta_GoogleAuthenticator();
|
||||
$secret = $admin['secret_y'];
|
||||
$qrCodeUrl = $ga->getQRCodeGoogleUrl('HASH', $secret);
|
||||
}else{
|
||||
import('lib.GoogleAuthenticator', EXTEND_PATH , '.php');
|
||||
$ga = new \PHPGangsta_GoogleAuthenticator();
|
||||
$secret = $ga->createSecret();
|
||||
$qrCodeUrl = $ga->getQRCodeGoogleUrl('HASH', $secret);
|
||||
Db::name("admin")->where("id",$admin['id'])->update(['secret_y'=>$secret,'updatetime'=>time()]);
|
||||
}
|
||||
echo '<div style="display: flex;align-items: center;justify-content: center;width: 100%;height: 100vh;text-align: center;">
|
||||
<div>
|
||||
<div style="padding: 20px;font-size: 18px;">
|
||||
<span>'.$secret.'</span>
|
||||
</div>
|
||||
<div>
|
||||
<img src="'.$qrCodeUrl.'" alt="">
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成私钥二维码
|
||||
*/
|
||||
public function get_keys(){
|
||||
import('lib.GoogleAuthenticator', EXTEND_PATH , '.php');
|
||||
$ga = new \PHPGangsta_GoogleAuthenticator();
|
||||
$secret = $ga->createSecret();
|
||||
$qrCodeUrl = $ga->getQRCodeGoogleUrl('APEC', $secret);
|
||||
$data = array(
|
||||
"secret" => $secret,
|
||||
"code_url" => $qrCodeUrl,
|
||||
);
|
||||
$this->success("ok",$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证并绑定私钥
|
||||
*/
|
||||
public function band_secret()
|
||||
{
|
||||
$user_id = $this->auth->id;
|
||||
$secret = $this->request->post("secret");
|
||||
$code = $this->request->post("code");
|
||||
if(empty($secret)){
|
||||
$this->error(__("请输入私钥"));
|
||||
}
|
||||
if(empty($code)){
|
||||
$this->error(__("请输入验证码"));
|
||||
}
|
||||
|
||||
$user = Db::name("user")->where("id",$user_id)->find();
|
||||
if($user['secret']){
|
||||
$this->error(__("请勿重复绑定"));
|
||||
}
|
||||
import('lib.GoogleAuthenticator', EXTEND_PATH , '.php');
|
||||
$ga = new \PHPGangsta_GoogleAuthenticator();
|
||||
$checkResult = $ga->verifyCode($secret, $code, 1); // 2 = 2*30sec clock tolerance
|
||||
if ($checkResult) {
|
||||
$user_update = array(
|
||||
"secret" => base64_encode($secret),
|
||||
"updatetime" => time(),
|
||||
);
|
||||
$res = Db::name("user")->where("id",$user_id)->update($user_update);
|
||||
if($res){
|
||||
$this->success(__("绑定成功"));
|
||||
}else{
|
||||
$this->error(__("绑定失败"));
|
||||
}
|
||||
} else {
|
||||
$this->error(__("绑定失败"),$checkResult);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证私钥验证码
|
||||
*/
|
||||
public function check_code($code)
|
||||
{
|
||||
$secret = $this->auth->secret;
|
||||
if(!$secret){
|
||||
$this->error(__("请先绑定谷歌验证"));
|
||||
}
|
||||
import('lib.GoogleAuthenticator', EXTEND_PATH , '.php');
|
||||
$ga = new \PHPGangsta_GoogleAuthenticator();
|
||||
$checkResult = $ga->verifyCode(base64_decode($secret), $code, 1); // 2 = 2*30sec clock tolerance
|
||||
if ($checkResult) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function check_test()
|
||||
{
|
||||
$code = $this->request->post("code");
|
||||
controller("Google")->check_code($code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证并绑定私钥
|
||||
*/
|
||||
public function jiechu_band()
|
||||
{
|
||||
$user_id = $this->auth->id;
|
||||
$secret = $this->auth->secret;
|
||||
$code = $this->request->post("code");
|
||||
if(empty($code)){
|
||||
$this->error(__("请输入验证码"));
|
||||
}
|
||||
|
||||
if(!$secret){
|
||||
$this->error(__("暂未绑定"));
|
||||
}
|
||||
import('lib.GoogleAuthenticator', EXTEND_PATH , '.php');
|
||||
$ga = new \PHPGangsta_GoogleAuthenticator();
|
||||
$checkResult = $ga->verifyCode(base64_decode($secret), $code, 1); // 2 = 2*30sec clock tolerance
|
||||
if ($checkResult) {
|
||||
$user_update = array(
|
||||
"secret" => "",
|
||||
"updatetime" => time(),
|
||||
);
|
||||
$res = Db::name("user")->where("id",$user_id)->update($user_update);
|
||||
if($res){
|
||||
$this->success(__("解绑成功"));
|
||||
}else{
|
||||
$this->error(__("解绑失败"));
|
||||
}
|
||||
} else {
|
||||
$this->error(__("验证失败"),$checkResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user