Browse Source

标记茶宝资产转账

afa 4 months ago
parent
commit
5066e8274d
1 changed files with 12 additions and 4 deletions
  1. 12 4
      application/api/controller/Ledger.php

+ 12 - 4
application/api/controller/Ledger.php

@@ -120,10 +120,14 @@ class Ledger extends Api
     {
         $amount = $this->request->post('amount'); // 茶宝
         $account= $this->request->post('account', ''); // 账号
-        $type    = (strlen($account) > 11)? 0: 1;    // type: 0地址 1uid
+        $type    = (substr($account, 0, 2) == '0x')? 0: 1;    // type: 0地址 1uid
         if(empty($amount) || empty($account)){
             $this->error(__('Parameter error'));
         }
+        // 验证地址是否以0x开头
+        if($type == 0 && substr($account, 0, 2) !== '0x'){
+            $this->error(__('Invalid address format, must start with 0x'));
+        }
         $real   = bcsub($amount, bcmul(getConfig('frozen_transfer'), $amount, 2), 2) ; // 手续费
         // 启动事务
         Db::startTrans();
@@ -164,17 +168,21 @@ class Ledger extends Api
     }
     
     /**
-     * 茶宝赠送
+     * 茶宝赠送 0x
      * @return void
      */
     public function chabaoGift(UserModel $userModel,  LedgerWalletModel $ledgerWalletModel)
     {
         $amount = $this->request->post('amount'); // 茶宝
         $account= $this->request->post('account', ''); // 账号
-        $type    = (strlen($account) > 11)? 0: 1;    // type: 0地址 1uid
+        $type    = (substr($account, 0, 2) == '0x')? 0: 1;    // type: 0地址 1uid
         if(empty($amount) || empty($account)){
             $this->error(__('Parameter error'));
         }
+        // 验证地址是否以0x开头
+        if($type == 0 && substr($account, 0, 2) !== '0x'){
+            $this->error(__('Invalid address format, must start with 0x'));
+        }
         $real   = bcsub($amount, bcmul(getConfig('chabao_giveaway'), $amount, 2), 2) ; // 手续费
 
         // 启动事务
@@ -253,4 +261,4 @@ class Ledger extends Api
     {   
         return $this->success('', ['value'=> Env::get('rental.pay_address'), 'name'=>getConfig('recharge_txt')]);
     }
-}
+}