afa 5 сар өмнө
parent
commit
d0d0af2ba0

+ 46 - 0
app/api/command/Order.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace app\api\command;
+
+use app\common\service\OrderService;
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+
+class Order extends Command
+{
+    protected function configure()
+    {
+        $this->setName('Order')->setDescription("订单相关定时任务");
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        /* 永不超时 */
+//        ini_set('max_execution_time', 0);
+
+        // 记录开始运行的时间
+        $GLOBALS['_beginTime'] = microtime(TRUE);
+        $output->writeln('定时任务开始执行:' . date('Y-m-d H:i:s', time()));
+
+        $output->writeln("开始匹配订单:");
+        (new OrderService())->checkOrderStatus();
+        $output->writeln("订单匹配运行结束");
+        $output->writeln("");
+
+        $output->writeln("开始重置订单:");
+        (new OrderService())->resetOrderStatus();
+        $output->writeln("重置订单结束");
+        $output->writeln("");
+
+        $output->writeln("开始补充回调:");
+        (new OrderService())->resetCallBack();
+        $output->writeln("回调结束");
+        $output->writeln("");
+
+
+        /*** 这里写计划任务列表集 END ***/
+        $time_total = round(microtime(true) - $GLOBALS['_beginTime'], 4);//计算耗时
+        $output->writeln('定时任务执行结束:' . date('Y-m-d H:i:s', time()) . '; 耗时:' . $time_total . '秒');
+    }
+}

+ 5 - 10
app/api/common.php

@@ -1,11 +1,6 @@
 <?php
-// 这是系统自动生成的公共文件
-if (!function_exists('create_out_trade_no')) {
-    /**
-     * 生成随机订单号
-     */
-    function create_out_trade_no()
-    {
-        return date('YmdHis',time()).rand(10000,99999);
-    }
-}
+declare (strict_types = 1);
+
+// 这是自定义的公共文件
+use think\Log;
+

+ 0 - 33
app/api/config/site.php

@@ -1,33 +0,0 @@
-<?php
-// +----------------------------------------------------------------------
-// | 应用设置
-// +----------------------------------------------------------------------
-
-return [
-     'auth'=>[
-          //允许同时在线的设备数量
-         'allow_device_num'=>10,
-          //使用期间自动续时
-         'keepalive'=>true,
-          //保持登陆时间,单位秒
-         'keepalive_time'=>24*3600*30,
-         //用户信息保存适配器,更换适配器需要实现app\api\service\auth\Adapter接口
-         'adapter'=>app\api\service\auth\MysqlAdapter::class,
-     ],
-    'upload'=>[
-        //上传地址
-        'uploadurl' => 'ajax/upload',
-        //上传适配器
-        'disks'   => 'local_public',
-        //最大可上传大小,单位mb
-        'maxsize'   => 10,
-        //可上传的文件类型
-        'mimetype'  => 'jpg,png,bmp,jpeg,gif,txt,doc,docx,xls,xlsx',
-        //生成缩略图
-        'thumb'=>true,
-        //压缩图片
-        'compress'=>true,
-        //图片加水印
-        'watermark'=>true
-    ]
-];

+ 0 - 56
app/api/controller/Api.php

@@ -1,56 +0,0 @@
-<?php
-/**
- * ----------------------------------------------------------------------------
- * 行到水穷处,坐看云起时
- * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
- * ----------------------------------------------------------------------------
- * Author: 老成
- * email:85556713@qq.com
- */
-declare(strict_types=1);
-
-namespace app\api\controller;
-
-use app\api\service\ApiAuthService;
-use app\common\controller\BaseController;
-use think\exception\HttpResponseException;
-use think\facade\Config;
-use think\facade\Cookie;
-use think\Response;
-
-class Api extends BaseController
-{
-    /**
-     * 当前登录用户
-     * @var \app\api\service\ApiAuthService
-     */
-    protected $auth;
-    /**
-     * 无需登录的方法,同时也就不需要鉴权了
-     * @var array
-     */
-    protected $noNeedLogin = [];
-
-    protected function _initialize()
-    {
-        
-        $token=request()->header('token');
-        if(!$token){
-            $token=Cookie::get('token');
-        }
-        // if(!$token){
-        //     $token=request()->get('token');
-        // }
-        // if(!$token){
-        //     $token=request()->post('token');
-        // }
-        $actionname = $this->request->action();
-        $noNeedLoginSet=is_string($this->noNeedLogin)?[$this->noNeedLogin]:$this->noNeedLogin;
-        $noNeedLogin = in_array('*',$noNeedLoginSet) || in_array($actionname,$noNeedLoginSet);
-        //需要登陆
-        if(!$noNeedLogin && !ApiAuthService::getToken($token)){
-            $response = Response::create(__('请先登录!'), 'html', 401);
-            throw new HttpResponseException($response);
-        }
-    }
-}

+ 113 - 0
app/api/controller/Base.php

@@ -0,0 +1,113 @@
+<?php
+
+namespace app\api\controller;
+
+use think\exception\HttpResponseException;
+use think\Request;
+use think\Response;
+
+class Base
+{
+    /**
+     * @var Request Request 实例
+     */
+    protected $request;
+    /**
+     * 默认响应输出类型,支持json/xml
+     * @var string
+     */
+    protected string $responseType = 'json';
+
+    /**
+     * 构造方法
+     * @param Request|null $request
+     */
+    public function __construct(Request $request = null)
+    {
+        $this->request = is_null($request) ? request() : $request;
+
+        // 控制器初始化
+        $this->_initialize();
+    }
+
+    /**
+     * 初始化操作
+     * @access protected
+     */
+    protected function _initialize()
+    {
+//        //跨域请求检测
+//        check_cors_request();
+//
+//        // 检测IP是否允许
+//        check_ip_allowed();
+
+        //移除HTML标签
+        //$this->request->filter('trim,strip_tags,htmlspecialchars');
+    }
+
+    /**
+     * 操作成功返回的数据
+     * @param string $msg 提示信息
+     * @param mixed $data 要返回的数据
+     * @param int $code 错误码,默认为1
+     * @param string|null $type 输出类型
+     * @param array $header 发送的 Header 信息
+     */
+    protected function success(string $msg = '', $data = null, int $code = 200, string $type = null, array $header = [])
+    {
+        if (empty($msg)) {
+            $msg = "操作成功";
+        }
+        $this->result($msg, $data, $code, $type, $header);
+    }
+
+    /**
+     * 操作失败返回的数据
+     * @param string $msg 提示信息
+     * @param mixed $data 要返回的数据
+     * @param int $code 错误码,默认为0
+     * @param string|null $type 输出类型
+     * @param array $header 发送的 Header 信息
+     */
+    protected function error(string $msg = '', $data = null, int $code = 400, string $type = null, array $header = [])
+    {
+        if (empty($msg)) {
+            $msg = "操作失败";
+        }
+        $this->result($msg, $data, $code, $type, $header);
+    }
+
+    /**
+     * 返回封装后的 API 数据到客户端
+     * @access protected
+     * @param mixed $msg 提示信息
+     * @param mixed $data 要返回的数据
+     * @param int $code 错误码,默认为0
+     * @param string|null $type 输出类型,支持json/xml/jsonp
+     * @param array $header 发送的 Header 信息
+     * @return void
+     * @throws HttpResponseException
+     */
+    protected function result($msg, $data = null, int $code = 0, string $type = null, array $header = [])
+    {
+        $result = [
+            'code' => $code,
+            'msg'  => $msg,
+            'data' => $data,
+        ];
+        // 如果未设置类型则自动判断
+        $type = $type ? $type : ($this->request->param(config('var_jsonp_handler')) ? 'jsonp' : $this->responseType);
+
+        if (isset($header['statuscode'])) {
+            $code = $header['statuscode'];
+            unset($header['statuscode']);
+        } else {
+            //未设置状态码,根据code值判断
+            $code = $code < 200 ? 200 : $code;
+        }
+        $response = Response::create($result, $type, $code)->header($header);
+        throw new HttpResponseException($response);
+    }
+
+}

+ 0 - 47
app/api/controller/Common.php

@@ -1,47 +0,0 @@
-<?php
-declare(strict_types=1);
-
-namespace app\api\controller;
-
-use think\annotation\route\Post;
-use think\annotation\route\Get;
-use think\annotation\route\Group;
-use app\common\service\upload\PublicUploadService;
-
-
-class Common extends Api{
-
-    protected $noNeedLogin = ['*'];
-    /**
-     * 上传文件
-     * @param File $file 文件流
-     */
-    public function upload()
-    {
-        $file = $this->request->file('file');
-        try{
-            $savename=PublicUploadService::newInstance([
-                'config'=>config('site.upload'),
-                'user_id'=>$this->auth->id,
-                'file'=>$file
-            ])->save();
-        }catch (\Exception $e){
-            $this->error(__('上传文件出错'),[
-                'file'=>$e->getFile(),
-                'line'=>$e->getLine(),
-                'msg'=>$e->getMessage()
-            ]);
-        }
-        $this->success('',$savename);
-    }
-
-
-    public function area($pid)
-    {
-        if(!class_exists('\app\common\model\Area')){
-           $this->error('请先安装插件-省份城市地区数据');
-        }
-        $area=\app\common\model\Area::where('pid',$pid)->field('id,name')->select();
-        $this->success('',$area);
-    }
-}

+ 0 - 77
app/api/controller/Index.php

@@ -1,77 +0,0 @@
-<?php
-declare (strict_types = 1);
-
-namespace app\api\controller;
-
-use app\api\service\msg\WechatMsg;
-use think\annotation\route\Get;
-use think\annotation\route\Group;
-use think\annotation\route\Post;
-
-/**
- * 测试控制器,实际开发请删除全部方法
- */
-class Index extends Api
-{
-    protected $noNeedLogin = ['*'];
- 
-    public function testget()
-    {
-        sleep(1);
-        $data=$this->request->get();
-        $this->success('返回消息',$data);
-    }
-
-
-    public function testpost()
-    {
-        sleep(1);
-        $data=$this->request->post();
-        $this->success('返回消息',$data);
-    }
-
-   
-    public function list()
-    {
-        $page=$this->request->get('page/d');
-        //假装有29条数据
-        $limit=0;
-        if($page==1 || $page==2){
-            $limit=10;
-        }
-        if($page==3){
-            $limit=9;
-        }
-        if($page>3){
-            $limit=0;
-        }
-        $res=[];
-        for ($i=0;$i<$limit;$i++){
-            $id=($page-1)*10+1+$i;
-            $res[]=array(
-                'id'=>$id,
-                'title'=>'标题'.$id,
-                'content'=>'内容'.$id
-            );
-        }
-        $this->success('',$res);
-    }
-
-
-    public function mpconfig()
-    {
-        $result=[
-            'url'=>$this->request->domain().'/api/mpapp/connect',
-            'token'=>site_config("uniapp.mpapp_token"),
-            'encodingaeskey'=>site_config("uniapp.mpapp_aeskey"),
-        ];
-        $this->success('',$result);
-    }
-
- 
-    public function sendtempmsg()
-    {
-        WechatMsg::testMsg($this->auth->id);
-        $this->success('创建消息成功,等待消息推送');
-    }
-}

+ 0 - 62
app/api/controller/Miniapp.php

@@ -1,62 +0,0 @@
-<?php
-declare (strict_types = 1);
-
-namespace app\api\controller;
-
-use app\common\model\Third;
-use think\annotation\route\Group;
-use think\annotation\route\Post;
-
-#[Group("miniapp")]
-class Miniapp extends Api
-{
-    protected $noNeedLogin = ['login','getMobile','mockLogin'];
-
-    #[Post('login')]
-    public function login()
-    {
-        $code=$this->request->post('code');
-        $config=[
-            'appid'=>site_config("uniapp.miniapp_id"),
-            'appsecret'=>site_config("uniapp.miniapp_secret")
-        ];
-        $mini = new \WeMini\Crypt($config);
-        $data = $mini->session($code);
-        $openid=$data['openid'];
-        $unionid=isset($data['unionid'])?$data['unionid']:'';
-        $avatar=$this->request->post('avatar');
-        $nickname=$this->request->post('nickname');
-        $mobile=$this->request->post('mobile');
-        //判断是否启用账号绑定
-        $third=Third::connect(Third::PLATFORM('微信小程序'), compact('openid', 'unionid', 'avatar', 'nickname', 'mobile'));
-        $this->auth->loginByThirdPlatform(Third::PLATFORM('微信小程序'),$third);
-        $token=$this->auth->getToken();
-        $userinfo=$this->auth->userinfo();
-        $this->success('登录成功',compact('token','userinfo'));
-    }
-
-    #[Post('getMobile')]
-    public function getMobile()
-    {
-        $code=$this->request->post('code');
-        $config=[
-            'appid'=>site_config("uniapp.miniapp_id"),
-            'appsecret'=>site_config("uniapp.miniapp_secret")
-        ];
-        $mini = new \WeMini\Crypt($config);
-        $result=$mini->getPhoneNumber($code);
-        $this->success('',$result['phone_info']['phoneNumber']);
-    }
-
-    //模拟登陆
-    #[Post('mock-login')]
-    public function mockLogin()
-    {
-        $openid=$this->request->post('openid');
-        $third=Third::where(['openid'=>$openid,'platform'=>Third::PLATFORM('微信小程序')])->find();
-        $this->auth->loginByThirdPlatform(Third::PLATFORM('微信小程序'),$third);
-        $token=$this->auth->getToken();
-        $userinfo=$this->auth->userinfo();
-        $this->success('登录成功',compact('token','userinfo'));
-    }
-}

+ 0 - 246
app/api/controller/Mpapp.php

@@ -1,246 +0,0 @@
-<?php
-declare(strict_types=1);
-namespace app\api\controller;
-
-use app\common\model\Admin;
-use app\common\model\MpSubscribe;
-use app\common\model\Qrcode;
-use app\common\model\Third;
-use app\common\model\QrcodeScan;
-use think\annotation\route\Get;
-use think\annotation\route\Group;
-use think\annotation\route\Route;
-use app\common\model\User;
-
-#[Group("mpapp")]
-class Mpapp extends Api{
-    protected $noNeedLogin = ['*'];
-
-    protected $config=[];
-
-    const PAGE=[
-        //首页
-        'index'=>'/pages/index/index',
-        //绑定用户
-        'binduser'=>'/pages/index/index',
-        //NEXT页
-        'next'=>'/pages/index/next',
-    ];
-
-    protected function _initialize()
-    {
-        parent::_initialize();
-        $this->config=[
-            'appid'=>site_config("uniapp.mpapp_id"),
-            'appsecret'=>site_config("uniapp.mpapp_secret"),
-            'token'=>site_config("uniapp.mpapp_token"),
-            'encodingaeskey'=>site_config("uniapp.mpapp_aeskey")
-        ];
-    }
-    /**
-     * 发起授权
-     */
-    #[Get('connect')]
-    public function connect()
-    {
-        if($this->auth->id){
-            return $this->gourl();
-        }else{
-            $arr=$this->request->get();
-            if(count($arr)>0){
-                $str='';
-                foreach ($arr as $k=>$v){
-                    $str.=$k.'='.$v.'&';
-                }
-                $str=substr($str,0,strlen($str)-1);
-                $callback=$this->request->domain().'/api/mpapp/callback?'.$str;
-            }else{
-                $callback=$this->request->domain().'/api/mpapp/callback';
-            }
-            $wechat = new \WeChat\Oauth($this->config);
-            // 执行操作
-            $result = $wechat->getOauthRedirect($callback, '', 'snsapi_userinfo');
-            return redirect($result);
-        }
-    }
-
-    /**
-     * 授权回调
-     */
-    #[Get('callback')]
-    public function callback()
-    {
-        // 授权成功后的回调
-        $wechat = new \WeChat\Oauth($this->config);
-        $result = $wechat->getOauthAccessToken();
-        $userinfo = $wechat->getUserInfo($result['access_token'],$result['openid']);
-        $result['nickname']=$userinfo['nickname'];
-        $result['avatar']=$userinfo['headimgurl'];
-        //判断是否启用账号绑定
-        $third=Third::connect('mpapp', $result);
-        $this->auth->loginByThirdPlatform(Third::PLATFORM('微信公众号'),$third);
-        return $this->gourl();
-    }
-
-    private function gourl()
-    {
-        $arr=$this->request->get();
-        $action=$arr['action'];
-        unset($arr['action']);
-        unset($arr['code']);
-        unset($arr['state']);
-        $query='&'.http_build_query($arr);
-        $url=request()->domain().'/h5/#'.self::PAGE[$action].'?token='.$this->auth->getToken().$query;
-        return redirect($url);
-    }
-
-    /**
-     * 创建菜单
-     */
-    #[Get('menu')]
-    public function menu()
-    {
-        $this->error('请删除这行代码后重试');
-        $menu = new \WeChat\Menu($this->config);
-        $json=array('button'=>[
-            //跳转到公众号页面
-            [
-                "name"=>"首页",
-                "url"=>$this->request->domain()."/h5/#/pages/index/index",
-                "type"=>"view",
-            ],
-            //跳转到小程序页面
-            [
-                "name"=>"列表",
-                "type"=>"miniprogram",
-                "appid"=>site_config("uniapp.miniapp_id"),
-                "pagepath"=>"pages/index/list",
-            ],
-            //二级页面
-            [
-                "name"=>"我的",
-                "sub_button"=>[
-                    //先登陆,再跳转到指定页面
-                    [
-                        "name"=>"我的余额",
-                        "url"=>$this->request->domain()."api/mpapp/connect?action=101",
-                        "type"=>"view",
-                    ],
-                    [
-                        "name"=>"其他菜单",
-                        "type"=>"click",
-                        "key"=>"V1001_GOOD",
-                    ],
-                ]
-            ]
-        ]);
-        // 执行创建菜单
-        $menu->create($json);
-        $this->success('创建菜单成功');
-    }
-
-    /**
-     * 公众号事件接收方法
-     */
-    #[Route('POST,GET','event')]
-    public function event()
-    {
-        $api = new \WeChat\Receive($this->config);
-        $msgtype=$api->getMsgType();
-        if($msgtype=='text'){
-            $api->text('尊敬客户您好,感谢您使用【'.site_config("basic.sitename").'】公众号!')->reply();
-            return;
-        }
-        if($msgtype=='event'){
-            $message = $api->getReceive();
-            event('write_log','微信消息:'.json_encode($message));
-            $event = $message['Event'];
-            $eventkey = isset($message['EventKey'])? $message['EventKey'] : '';
-            $openid=$message['FromUserName'];
-            switch ($event) {
-                //添加关注
-                case 'subscribe':
-                    $user = new \WeChat\User($this->config);
-                    $userinfo=$user->getUserInfo($openid);
-                    $unionid=isset($userinfo['unionid'])?$userinfo['unionid'] : '';
-                    //记录关注
-                    MpSubscribe::create([
-                        'openid'=>$openid,
-                        'unionid'=>$unionid,
-                    ]);
-                    //普通关注
-                    if(is_array($eventkey)){
-                        $api->text('尊敬客户您好,感谢您使用【'.site_config("basic.sitename").'】公众号!')->reply();
-                        return;
-                    }
-                    //扫码关注
-                    if(strpos($eventkey,'qrscene_')===0){
-                        $eventkey=substr($eventkey,8);
-                        $resp=$this->scanQrcode($openid,$unionid,$eventkey);
-                        $api->text($resp)->reply();
-                        return;
-                    }
-                //取消关注
-                case 'unsubscribe':
-                    MpSubscribe::where(['openid'=>$openid])->delete();
-                    return;
-                //扫二维码
-                case 'SCAN':
-                    $user = new \WeChat\User($this->config);
-                    $userinfo=$user->getUserInfo($openid);
-                    $unionid=isset($userinfo['unionid'])?$userinfo['unionid'] : '';
-                    $resp=$this->scanQrcode($openid,$unionid,$eventkey);
-                    $api->text($resp)->reply();
-                    return;
-                //跳转链接
-                case 'VIEW':
-            }
-        }
-    }
-
-    /**
-     * 扫码回调事件
-     */
-    private function scanQrcode($openid,$unionid,$qrcode_id)
-    {
-        $qrcode=Qrcode::find($qrcode_id);
-        if(!$qrcode){
-            return '尊敬客户您好,感谢您使用【'.site_config("basic.sitename").'】公众号!';
-        }
-        //记录扫码
-        $scan=QrcodeScan::where(['openid'=>$openid,'qrcode_id'=>$qrcode->id])->find();
-        if(!$scan){
-            //生成的扫码记录表,可以在用户注册时,查询该表从而绑定推荐人
-            QrcodeScan::create([
-                'openid'=>$openid,
-                'unionid'=>$unionid,
-                'qrcode_id'=>$qrcode->id,
-                'foreign_key'=>$qrcode->foreign_key,
-                'type'=>$qrcode->type,
-            ]);
-        }
-        //根据业务场景返回不同的消息
-        switch ($qrcode->type){
-            case 'backend-login':
-                $third=Third::where(['platform'=>Third::PLATFORM('微信公众号'),'openid'=>$openid])->find();
-                if(!$third){
-                    return '您的微信没有绑定管理员,登陆失败!';
-                }
-                $admin=Admin::where(['third_id'=>$third->id])->find();
-                if(!$admin){
-                    return '您的微信没有绑定管理员,登陆失败!';
-                }
-                if($admin->status=='hidden'){
-                    return '管理员已经被禁止,登陆失败!';
-                }
-                return '登陆成功!';
-            case 'bind-third-user':
-                $path=$this->request->domain()."/api/mpapp/connect?action=binduser";
-                $end="<a href=\"{$path}\">👉👉点击这里授权👈️👈️</a>";
-                return "您正在使用微信扫码授权获取您的微信头像、昵称\n\n{$end}";
-            case 'toker':
-                $user=User::find($qrcode->foreign_key);
-                return '尊敬客户您好,您的好友'.$user->nickname.'推荐您使用【'.site_config("basic.sitename").'】公众号!';
-        }
-    }
-}

+ 17 - 0
app/api/controller/Test.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\model\Orders;
+use app\common\service\OrderService;
+
+class Test extends Base
+{
+
+    public function index(){
+      
+        
+        return  $this->error('apiId有误');
+
+    }
+}

+ 171 - 0
app/api/controller/Transaction.php

@@ -0,0 +1,171 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\model\ApiUser;
+use app\common\model\Orders;
+use app\common\model\OrdersRequestLog;
+use think\facade\Db;
+use think\Exception;
+use think\facade\Request;
+use think\Log;
+
+class Transaction extends Base
+{
+    protected $contract_address = '0x55d398326f99059ff775485246999027b3197955';//交易币种的合约地址,默认为usdt的:0x55d398326f99059ff775485246999027b3197955,测试合约:0xcf3271b1be72f834e4dd35b9d558d583894473f1
+
+    /**
+     *
+     *
+     *
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function withdraw(){
+//        $data = [
+//            'apiId'             => '$api_key',
+//            'toAddress'         => '$address',
+//            'coinName'          => 'usdt',
+//            'coinType'          => 'bsc',
+//            'amount'            => '$mum',//提币数量
+//            'orderNo'           => '$order_sn',//本平台的唯一订单号
+//            'timeStamp'         => '$order_sn',//本平台的唯一订单号
+//            'sign'              => '$order_sn'//本平台的唯一订单号
+//        ];
+
+        //获取post参数
+        $params = Request::post();
+
+        $api_user = (new ApiUser())
+            ->where('api_id', $params['apiId'])
+            ->find();
+        if(empty($api_user)){
+            $this->error('apiId有误');
+        }
+
+        $sign = $params['sign'];
+
+        // "param" => "amount=2&apiId=1001&coinName=usdt&coinType=BEP20&orderNo=T2023&timeStamp=1700584041&toAddress=ox4545454545-&apiKey=123456"
+        if($sign != md5(getSignKey($params, $api_user['api_key']))){
+            dump($sign);
+            dump(md5(getSignKey($params, $api_user['api_key'])));
+            $this->error('签名错误');
+        }
+
+        $check_order = (new Orders())
+            ->where('api_id', $params['apiId'])
+            ->where('user_order_no', $params['orderNo'])
+            ->count();
+        if($check_order){
+            $this->error('该订单号已存在,请勿重复提交');
+        }
+
+        // 启动事务
+        Db::startTrans();
+        try {
+            // 生成订单
+            $order_id = (new Orders())
+                ->insertGetId([
+                    'api_id'        => $params['apiId'],
+                    'order_no'      => $params['apiId'] . '-' . $params['orderNo'],
+                    'user_order_no' => $params['orderNo'],
+                    'to_address'    => $params['toAddress'],
+                    'amount'        => $params['amount'],
+                    'coin_type'     => 'BEP20',
+                    'coin_name'     => 'usdt',
+                    'create_time'   => date('Y-m-d H:i:s')
+                ]);
+
+            $rs_id = (new OrdersRequestLog())
+                ->save([
+                    'order_id'        => $order_id,
+                    'ip'              => $_SERVER['REMOTE_ADDR'],
+                    'url'             => $this->request->host(),
+                    'params'          => json_encode($params),
+                ]);
+
+            // 提交事务
+            Db::commit();
+        } catch (Exception $e) {
+            // 回滚事务
+            Db::rollback();
+            $this->error('提交失败:' . $e->getMessage());
+        }
+        $this->success('提交成功');
+    }
+
+    public function getTxhashDetail(){
+        $tx_hash = Request::post('tx_hash');
+        $api_url = 'http://127.0.0.1:3389/api/txDetail';
+        if(empty($tx_hash)){
+            $this->error('参数有误');
+        }
+        $data = [
+            'tx_hash' => $tx_hash,
+        ];
+        $body = $this->doCurlPostRequest($api_url, $data);
+        //dump($body);
+        $info = json_decode($body, true);
+        //dump($body);
+
+        //$body = $this->getInfoByTransactionHash($txhash);
+        if($info['code'] == 200){
+            $this->success('', $info['data']);
+        }
+        $this->error($info['message']);
+    }
+
+    public function createAddress(){
+        $tx_hash = Request::post('tx_hash');
+        $api_url = 'http://127.0.0.1:3389/api/txDetail';
+        if(empty($tx_hash)){
+            $this->error('参数有误');
+        }
+        $data = [
+            'api_id'  => 1,
+            'coin_type' => 'BEP20',
+            'user_no' => 1,
+            'time_stamp' => 1122,
+            'reset' => true
+        ];
+        $body = $this->doCurlPostRequest($api_url, $data);
+        //dump($body);
+        $info = json_decode($body, true);
+        //dump($body);
+
+        //$body = $this->getInfoByTransactionHash($txhash);
+        if($info['code'] == 200){
+            $this->success('', $info['data']);
+        }
+        $this->error($info['message']);
+    }
+
+
+    function doCurlPostRequest($url = '',Array $data = array())
+    {
+        $data_string = json_encode($data,JSON_UNESCAPED_UNICODE);
+        // $data_string = $data;
+        $curl_con = curl_init();
+        curl_setopt($curl_con, CURLOPT_URL,$url);
+        curl_setopt($curl_con, CURLOPT_HEADER, false);
+        curl_setopt($curl_con, CURLOPT_POST, true);
+        curl_setopt($curl_con, CURLOPT_RETURNTRANSFER, TRUE);
+        curl_setopt($curl_con, CURLOPT_CONNECTTIMEOUT, 5);
+        curl_setopt($curl_con, CURLOPT_HTTPHEADER, array(
+                'Content-Type: application/json',
+                'Content-Length: ' . strlen($data_string))
+        );
+        curl_setopt($curl_con, CURLOPT_POSTFIELDS, $data_string);
+        $res = curl_exec($curl_con);
+        $status = curl_getinfo($curl_con);
+        curl_close($curl_con);
+
+        if (isset($status['http_code']) && $status['http_code'] == 200) {
+            return $res;
+        } else {
+            return FALSE;
+        }
+    }
+}

+ 0 - 47
app/api/controller/User.php

@@ -1,47 +0,0 @@
-<?php
-declare (strict_types = 1);
-
-namespace app\api\controller;
-
-use app\api\validate\User as UserValidate;
-use app\api\service\ApiAuthService;
-use think\annotation\route\Post;
-use think\exception\ValidateException;
-
-
-class User extends Api
-{
-    
-    protected $noNeedLogin = ['login'];
-
-
-    public function userinfo(ApiAuthService $apiAuth)
-    {
-        $user= $apiAuth->userinfo();
-        return $this->jsonSuccess('登录成功', $user); 
-    }
-
-  
-
-
-    //登录
-    public function login(ApiAuthService $apiAuth)
-    {
-        $data=$this->request->post();
-        try {
-
-            validate(UserValidate::class)->scene('edit')->check($data);
-            $ret = $apiAuth->login($data['username'], $data['password']);
-            return $this->jsonSuccess('登录成功', $ret);    
-            
-        } catch (ValidateException $e) {
-            return $this->jsonError($e->getError());
-        }catch (\Exception $e) {
-        
-            return $this->jsonError($e->getMessage());
-        }
-    }
-
-
-    
-}

+ 0 - 6
app/api/middleware.php

@@ -1,6 +0,0 @@
-<?php
-// 这是系统自动生成的middleware定义文件
-return [
-    //跨域请求
-    app\api\middleware\AllowCrossDomain::class,
-];

+ 1 - 0
app/api/middleware/AllowCrossDomain.php

@@ -3,6 +3,7 @@ declare(strict_types=1);
 namespace app\api\middleware;
 
 class AllowCrossDomain{
+    
     public function handle($request, \Closure $next)
     {
         header('Access-Control-Allow-Credentials: true');

+ 9 - 0
app/api/route/route.php

@@ -0,0 +1,9 @@
+<?php
+declare(strict_types=1);
+
+use think\facade\Route;
+
+Route::rule('test','test/index','GET|POST');
+Route::rule('withdraw','transaction/withdraw','GET|POST');
+Route::rule('getTxhashDetail','transaction/getTxhashDetail','GET|POST');
+Route::rule('createAddress','transaction/createAddress','GET|POST');

+ 0 - 74
app/api/service/ApiAuthService.php

@@ -1,74 +0,0 @@
-<?php
-declare(strict_types=1);
-namespace app\api\service;
-
-use think\facade\Cookie;
-use app\api\service\auth\MysqlAdapter;
-use app\common\model\User;
-use app\common\model\UserToken;
-use app\common\service\AuthService;
-
-
-class ApiAuthService extends AuthService
-{
-    protected $allowFields = ['id', 'nickname', 'mobile', 'avatar', 'balance', 'score'];
-   
-
-    public function userinfo(bool $allinfo = false)
-    {   
-        $time=time();
-        $token =  Cookie::get('token');
-        if(!$token){
-            return false;
-        }
-        $user = UserToken::where('token',$token)->where('expire','>',$time)->field('mobile')->value('user_id');
-        return $user?User::where('id',$user)->field($this->allowFields)->find()->toArray():false;
-    }
-
-    public function logout()
-    {   
-        $adapter = new MysqlAdapter();
-        $adapter->logout();
-    }
-
-    public static function getToken($token):int
-    {   
-        $time=time();
-        return UserToken::where('token',$token)->where('expire','>',$time)->count();
-    }
-
-    //登录
-    public function login(string $username, string $password)
-    {
-        $token= uuid();
-        $user=User::where('username',$username)->find();
-        if(!$user){
-            throw new \Exception('账号或密码错误');
-        }
-        if($user->password!=md5(md5($password.$user->salt))){
-            throw new \Exception('账号或密码错误');
-        }
-        if($user->status!='normal'){
-            throw new \Exception('账号已经被禁用');
-        }
-
-        $adapter = new MysqlAdapter();
-        $token = $adapter->login($token,$user);
-        $this->login_user=$adapter->userinfo();
-        return ['userinfo' => $this->login_user, 'token' => $token];
-    }
-
-
-    public function loginByMobile(string $mobile, string $code)
-    {
-        // TODO: Implement loginByMobile() method.
-    }
-
- 
-    public function updateToken(array $arr)
-    {
-        $usertoken=$this->adapter->getUserToken();
-        UserToken::where('id',$usertoken->id)->update($arr);
-    }
-
-}

+ 0 - 59
app/api/service/auth/MysqlAdapter.php

@@ -1,59 +0,0 @@
-<?php
-declare(strict_types=1);
-namespace app\api\service\auth;
-
-use think\facade\Cookie;
-use app\common\model\UserToken;
-use app\common\model\User;
-use think\facade\Config;
-
-class MysqlAdapter 
-{
-    private UserToken $usertoken;
-
- 
-    public function userinfo():array|false
-    {
-        if(isset($this->usertoken)){
-            return $this->usertoken->user->toArray();
-        }
-        return false;
-    }
-
-    public function getUserToken():UserToken|false
-    {
-        if(isset($this->usertoken)){
-            return $this->usertoken;
-        }
-        return false;
-    }
-
-    public function login(string $token,User $user)
-    {
-        $keepalive_time=Config::get('app.auth.keepalive_time');
-        $token = md5($token);
-        $this->usertoken=UserToken::create([
-            'token'  => $token,
-            'user_id'=> $user->id,
-            'expire' => time()+$keepalive_time
-        ]);
-        $this->usertoken->token=$token;
-        $this->usertoken->user=$user;
-        $allow_device_num=Config::get('app.auth.allow_device_num');
-        //如果数据库中保存的设备数大于允许的设备数,如果超出则挤出去最早登陆的设备
-        $time=time();
-        $count=UserToken::where('user_id',$user->id)->where('expire','>',$time)->count();
-        if($count>$allow_device_num){
-            $usertoken=UserToken::where('user_id',$user->id)->where('expire','>',$time)->order('id','asc')->find();
-            $usertoken->delete();
-        }
-        Cookie::set('token', $token ,$keepalive_time);
-        return $token;
-    }
-
-    public function logout()
-    {
-        UserToken::where('token',$this->usertoken->token)->delete();
-        Cookie::delete('token');
-    }
-}

+ 0 - 10
route/route.php

@@ -2,13 +2,3 @@
 use think\facade\Route;
 
 
-
-//员工端
-Route::group('/user/api', function () {
-
-      //登录
-      Route::post('login', 'User@login');
-      Route::post('userinfo', 'User@userinfo');
-      
-      //->controller('api/Index','hello');
-})->namespace('app\api\controller')->middleware('app\api\middleware');