| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services;
- use App\Models\MemberModel;
- use BitWasp\Bitcoin\Address\AddressCreator;
- use BitWasp\Bitcoin\Address\PayToPubKeyHashAddress;
- use BitWasp\Bitcoin\Crypto\Random\Random;
- use BitWasp\Bitcoin\Key\Factory\PrivateKeyFactory;
- use BitWasp\Bitcoin\Network\NetworkInterface;
- /**
- * USDT链管理-服务类
- * Class UsdtWalletService
- * @package App\Services
- */
- class UsdtWalletService extends BaseService
- {
- protected $config = [];
- /**
- * 构造函数
- * UsdtWalletService constructor.
- */
- public function __construct()
- {
- $this->config = ConfigService::make()->getConfigByGroup(2);
- if (empty($this->config)) {
- return false;
- }
- }
- /**
- * 静态入口
- * @return UsdtWalletService|null
- */
- public static function make()
- {
- return parent::make(); // TODO: Change the autogenerated stub
- }
- /**
- * 获取
- */
- public function getLink()
- {
- }
- /**
- * 创建转入TRC2.0转账交易
- * api: https://services.tokenview.com/vipapi/onchainwallet/{币种简称小写}?apikey={apikey}
- */
- public function transferTrc20()
- {
- //
- }
- /**
- * 获取钱包地址
- * @param string $type
- * @throws \BitWasp\Bitcoin\Exceptions\RandomBytesFailure
- */
- public function getWalletAddress()
- {
- $random = new Random();
- $privateKeyFactory = new PrivateKeyFactory();
- $privateKey = $privateKeyFactory->generateCompressed($random);
- $publicKey = $privateKey->getPublicKey();
- // p2pkh 格式的地址
- $addressService = new PayToPubKeyHashAddress($publicKey->getPubKeyHash());
- // 将生成的钱包保存到数据库中
- $network = null;
- $wif = $privateKey->toWif($network);
- $address = $addressService->getAddress();
- return ['wif'=> $wif, 'address'=> $address];
- }
- /**
- * 获取HASH钱包地址
- * @param $address 钱包地址
- * @return \BitWasp\Buffertools\BufferInterface
- * @throws \BitWasp\Bitcoin\Exceptions\UnrecognizedAddressException
- */
- public function getHashAddress($address)
- {
- $data = (new AddressCreator())->fromString($address)->getHash();
- return isset($data['buffer'])? $data['buffer'] : '';
- }
- }
|