'0', // 系统余额(U) 'withdraw_min_amount' => getConfig('withdraw_min_amount'), // 最低提现U数量 'withdraw_fee_rate' => getConfig('withdrawal_fee') // 手续费比例 ]; $this->success('', $resp); } /** * 提现 * @return void */ public function withdrawCash() { $amount = $this->request->post('amount'); // 金额 $sign = $this->request->post('sign'); // 签名信 $address = $this->request->post('to_address'); // 地址 if(empty($sign) || empty($address)){ $this->error(__('Invalid parameters')); } $real = bcdiv($amount, getConfig('convert_rate'), 6); // 折合转换 U = 1 $min = getConfig('withdraw_min_amount'); $rate = getConfig('withdrawal_fee'); if ($amount <= 0) { $this->error(__('The withdrawal amount must be greater than 0')); } else if ($amount < $min) { $this->error(__('The withdrawal amount cannot be less than') . $min); } // 扣除手续费后 if ($rate > 0 && $rate < 1) { // 比例范围只在0-1之间 $real = bcmul($real, bcsub(1, $rate, 6), 6); } $uid = $this->auth->getTokenUserID(); // 用户信息 $user = (new UserModel())->getById($uid); if($user['is_withdraw']){ $this->error(__('Withdrawal failed, please contact customer service.')); } // 验签 $signMsg = "withdraw"; // 与前端约定的固定值 if (!checkSign($signMsg, $sign, $address)) { $this->error(__('Signature verification failed')); } // 启动事务 Db::startTrans(); try { // 更新USDT和账变 (new LedgerWalletModel())->changeWalletAccount($uid, Asset::TOKEN, -$amount, LedgerWalletModel::Withdraw); // 创建提现记录 $txHash = Random::uuid(); (new OfflineWithdrawRecordModel())->createWithdraw($txHash, $uid, $amount, $real, $address, 'usdt'); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error( $e->getMessage()); } $this->success('ok'); } /** * 提现地址 * @return void */ public function withdrawList() { $where = ['user_id' => $this->auth->getTokenUserID()]; $paginator = (new OfflineWithdrawRecordModel)->where($where)->order('id DESC')->paginate($this->pageSize); $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items())); } /** * 充值记录 * @return void */ public function rechargeList() { $where = ['user_id' => $this->auth->getTokenUserID()]; $paginator = (new OfflineRechargeRecordModel)->where($where)->order('id DESC')->paginate($this->pageSize); $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items())); } /** * 获取签名-带连接符号 * @return string */ protected static function getSignKey(array $arr, string $secretKey)//: string { ksort($arr); $arr['apiSecret'] = $secretKey; $string = ''; foreach ($arr as $key => $value) $string .= '&'.$key .'='.$value; return ltrim($string, '&'); } //post private static function curlPostData($url , $data=array()) { $headers = array("Content-type:application/x-www-form-urlencoded;charset=UTF-8"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER,$headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // POST数据 curl_setopt($ch, CURLOPT_POST, 1); // 把post的变量加上 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); $output = curl_exec($ch); curl_close($ch); return $output; } //get private static function curlGetData($url){ Log::info('查询余额'); Log::info($url); # 初始化一个curl会话 $ch = curl_init(); # 判断是否是https if (stripos($url, "https://") !== false) { # 禁用后cURL将终止从服务端进行验证 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); # 使用的SSL版本(2 或 3) curl_setopt($ch, CURLOPT_SSLVERSION, 1); } # 设置请求地址 curl_setopt($ch, CURLOPT_URL, $url); # 在启用CURLOPT_RETURNTRANSFER的时候,返回原生的(Raw)输出 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); # 执行这个请求 $output = curl_exec($ch); # 关闭这个请求 curl_close($ch); return $output; } }