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