Pro/extend/pay/Usdt.php
2026-02-25 01:50:31 +08:00

100 lines
2.4 KiB
PHP

<?php
namespace pay;
use think\Cache;
use \think\Controller;
use think\Db;
class Usdt{
public function __construct()
{
$this->getConfig();
}
/**
* 获取配置信息
*/
private function getConfig()
{
// 域名
$this->domain = "https://ubcagent.rosettawe.com";
// 参数配置
$config = Db::name('pay_channel')->where('key','USDT')->value('value');
$config = json_decode($config,true);
$this->merchAddr = $config['merch_addr'];
$this->merchType = $config['merch_type'];
$this->accessToken = $config['access_token'];
}
/**
* 新用户生成钱包
*/
public function newUserWallet()
{
$key = '/usr/newUserWallet';
$requestUrl = $this->domain . $key;
$requestUrl .= '?'. $this->dataGet($key);
$result = null;//httpGet($requestUrl); // 临时屏蔽 2023-09-16
return $result;
}
/**
* 用户提现
*/
public function applyUserWithdraw($orderNo,$toAddress,$amount)
{
$key = '/usr/applyUserWithdraw';
$requestUrl = $this->domain . $key;
$data = [
'uuid' => $orderNo,
'user_addr' => $this->merchAddr,
'to_addr' => $toAddress,
'asset' => 'USDT',
'amount' => $amount,
'try_count' => '5',
];
$requestUrl .= '?'. $this->dataGet($key,$data);
$result = httpGet($requestUrl);
return $result;
}
/**
* get请求参数设置
* @param $key
* @param array $data
* @return string
*/
private function dataGet($key,$data=[])
{
$time = time();
$str = "key=".$key;
$str .= "&merch_addr=".$this->merchAddr;
$str .= "&merch_type=".$this->merchType;
$str .= '&timestamp='.$time."&";
foreach($data as $k => $v){
$str .= $k ."=" . $v . "&";
}
$str .= "sign=".$this->getSign($key,$time);
return $str;
}
/**
* 签名
* @param $data
* @return string
*/
private function getSign($key,$timestamp)
{
$signData = "key=".urlencode($key);
$signData .= "&merch_addr=".$this->merchAddr;
$signData .= "&merch_type=".$this->merchType;
$signData .= "&timestamp=".$timestamp;
$signData .= "&access_token=".$this->accessToken;
$sign = sha1($signData);
return $sign;
}
}