123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\FrontController;
- use App\Jobs\BarrageJob;
- use App\Models\AgencySet;
- use App\Models\Config;
- use App\Models\Contract;
- use App\Models\MemberClan;
- use App\Models\Region;
- use App\Servers\BroadcastServer;
- use App\Servers\CommonServer;
- use App\Servers\ContractServer;
- use App\Servers\Icon\Address;
- use App\Servers\Icon\BanRPC;
- use App\Servers\Icon\Utils;
- use App\Servers\PassServer;
- use App\Servers\ShopServer;
- use App\Servers\SmsServer;
- use App\Servers\TronAnalyzeServer;
- use App\Servers\TxMapServer;
- use App\Servers\WeixinServer;
- use BitWasp\Bitcoin\Address\PayToPubKeyHashAddress;
- use BitWasp\Bitcoin\Crypto\Random\Random;
- use BitWasp\Bitcoin\Key\Factory\HierarchicalKeyFactory;
- use BitWasp\Bitcoin\Mnemonic\Bip39\Bip39Mnemonic;
- use BitWasp\Bitcoin\Mnemonic\Bip39\Bip39SeedGenerator;
- use BitWasp\Bitcoin\Mnemonic\MnemonicFactory;
- use Illuminate\Contracts\Routing\ResponseFactory;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Storage;
- use Web3p\EthereumUtil\Util;
- class CommonController extends FrontController
- {
- public function __construct()
- {
- parent::__construct();
- }
- function index()
- {
- $bnbServer=BanRPC::creatServer();
- $from='0x6652548D0783b45FC6D7a92E70B15Cf933A3D775';
- $data=[
- 'from'=>$from,
- 'to'=>'0xB2568EFafA4895236bCf3e34B03856BC48B4E9Ec',
- //交易描述,合约为调用函数的方法与参数进行哈希
- 'data'=>'0x0',
- //转账金额
- 'value'=> Utils::dec2hex(Utils::fund2int(0.0001 )),
- 'chain_id'=>$bnbServer->chainId,
- ];
- //交易序列号
- $nonce = $bnbServer->getTransactionCount($from);
- $data['nonce'] = $nonce;
- dd($nonce);
- // $gas_price = $bnbServer->getGasPrice();
- // $data['gas_price'] =$gas_price;
- // $gas_limit =BroadcastServer::creatServer()->getEthGasLimit($data);
- // $data['gas_limit'] = $gas_limit;
- // $sign =BroadcastServer::creatServer()->ethSign($data,"c1c2169a2cd2b82a6ca4e3ab93d04fb02be23f57ee0ee12c3a4875eec1521276");
- // $hash = $bnbServer->sendRawTransaction($sign, $error);//广播交易
- // $receipt = $bnbServer->getTransactionReceipt("0xcd1b28551be1a770908dc0c2bacea12ac9fc3b5fb6ae25cf1d23329bba8fd799");
- $receipt = $bnbServer->sendBlockByNumber(43679869);
- dd($receipt);
- //0x6652548D0783b45FC6D7a92E70B15Cf933A3D775
- //0xb2568efafa4895236bcf3e34b03856bc48b4e9ec
- // $bnb_block = BanRPC::creatServer()->sendBlockNumber();
- // dd($bnb_block);
- // $block_deal = BanRPC::creatServer()->sendBlockByNumber(43679463);
- // dd($block_deal);
- // $deal = BanRPC::creatServer()->getTransactionReceipt("0xd520c1b14e4d49064612c92647e2338547e5864fe1401972e356a658d4aa0972");//交易查询
- // $deal = BanRPC::creatServer()->getGasPrice();//交易查询
- // dd($deal);
- // $data=Address::generate();
- // dd($data);
- // $random = new Random();
- // // 生成随机数(initial entropy)
- // $entropy = $random->bytes(Bip39Mnemonic::MIN_ENTROPY_BYTE_LEN);
- // $bip39 = MnemonicFactory::bip39();
- // // 通过随机数生成助记词
- // $mnemonic = $bip39->entropyToMnemonic($entropy);
- $mnemonic = "poem decide already flush ramp unhappy deputy fiscal refuse history step grape";
- // dump($mnemonic);
- //
- $seedGenerator = new Bip39SeedGenerator();
- // // 通过助记词生成种子,传入可选加密串'hello'
- $seed = $seedGenerator->getSeed($mnemonic);
- dump( "seed: " .$seed->getHex());
- $hdFactory = new HierarchicalKeyFactory();
- $master = $hdFactory->fromEntropy($seed);
- //
- $hardened = $master->derivePath("44'/60'/0'/0/0");
- dump( 'WIF: ' . $hardened->getPrivateKey()->toWif());
- $address = new PayToPubKeyHashAddress($hardened->getPublicKey()->getPubKeyHash());
- dump( 'address: ' . $address->getAddress());
- dump( " public key: " . $hardened->getPublicKey()->getHex());
- dump( " private key: " . $hardened->getPrivateKey()->getHex());
- $util = new Util();
- dump( " address: " . $util->publicKeyToAddress($util->privateKeyToPublicKey($hardened->getPrivateKey()->getHex())));
- // $contract=Contract::where('id',1)->first();
- // $memberTeam=MemberClan::where('m_id',$contract->{'m_id'})->select(['id','m_id','p_ids','one_m_id','two_m_id'])->first();
- // $pIds=array_reverse(array_filter(explode(',',$memberTeam->{'p_ids'})));
- // ContractServer::creatServer()->teamProportion($contract,$pIds);
- dd(1221);
- // $data=Address::generate();
- // $key='1212';
- // $key=$data['key'];
- // dump($key);
- // $key=PassServer::creatServer()->setSecretKey($key);
- // dump($key);
- // dump($data['key']);
- // dump(PassServer::creatServer()->getSecretKey($key));
- // dd($data);
- }
- /**
- * 获取城市列表
- * @return \Illuminate\Http\JsonResponse
- */
- function city()
- {
- $p_id = request()->input('p_id', 0);
- $list = Region::where('p_id', $p_id)->select(['id', 'name'])->get();
- return $this->apiResponseSuccess('获取数据成功', $list);
- }
- /**
- * 发送短信
- * @return \Illuminate\Http\JsonResponse
- * @throws \End01here\EasySms\Exceptions\CodeErrorException
- * @throws \End01here\EasySms\Exceptions\GatewayErrorException
- * @throws \End01here\EasySms\Exceptions\MessageException
- */
- function sendSms()
- {
- $phone = request()->input('phone', '');
- $send_type = request()->input('send_type', 'default');
- if (empty($phone)) {
- return $this->apiResponseError('请输入手机号码');
- }
- $send_server = SmsServer::creatServer();
- $ret = $send_server->sendCode($phone, $send_type);
- if (!$ret) {
- return $this->apiResponseError($send_server->getErrorMsg() ?: '短信发送失败');
- } else {
- return $this->apiResponseSuccess('短信发送成功');
- }
- }
- /**
- * base64 图片上传
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function base64Image(Request $request)
- {
- $result = $this->base64ToImage($request->input('image', ""), 'attest');
- if ($result['code'] === false) {
- return $this->apiResponseError('图片上传失败');
- } else {
- if ($result) {
- return $this->apiResponseSuccess('图片上传成功', ['url' => $result['url']]);
- } else {
- return $this->apiResponseError('图片上传失败');
- }
- }
- }
- // base64图片保存
- protected function base64ToImage($base64ImageContent, $path)
- {
- $base64_image_content = $base64ImageContent;
- if (!empty($base64_image_content)) {
- $upload_path = "storage" . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . date('Ymd', time()) . DIRECTORY_SEPARATOR;
- $img_url = md5(uniqid() . time()) . '.jpg';
- $upload_path1 = public_path($upload_path);
- if (!is_dir($upload_path1)) {
- mkdir($upload_path1, 0777, true);
- }
- try {
- $base64_image_content = str_replace('[removed]', '', $base64_image_content);
- preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result);
- // oss 上传
- $oss = Storage::disk('oss');
- $pathA = "{$upload_path}{$img_url}";
- if (empty($result[1])) {
- $update = $oss->put($pathA, base64_decode($base64_image_content));
- if (!$update) { // 如果失败上传本地
- file_put_contents($upload_path1 . $img_url, base64_decode($base64_image_content));
- }
- } else {
- $update = $oss->put($pathA, base64_decode(str_replace($result[1], '', $base64_image_content)));
- if (!$update) { // 如果失败上传本地
- file_put_contents($upload_path1 . $img_url, base64_decode(str_replace($result[1], '', $base64_image_content)));
- }
- }
- return [
- 'code' => true,
- 'url' => $update ? ($oss->url($pathA) . '?x-oss-process=image/auto-orient,1/quality,q_90') : asset($pathA),
- ];
- } catch (\Exception $e) {
- return [
- 'code' => false,
- 'msg' => "图片错误" . $e->getMessage() . " " . $e->getLine(),
- ];
- }
- } else {
- return [
- 'code' => false,
- 'msg' => "请上传图片",
- ];
- }
- }
- /**
- * @param Request $request
- * @param ResponseFactory $response
- * @return mixed
- * 单图上传
- */
- public function fileImage()
- {
- if (request()->isMethod('post')) {
- if (request()->hasFile('file_image')) {
- // 文件后缀判断
- $ext = request()->file("file_image")->extension();
- if (!in_array($ext, ["jpg", "jpeg", "gif", "png", "bmp", "webp"])) {
- return $this->apiResponseError('上传图片仅支持png、jpg、jpeg、gif、bmp、webp后缀');
- }
- // 文件大小是否满足 2M = 2*1024*1024 B
- if (request()->file("file_image")->getClientSize() > 20971552) {
- return $this->apiResponseError('上传图片大小超过5M');
- }
- // 上传过程是否出错
- if (!request()->file("file_image")->isValid()) {
- return $this->apiResponseError('上传文件出错,请重试');
- }
- // 文件保存 生成一个唯一的文件名称
- $fileName = time() . str_random(4) . mt_rand(1000, 9999) . ".{$ext}";
- $pathA = 'image/' . date('y-m', time()) . '/' . $fileName;
- // oss 上传图片
- $oss = Storage::disk('oss');
- $update = $oss->put($pathA, file_get_contents(request()->{'file_image'}->getRealPath()));
- if ($update) {
- return $this->apiResponseSuccess('图片上传成功', ['url' => $oss->url($pathA)]);
- } else {
- return $this->apiResponseError('图片上传保存失败,请重试');
- }
- } else {
- return $this->apiResponseError('请上传图片文件');
- }
- }
- }
- /**
- * 获取JS签名信息
- * @return \Illuminate\Http\JsonResponse
- */
- function getJsConfig()
- {
- $url = request()->input('url');
- $ret = WeixinServer::creatServer()->getJsConfig($url);
- return $this->apiResponseSuccess('获取信息成功', $ret);
- }
- /**
- * 获取系统简介
- * @return \Illuminate\Http\JsonResponse
- */
- function getSysMessage()
- {
- $type = request()->input('type', '1');
- $v = Config::where('key', 'about_us')->value('value');
- return $this->apiResponseSuccess('获取信息成功', $v);
- }
- /**
- * 获取定位信息
- */
- function getLocation()
- {
- $ip = CommonServer::creatServer()->getClientIp();
- $location = TxMapServer::creatServer()->getLocation($ip);
- if ($location['status'] === 0) {
- $data = $location['result']['location'];
- $address = TxMapServer::creatServer()->getLocationAddress($data['lat'], $data['lng']);
- if ($address['status'] != 0) {
- return $this->apiResponseError('定位失败');
- }
- $data['addr'] = $address['result']['address'];
- return $this->apiResponseSuccess('获取信息成功', $data);
- } else {
- return $this->apiResponseError('定位错误');
- }
- }
- /**
- * 根据经纬度获取地址信息
- * @return \Illuminate\Http\JsonResponse
- */
- function getLocationAddress()
- {
- $data['lat'] = request()->input('lat');
- $data['lng'] = request()->input('lng');
- if (empty($data['lat']) || empty($data['lng'])) {
- return $this->apiResponseError('缺少必要参数');
- }
- $address = TxMapServer::creatServer()->getLocationAddress($data['lat'], $data['lng']);
- if ($address['status'] != 0) {
- return $this->apiResponseError('定位失败');
- }
- $data['addr'] = $address['result']['address'];
- return $this->apiResponseSuccess('获取信息成功', $data);
- }
- /**
- * 获取阿里云临时权限
- * @return \Illuminate\Http\JsonResponse
- */
- function getAliSts()
- {
- $ret = CommonServer::creatServer()->getAliSts();
- if (empty($ret['code'])) {
- return $this->apiResponseError($ret['msg']);
- } else {
- return $this->apiResponseSuccess($ret['msg'], $ret['data']);
- }
- }
- /**
- * 获取隐私协议
- * @return \Illuminate\Http\JsonResponse
- */
- function getPrivacyInfo()
- {
- $info = Config::where('key', 'privacy_protocol')->value('value');
- return $this->apiResponseSuccess('获取成功', $info);
- }
- }
|