修改功能
This commit is contained in:
parent
30221fa626
commit
8ceabd0eec
|
@ -3,7 +3,9 @@
|
|||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Models\UsdtAddr;
|
||||
use App\ServicePay\PayApiProvidesTrait;
|
||||
use App\ServicePay\UsdtWalletServices;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
@ -36,7 +38,11 @@ class UsdtAddrGetList extends Command
|
|||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var UsdtWalletServices
|
||||
*/
|
||||
private $pay_service;
|
||||
private $pay_gate;
|
||||
/**
|
||||
|
@ -47,6 +53,7 @@ class UsdtAddrGetList extends Command
|
|||
public function handle()
|
||||
{
|
||||
$this->checkNeedUpdateAddr();
|
||||
$this->updateTimeoutAddr();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,14 +73,15 @@ class UsdtAddrGetList extends Command
|
|||
Log::error('通道不存在 1017');
|
||||
return;
|
||||
}
|
||||
Log::info($this->pay_gate);
|
||||
|
||||
$this->pay_service->payConfig('1007');
|
||||
Log::info($this->pay_service->pay_config);
|
||||
|
||||
|
||||
//查找地址数据库
|
||||
$addr_list = \App\Models\UsdtAddr::all();
|
||||
$addr_list = UsdtAddr::all();
|
||||
if(count($addr_list) > 0){
|
||||
Log::info(count($addr_list));
|
||||
return;
|
||||
}
|
||||
//没有地址数据,请求接口更新数据
|
||||
$addr = $this->reqAddrList();
|
||||
|
@ -89,8 +97,6 @@ class UsdtAddrGetList extends Command
|
|||
$this->insertAddr($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -98,10 +104,10 @@ class UsdtAddrGetList extends Command
|
|||
$createUrl='http://api.etwallet.net/wallet'.'/v1/api/address/batch';
|
||||
|
||||
//商户号
|
||||
$accountId = $this->pay_service->pay_config['mch_id'];
|
||||
$accountId = $this->pay_service->pay_config['app_id'];
|
||||
//商户秘钥
|
||||
$key = $this->pay_service->pay_config['token'];
|
||||
Log::info($key);
|
||||
|
||||
$payData = [
|
||||
'num' => 2,//请求钱包地址数量
|
||||
'nonce' => strval(mt_rand(10000,99999)),//随机数
|
||||
|
@ -113,8 +119,8 @@ class UsdtAddrGetList extends Command
|
|||
$payData['sign'] = $sign;
|
||||
|
||||
$res = Curl::to($createUrl)->withData($payData)->post();
|
||||
Log::info('下单接口请求内容' . json_encode($payData, 256), []);
|
||||
Log::info('返回内容' . json_encode($res, 256), []);
|
||||
// Log::info('下单接口请求内容' . json_encode($payData, 256), []);
|
||||
// Log::info('返回内容' . json_encode($res, 256), []);
|
||||
|
||||
$res = is_array($res) ? $res : json_decode($res, true);
|
||||
if (is_array($res) && isset($res['code']) && $res['code'] == 0) {
|
||||
|
@ -131,7 +137,7 @@ class UsdtAddrGetList extends Command
|
|||
private function insertAddr($addr)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
$addrModel = new \App\Models\UsdtAddr();
|
||||
$addrModel = new UsdtAddr();
|
||||
foreach ($addr as $k => $v) {
|
||||
$addrModel->$k = $v;
|
||||
}
|
||||
|
@ -145,4 +151,32 @@ class UsdtAddrGetList extends Command
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从订单表中,查找所有超期的订单,回收usdt地址
|
||||
* @return void
|
||||
*/
|
||||
public function updateTimeoutAddr(){
|
||||
$allOrder = Order::where(['pay_type'=>'1017','usdt_addr_status'=>'0'])
|
||||
->where('order_at','<',date('Y-m-d H:i:s',strtotime("-20 minute")))->limit(100)->get();
|
||||
if(empty($allOrder)){
|
||||
return;
|
||||
}
|
||||
$allOrder = $allOrder->toArray();
|
||||
if(!is_array($allOrder)){
|
||||
return;
|
||||
}
|
||||
//查询所有的订单地址
|
||||
foreach ($allOrder as $key => $value) {
|
||||
$addr = $value["usdt_addr"];
|
||||
if (!empty($addr)){
|
||||
try {
|
||||
Order::where("id",$value['id'])->firstOrFail()->update(['usdt_addr_status' => 1]);
|
||||
UsdtAddr::where("addr",$addr)->firstOrFail()->update(['is_checked' => 1]);
|
||||
}catch(Exception $exception){
|
||||
Log::error('失败异常内容:' . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,7 @@ class Kernel extends ConsoleKernel
|
|||
// $schedule->command('check:redis')->everyMinute()->sendOutputTo('storage/logs/checkredis.log')
|
||||
// ->withoutOverlapping();
|
||||
|
||||
$schedule->command('command:usdt_addr_get_list')->everyMinute()
|
||||
->sendOutputTo('storage/logs/usdtaddr.log')->withoutOverlapping();
|
||||
$schedule->command('command:usdt_addr_get_list')->everyMinute()->withoutOverlapping();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ class ApiOrderServices
|
|||
//检查商户
|
||||
$this->checkMerchant($request);
|
||||
//检查签名
|
||||
//$this->checkSign($this->merchant, $request);
|
||||
$this->checkSign($this->merchant, $request);
|
||||
//通道检查
|
||||
$this->checkGateway($request);
|
||||
if (count(self::$errorArr) > 0) {
|
||||
|
|
|
@ -98,7 +98,6 @@ class UsdtWalletServices extends BasePay implements PayApiInterface
|
|||
|
||||
public function sign($tempArr, $signKey,$filter=[]): string
|
||||
{
|
||||
|
||||
$keyVal = '';
|
||||
|
||||
if (isset($tempArr['sign'])) {
|
||||
|
@ -207,17 +206,22 @@ class UsdtWalletServices extends BasePay implements PayApiInterface
|
|||
//取得通道id
|
||||
$this->gateway = $this->pay_gateway = config('gateway.config')[$this->gateway_id];
|
||||
//dd($this->gateway);
|
||||
// $checkresult = $this->checkWhiteIP($this->gateway);//检查回调IP
|
||||
// if (!$checkresult) {
|
||||
// $this->debugLog('ip 不合法');
|
||||
// return 'ip 不合法';
|
||||
// }
|
||||
$checkresult = $this->checkWhiteIP($this->gateway);//检查回调IP
|
||||
if (!$checkresult) {
|
||||
$this->debugLog('ip 不合法');
|
||||
return 'ip 不合法';
|
||||
}
|
||||
//取得支付配置
|
||||
$this->payConfig($this->pay_type);
|
||||
|
||||
$this->result_data = $allData;
|
||||
// $this->debugLog('回调原始数据', $this->result_data);
|
||||
//检查三方的订单
|
||||
if($allData['amount'] != $this->order['order_money']){
|
||||
$this->debugLog('金额不正确');
|
||||
return '金额不正确';
|
||||
}
|
||||
|
||||
// $out_trade_no=strval($allData['id']);
|
||||
// $checkorder = $this->checkOrder($out_trade_no);
|
||||
// if (!$checkorder) {
|
||||
|
@ -229,10 +233,10 @@ class UsdtWalletServices extends BasePay implements PayApiInterface
|
|||
|
||||
|
||||
//进行验证签名
|
||||
// if (!$this->verify()) {
|
||||
// $this->debugLog('签名以及支付状态验证失败');
|
||||
// return '签名以及支付状态验证失败';
|
||||
// }
|
||||
if (!$this->verify()) {
|
||||
$this->debugLog('签名以及支付状态验证失败');
|
||||
return '签名以及支付状态验证失败';
|
||||
}
|
||||
|
||||
return $this->payNotify();
|
||||
}
|
||||
|
@ -378,6 +382,7 @@ class UsdtWalletServices extends BasePay implements PayApiInterface
|
|||
//需要增加订单表的usdt_addr
|
||||
$ret = $this->getUstdAddr();
|
||||
if(empty($ret)){
|
||||
$this->addError(['msg' => '没有可用的usdt地址']);
|
||||
return false;
|
||||
}
|
||||
$orderData['usdt_addr'] = $ret;
|
||||
|
@ -386,7 +391,7 @@ class UsdtWalletServices extends BasePay implements PayApiInterface
|
|||
|
||||
private function getUstdAddr(){
|
||||
DB::beginTransaction();
|
||||
$addr = UsdtAddr::where('is_checked',1)->orderby('updated_at','desc')->firstOrFail();
|
||||
$addr = UsdtAddr::where('is_checked',1)->orderby('updated_at','asc')->firstOrFail();
|
||||
if (!empty($addr)){
|
||||
$addr['is_checked'] = 0;
|
||||
$ret = $addr['addr'];
|
||||
|
|
|
@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Scope;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
class PayServices
|
||||
|
@ -47,8 +48,11 @@ class PayServices
|
|||
$strkey = $this->toUrlParams($data);
|
||||
//转换小写
|
||||
$app_signature=strtolower($strkey);
|
||||
//Log::info("md5 before:".$app_signature);
|
||||
//MD5加密
|
||||
$app_signature = md5($app_signature);
|
||||
//Log::info("md5 end:".$app_signature);
|
||||
|
||||
//回调验证
|
||||
if($is_verfy)
|
||||
{
|
||||
|
|
|
@ -111,6 +111,4 @@ $secret .= 'token=' . $token;
|
|||
|
||||
$sign = md5($token.md5(strtolower(trim($secret, '&'))).'pay_money=' . $_POST['pay_money'] . 'pay_status=' .$_POST['pay_status']);
|
||||
|
||||
uid=5
|
||||
ts=112223123
|
||||
|
||||
|
|
Loading…
Reference in New Issue