GetEnergyPlatformBalance.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <?php
  2. namespace App\Task;
  3. use App\Model\Energy\EnergyPlatform;
  4. use App\Library\Log;
  5. use App\Service\RsaServices;
  6. use App\Model\Telegram\TelegramBotUser;
  7. class GetEnergyPlatformBalance
  8. {
  9. public function execute()
  10. {
  11. try {
  12. $data = EnergyPlatform::from('energy_platform as a')
  13. ->leftJoin('telegram_bot as b','a.tg_notice_bot_rid','b.rid')
  14. ->where('a.status',0)
  15. ->select('a.*','b.bot_token')
  16. ->get();
  17. if($data->count() > 0){
  18. $rsa_services = new RsaServices();
  19. foreach ($data as $k => $v) {
  20. //neee.cc平台
  21. if($v['platform_name'] == 1){
  22. $header = [
  23. "Content-Type:application/json"
  24. ];
  25. $param = [
  26. "uid" => $v['platform_uid'],
  27. "time" => time()
  28. ];
  29. ksort($param);
  30. reset($param);
  31. $signstr = $rsa_services->privateDecrypt($v['platform_apikey']);
  32. foreach($param as $k1 => $v1){
  33. if($k1 != "sign" && $k1 != "sign_type" && $v1!=''){
  34. $signstr .= $k1.$v1;
  35. }
  36. }
  37. $sign = md5($signstr);
  38. $param['sign'] = $sign;
  39. $balance_url = 'https://api.tronqq.com/openapi/v1/user/balance';
  40. $res = Get_Pay($balance_url,json_encode($param),$header);
  41. if(empty($res)){
  42. $this->log('energyplatformbalance',$v['rid'].'平台请求失败');
  43. }else{
  44. $res = json_decode($res,true);
  45. if($res['status'] == 200){
  46. if(empty($res['data'])){
  47. $this->log('energyplatformbalance',$v['rid'].'平台请求失败2:'.json_encode($res));
  48. }else{
  49. $balance = $res['data']['balance'];
  50. $balance = $balance <= 0 ?0:$balance;
  51. $updatedata1['platform_balance'] = $balance;
  52. //间隔10分钟通知一次
  53. if($balance <= $v['alert_platform_balance'] && $v['alert_platform_balance'] > 0 && strtotime($v['last_alert_time']) + 600 <= strtotime(nowDate())){
  54. $updatedata1['last_alert_time'] = nowDate();
  55. //余额通知管理员
  56. if($v['tg_notice_obj'] && !empty($v['tg_notice_obj'])){
  57. $replytext = "能量平台(neee.cc),余额不足,请立即前往平台充值!\n"
  58. ."能量平台ID:".$v['rid']."\n"
  59. ."平台用户UID:".$v['platform_uid']."\n"
  60. ."当前余额:".$balance."\n"
  61. ."告警金额:".$v['alert_platform_balance']."\n\n"
  62. ."不处理会一直告警通知!间隔10分钟告警一次";
  63. $sendlist = explode(',',$v['tg_notice_obj']);
  64. foreach ($sendlist as $x => $y) {
  65. $sendmessageurl = 'https://api.telegram.org/bot'.$v['bot_token'].'/sendMessage?chat_id='.$y.'&text='.urlencode($replytext).'&parse_mode=HTML';
  66. Get_Pay($sendmessageurl);
  67. }
  68. }
  69. }
  70. EnergyPlatform::where('rid',$v['rid'])->update($updatedata1);
  71. }
  72. }else{
  73. $this->log('energyplatformbalance',$v['rid'].'平台请求失败3:'.json_encode($res));
  74. }
  75. }
  76. }
  77. //RentEnergysBot平台
  78. elseif($v['platform_name'] == 2){
  79. $signstr = $rsa_services->privateDecrypt($v['platform_apikey']);
  80. $balance_url = 'https://api.wallet.buzz?api=getBalance&apikey='.$signstr;
  81. $res = Get_Pay($balance_url);
  82. if(!isset($res) || $res === ""){
  83. $this->log('energyplatformbalance',$v['rid'].'平台请求失败1:');
  84. }else{
  85. $balance = $res <= 0 ?0:$res;
  86. $updatedata2['platform_balance'] = $balance;
  87. if($balance <= $v['alert_platform_balance'] && $v['alert_platform_balance'] > 0 && strtotime($v['last_alert_time']) + 600 <= strtotime(nowDate())){
  88. $updatedata2['last_alert_time'] = nowDate();
  89. //余额通知管理员
  90. if($v['tg_notice_obj'] && !empty($v['tg_notice_obj'])){
  91. $replytext = "能量平台(RentEnergysBot),余额不足,请立即前往平台充值!\n"
  92. ."能量平台ID:".$v['rid']."\n"
  93. ."平台用户UID:".$v['platform_uid']."\n"
  94. ."当前余额:".$balance."\n"
  95. ."告警金额:".$v['alert_platform_balance']."\n\n"
  96. ."不处理会一直告警通知!间隔10分钟告警一次";
  97. $sendlist = explode(',',$v['tg_notice_obj']);
  98. foreach ($sendlist as $x => $y) {
  99. $sendmessageurl = 'https://api.telegram.org/bot'.$v['bot_token'].'/sendMessage?chat_id='.$y.'&text='.urlencode($replytext).'&parse_mode=HTML';
  100. Get_Pay($sendmessageurl);
  101. }
  102. }
  103. }
  104. EnergyPlatform::where('rid',$v['rid'])->update($updatedata2);
  105. }
  106. }
  107. //自己质押代理
  108. elseif($v['platform_name'] == 3 && mb_strlen($v['platform_uid']) == 34){
  109. $tronurl = 'https://api.trongrid.io/wallet/getaccountresource';
  110. $api_key = config('apikey.gridapikey');
  111. $apikeyrand = $api_key[array_rand($api_key)];
  112. $heders = [
  113. "TRON-PRO-API-KEY:".$apikeyrand
  114. ];
  115. $body = [
  116. "address" => $v['platform_uid'],
  117. "visible" => true
  118. ];
  119. $tronres = Get_Pay($tronurl,json_encode($body),$heders);
  120. if(empty($tronres)){
  121. $this->log('energyplatformbalance',$v['rid'].'平台请求失败1:');
  122. }else{
  123. $tronres = json_decode($tronres,true);
  124. if(isset($tronres['EnergyLimit'])){
  125. $balance = $tronres['EnergyLimit'] - ($tronres['EnergyUsed'] ?? 0);
  126. $updatedata3['platform_balance'] = $balance;
  127. if($balance <= $v['alert_platform_balance'] && $v['alert_platform_balance'] > 0 && strtotime($v['last_alert_time']) + 600 <= strtotime(nowDate())){
  128. $updatedata3['last_alert_time'] = nowDate();
  129. //余额通知管理员
  130. if($v['tg_notice_obj'] && !empty($v['tg_notice_obj'])){
  131. $replytext = "能量平台(自己质押代理),能量不足,请立即质押!\n"
  132. ."能量平台ID:".$v['rid']."\n"
  133. ."质押钱包地址:".$v['platform_uid']."\n"
  134. ."当前能量剩余:".$balance."\n"
  135. ."告警能量值:".$v['alert_platform_balance']."\n\n"
  136. ."不处理会一直告警通知!间隔10分钟告警一次";
  137. $sendlist = explode(',',$v['tg_notice_obj']);
  138. foreach ($sendlist as $x => $y) {
  139. $sendmessageurl = 'https://api.telegram.org/bot'.$v['bot_token'].'/sendMessage?chat_id='.$y.'&text='.urlencode($replytext).'&parse_mode=HTML';
  140. Get_Pay($sendmessageurl);
  141. }
  142. }
  143. }
  144. EnergyPlatform::where('rid',$v['rid'])->update($updatedata3);
  145. }
  146. }
  147. }
  148. //trongas.io平台
  149. elseif($v['platform_name'] == 4){
  150. $param = [
  151. "username" => $v['platform_uid']
  152. ];
  153. $balance_url = 'https://trongas.io/api/userInfo';
  154. $res = Get_Pay($balance_url,$param);
  155. if(empty($res)){
  156. $this->log('energyplatformbalance',$v['rid'].'平台请求失败');
  157. }else{
  158. $res = json_decode($res,true);
  159. if($res['code'] == 10000){
  160. if(empty($res['data'])){
  161. $this->log('energyplatformbalance',$v['rid'].'平台请求失败2:'.json_encode($res));
  162. }else{
  163. $balance = $res['data']['balance'];
  164. $balance = $balance <= 0 ?0:$balance;
  165. $updatedata4['platform_balance'] = $balance;
  166. //间隔10分钟通知一次
  167. if($balance <= $v['alert_platform_balance'] && $v['alert_platform_balance'] > 0 && strtotime($v['last_alert_time']) + 600 <= strtotime(nowDate())){
  168. $updatedata4['last_alert_time'] = nowDate();
  169. //余额通知管理员
  170. if($v['tg_notice_obj'] && !empty($v['tg_notice_obj'])){
  171. $replytext = "能量平台(trongas.io),余额不足,请立即前往平台充值!\n"
  172. ."能量平台ID:".$v['rid']."\n"
  173. ."平台用户UID:".$v['platform_uid']."\n"
  174. ."当前余额:".$balance."\n"
  175. ."告警金额:".$v['alert_platform_balance']."\n\n"
  176. ."不处理会一直告警通知!间隔10分钟告警一次";
  177. $sendlist = explode(',',$v['tg_notice_obj']);
  178. foreach ($sendlist as $x => $y) {
  179. $sendmessageurl = 'https://api.telegram.org/bot'.$v['bot_token'].'/sendMessage?chat_id='.$y.'&text='.urlencode($replytext).'&parse_mode=HTML';
  180. Get_Pay($sendmessageurl);
  181. }
  182. }
  183. }
  184. EnergyPlatform::where('rid',$v['rid'])->update($updatedata4);
  185. }
  186. }else{
  187. $this->log('energyplatformbalance',$v['rid'].'平台请求失败3:'.json_encode($res));
  188. }
  189. }
  190. }
  191. //机器人开发者代理
  192. elseif($v['platform_name'] == 5){
  193. $balance_url = env('THIRD_URL');
  194. if(!empty($balance_url)){
  195. $balance_url = $balance_url.'/api/thirdpart/balance?tg_uid='.$v['platform_uid'];
  196. $res = Get_Pay($balance_url);
  197. if(empty($res)){
  198. $this->log('energyplatformbalance',$v['rid'].'平台请求失败');
  199. }else{
  200. $res = json_decode($res,true);
  201. if($res['code'] == 200){
  202. if(empty($res['data'])){
  203. $this->log('energyplatformbalance',$v['rid'].'平台请求失败2:'.json_encode($res));
  204. }else{
  205. $balance = $res['data']['trx_balance'];
  206. $balance = $balance <= 0 ?0:$balance;
  207. $updatedata5['platform_balance'] = $balance;
  208. //间隔10分钟通知一次
  209. if($balance <= $v['alert_platform_balance'] && $v['alert_platform_balance'] > 0 && strtotime($v['last_alert_time']) + 600 <= strtotime(nowDate())){
  210. $updatedata5['last_alert_time'] = nowDate();
  211. //余额通知管理员
  212. if($v['tg_notice_obj'] && !empty($v['tg_notice_obj'])){
  213. $replytext = "能量平台(机器人开发者代理),余额不足,请立即联系客服充值!\n"
  214. ."能量平台ID:".$v['rid']."\n"
  215. ."平台用户UID:".$v['platform_uid']."\n"
  216. ."当前余额:".$balance."\n"
  217. ."告警金额:".$v['alert_platform_balance']."\n\n"
  218. ."不处理会一直告警通知!间隔10分钟告警一次";
  219. $sendlist = explode(',',$v['tg_notice_obj']);
  220. foreach ($sendlist as $x => $y) {
  221. $sendmessageurl = 'https://api.telegram.org/bot'.$v['bot_token'].'/sendMessage?chat_id='.$y.'&text='.urlencode($replytext).'&parse_mode=HTML';
  222. Get_Pay($sendmessageurl);
  223. }
  224. }
  225. }
  226. EnergyPlatform::where('rid',$v['rid'])->update($updatedata5);
  227. }
  228. }else{
  229. $this->log('energyplatformbalance',$v['rid'].'平台请求失败3:'.json_encode($res));
  230. }
  231. }
  232. }
  233. }
  234. // MeFree.NET 平台
  235. elseif($v['platform_name'] == 6){
  236. // API 配置信息
  237. $base_url = "https://api.mefree.net"; // Mefree API 基础地址
  238. $api_key = $v['platform_uid']; // 替换为实际的 API Key
  239. $secret_key = $v['platform_apikey']; // 替换为实际的 Secret Key
  240. // 获取账户信息
  241. $request_path = "/api/available"; // API 请求路径
  242. $response = send_request("GET", $request_path, $base_url, $api_key, $secret_key);
  243. // 处理返回结果
  244. if ($response['code'] == 0) {
  245. $balance = $response['data'] <= 0 ?0:$response['data'];
  246. $updatedata2['platform_balance'] = $balance;
  247. if($balance <= $v['alert_platform_balance'] && $v['alert_platform_balance'] > 0 && strtotime($v['last_alert_time']) + 600 <= strtotime(nowDate())){
  248. $updatedata2['last_alert_time'] = nowDate();
  249. //余额通知管理员
  250. if($v['tg_notice_obj'] && !empty($v['tg_notice_obj'])){
  251. $replytext = "能量平台(MeFree.NET),余额不足,请立即前往平台充值!\n"
  252. ."能量平台ID:".$v['rid']."\n"
  253. ."平台用户UID:".$v['platform_uid']."\n"
  254. ."当前余额:".$balance."\n"
  255. ."告警金额:".$v['alert_platform_balance']."\n\n"
  256. ."不处理会一直告警通知!间隔10分钟告警一次";
  257. $sendlist = explode(',',$v['tg_notice_obj']);
  258. foreach ($sendlist as $x => $y) {
  259. $sendmessageurl = 'https://api.telegram.org/bot'.$v['bot_token'].'/sendMessage?chat_id='.$y.'&text='.urlencode($replytext).'&parse_mode=HTML';
  260. Get_Pay($sendmessageurl);
  261. }
  262. }
  263. }
  264. EnergyPlatform::where('rid',$v['rid'])->update($updatedata2);
  265. }
  266. }
  267. }
  268. }
  269. }catch (\Exception $e){
  270. $this->log('energyplatformbalance','----------任务执行报错,请联系管理员。报错原因:----------'.$e->getMessage());
  271. }
  272. }
  273. /**
  274. * 记入日志
  275. * @param $log_title [日志路径]
  276. * @param $message [内容,不支持数组]
  277. * @param $remarks [备注]
  278. */
  279. protected function log($log_title,$message,$remarks='info'){
  280. Log::get($remarks,$log_title)->info($message);
  281. }
  282. }