Tree 1 kuukausi sitten
vanhempi
sitoutus
5223af141d

+ 98 - 0
app/Http/Controllers/Api/CoinPayController.php

@@ -0,0 +1,98 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Http\logic\api\CoinPayCashierLogic;
+use App\Http\logic\api\CoinPayLogic;
+use App\Inter\PayMentInterFace;
+use App\Notification\TelegramBot;
+use App\Services\CoinPay;
+use App\Util;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Redis;
+
+class CoinPayController implements PayMentInterFace
+{
+    private $retryTimes = 0;
+
+    public function pay_order($userId, $payAmt, $userName, $userEmail, $userPhone, $GiftsID, $buyIP, $AdId, $eventType, $pay_method = '')
+    {
+        $logic = new CoinPayLogic();
+
+        try {
+            $res = $logic->pay_order($userId, $payAmt, $userPhone, $userEmail, $userName, $GiftsID, $buyIP, $AdId, $eventType, $pay_method);
+        } catch (\Throwable $exception) {
+            Redis::set('PayErro_CoinPay', 1, 'EX', 600);
+            Util::WriteLog('CoinPay_error', $exception->getMessage());
+            TelegramBot::getDefault()->sendProgramNotify('CoinPay pay error', $exception->getMessage(), $exception);
+            return apiReturnFail($logic->getError());
+        }
+
+        if (isset($res['code']) && (int)$res['code'] === 0) {
+            $data = [
+                'content' => $res['data']['url'] ?? '',
+                'money' => $payAmt,
+                'prdOrdNo' => $res['data']['orderNo'] ?? '',
+            ];
+            return apiReturnSuc($data);
+        }
+
+        if ($res === false) {
+            return apiReturnFail($logic->getError());
+        }
+
+        if ($this->retryTimes > 0) {
+            Redis::set('PayErro_CoinPay', 1, 'EX', 600);
+            return apiReturnFail($logic->getError());
+        }
+
+        $this->retryTimes++;
+        return $this->pay_order($userId, $payAmt, $userName, $userEmail, $userPhone, $GiftsID, $buyIP, $AdId, $eventType, $pay_method);
+    }
+
+    public function notify(Request $request)
+    {
+        $post = $request->all();
+        Util::WriteLog('CoinPay', 'pay notify: ' . json_encode($post, JSON_UNESCAPED_UNICODE));
+
+        $service = new CoinPay();
+        if (!$service->verify($post)) {
+            Util::WriteLog('CoinPay', 'pay notify verify failed');
+            return 'fail';
+        }
+
+        $logic = new CoinPayLogic();
+        try {
+            return $logic->notify($post);
+        } catch (\Throwable $exception) {
+            Redis::set('PayErro_CoinPay', 1, 'EX', 600);
+            return '{"success":false,"message":"internal error"}';
+        }
+    }
+
+    public function sync_notify(Request $request)
+    {
+        Util::WriteLog('CoinPay', 'sync callback: ' . json_encode($request->all(), JSON_UNESCAPED_UNICODE));
+        return 'success';
+    }
+
+    public function cash_notify(Request $request)
+    {
+        $post = $request->all();
+        Util::WriteLog('CoinPay', 'cash notify: ' . json_encode($post, JSON_UNESCAPED_UNICODE));
+
+        $service = new CoinPay('CoinPayOut');
+        if (!$service->verify($post)) {
+            Util::WriteLog('CoinPay', 'cash notify verify failed');
+            return 'fail';
+        }
+
+        $logic = new CoinPayCashierLogic();
+        try {
+            return $logic->notify($post);
+        } catch (\Throwable $exception) {
+            return '{"success":false,"message":"internal error"}';
+        }
+    }
+}
+

+ 5 - 5
app/Http/Controllers/Game/PaymentEntryController.php

@@ -48,13 +48,13 @@ class PaymentEntryController {
         if ($query === null || $query === false) {
             return apiReturnFail(['web.payment.paytype_error','PayType ERROR']);
         }
-        $channel = $request->globalUser->Channel;
-        $payServiceString = PayMentService::getServiceByPayMethod($query, $payAmt,$pay_method);
+        if($pay_method>=64){
+            $payServiceString = 'CoinPay';
+        }else{
+            $payServiceString = PayMentService::getServiceByPayMethod($query, $payAmt,$pay_method);
+        }
 
 
-        Log::info('channel', [
-            'string' => $payServiceString
-        ]);
         $service = PayMentService::pay_order($payServiceString);
 
         if(isset($AdId)&&!empty($AdId))Redis::set('user_ad_'.$userId,$AdId);

+ 192 - 0
app/Http/logic/api/CoinPayCashierLogic.php

@@ -0,0 +1,192 @@
+<?php
+
+namespace App\Http\logic\api;
+
+use App\dao\Estatisticas\RechargeWithDraw;
+use App\Inter\CashierInterFace;
+use App\Models\PrivateMail;
+use App\Models\RecordUserDataStatistics;
+use App\Services\CoinPay;
+use App\Services\StoredProcedure;
+use App\Util;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class CoinPayCashierLogic implements CashierInterFace
+{
+    const AGENT = 102;
+
+    public function payment($RecordID, $amount, $accountName, $phone, $email, $OrderId, $PixNum, $PixType, $IFSCNumber, $BranchBank, $BankNO)
+    {
+        $query = DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('RecordID', $RecordID)->first();
+        if (!$query) {
+            return 'fail';
+        }
+
+        $service = new CoinPay('CoinPayOut');
+        $config = $service->getConfig();
+
+        $withdrawInfo = DB::table('QPAccountsDB.dbo.AccountWithDrawInfo')->where('UserID', $query->UserID)->first();
+        $address = $PixNum ?: ($withdrawInfo->PixNum ?? $withdrawInfo->BankNO ?? $BankNO);
+        if (!$address) {
+            Util::WriteLog('CoinPay', 'missing wallet address for withdraw: ' . $OrderId);
+            return 'fail';
+        }
+
+        $language = strtoupper($config['language'] ?? 'EN');
+        $coin = strtoupper($config['coin'] ?? 'USDT');
+        $protocol = strtoupper($config['protocol'] ?? 'TRC20');
+        $rateType = (int)($config['rateType'] ?? 2);
+        $currency = strtoupper($config['currency'] ?? 'USD');
+
+        $amountDecimal = number_format($amount / 100, 2, '.', '');
+
+        $params = [
+            'merchantMemberNo' => (string)$query->UserID,
+            'merchantOrderNo' => $OrderId,
+            'language' => $language,
+            'coin' => $coin,
+            'rateType' => $rateType,
+            'protocol' => $protocol,
+            'notifyUrl' => $config['cashNotify'] ?? '',
+            'toAddress' => $address,
+            'timestamp' => time(),
+        ];
+
+        if ($rateType === 1) {
+            $params['amount'] = number_format($amountDecimal, 8, '.', '');
+            $params['rate'] = $config['rate'] ?? '1';
+        } else {
+            $params['currencyAmount'] = $amountDecimal;
+            $params['currency'] = $currency;
+        }
+
+        $signedParams = $service->sign($params);
+        $response = $service->post('/order/withdrawOrderCoinCreate', $signedParams);
+
+        Log::info('CoinPay withdraw request', $signedParams);
+        Log::info('CoinPay withdraw response', [$response]);
+
+        try {
+            $data = \GuzzleHttp\json_decode($response, true);
+        } catch (\Throwable $e) {
+            Util::WriteLog('CoinPay_error', $e->getMessage());
+            return 'fail';
+        }
+
+        if (isset($data['code']) && (int)$data['code'] === 0) {
+            return $data;
+        }
+
+        return 'fail';
+    }
+
+    public function notify($post)
+    {
+        if (!is_array($post)) {
+            $post = \GuzzleHttp\json_decode($post, true);
+        }
+
+        Util::WriteLog('CoinPay', 'withdraw notify: ' . json_encode($post, JSON_UNESCAPED_UNICODE));
+
+        $OrderId = $post['merchantOrderNo'] ?? '';
+        $query = DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('OrderId', $OrderId)->first();
+        if (!$query) {
+            Util::WriteLog('CoinPay', 'withdraw order not found');
+            return '{"success":true,"message":"order not found"}';
+        }
+
+        if (!in_array($query->State, [5, 7])) {
+            Util::WriteLog('CoinPay', 'withdraw already handled: ' . $OrderId);
+            return 'SUCCESS';
+        }
+
+        $status = (int)($post['state'] ?? 0);
+        $now = now();
+        $withdraw_data = [];
+        $msg = $post['msg'] ?? '';
+
+        $TakeMoney = $query->WithDraw + $query->ServiceFee;
+        $UserID = $query->UserID;
+
+        switch ($status) {
+            case 3:
+                $withdraw_data = [
+                    'State' => 2,
+                    'agent' => self::AGENT,
+                    'finishDate' => $now,
+                ];
+                $this->handleSuccess($UserID, $TakeMoney, $OrderId, $query->ServiceFee);
+                break;
+
+            case 4:
+            case 5:
+            case 6:
+            case 7:
+                $msg = $msg ?: 'Withdraw rejected';
+                $bonus = '30000,' . $TakeMoney;
+                PrivateMail::failMail($UserID, $OrderId, $TakeMoney, $msg, $bonus);
+
+                $withdraw_data = [
+                    'State' => 6,
+                    'agent' => self::AGENT,
+                    'remark' => $msg,
+                ];
+                break;
+
+            default:
+                return 'SUCCESS';
+        }
+
+        $recordData = [
+            'before_state' => $query->State,
+            'after_state' => $withdraw_data['State'] ?? $query->State,
+            'RecordID' => $query->RecordID,
+            'update_at' => date('Y-m-d H:i:s'),
+        ];
+
+        DB::connection('write')->table('QPAccountsDB.dbo.AccountsRecord')
+            ->updateOrInsert(['RecordID' => $query->RecordID, 'type' => 1], $recordData);
+        DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')
+            ->where('OrderId', $OrderId)
+            ->update($withdraw_data);
+
+        return 'SUCCESS';
+    }
+
+    protected function handleSuccess($UserID, $TakeMoney, $OrderId, $serviceFee): void
+    {
+        $first = DB::connection('write')->table('QPAccountsDB.dbo.UserTabData')->where('UserID', $UserID)->first();
+        if ($first) {
+            DB::connection('write')->table('QPAccountsDB.dbo.UserTabData')->where('UserID', $UserID)->increment('TakeMoney', $TakeMoney);
+        } else {
+            DB::connection('write')->table('QPAccountsDB.dbo.UserTabData')->insert(['TakeMoney' => $TakeMoney, 'UserID' => $UserID]);
+            try {
+                PrivateMail::praiseSendMail($UserID);
+            } catch (\Throwable $e) {
+            }
+        }
+
+        try {
+            StoredProcedure::addPlatformData($UserID, 4, $TakeMoney);
+        } catch (\Throwable $exception) {
+            Util::WriteLog('StoredProcedure', $exception->getMessage());
+        }
+
+        $withdrawal_position_log = DB::connection('write')->table('agent.dbo.withdrawal_position_log')->where('order_sn', $OrderId)->first();
+        if ($withdrawal_position_log) {
+            DB::connection('write')->table('agent.dbo.withdrawal_position_log')
+                ->where('order_sn', $OrderId)
+                ->update(['take_effect' => 2, 'update_at' => date('Y-m-d H:i:s')]);
+        }
+
+        RecordUserDataStatistics::updateOrAdd($UserID, $TakeMoney, 0, $serviceFee);
+        (new RechargeWithDraw())->withDraw($UserID, $TakeMoney);
+        $redis = Redis::connection();
+        $redis->incr('draw_' . date('Ymd') . $UserID);
+
+        StoredProcedure::user_label($UserID, 2, $TakeMoney);
+    }
+}
+

+ 193 - 0
app/Http/logic/api/CoinPayLogic.php

@@ -0,0 +1,193 @@
+<?php
+
+namespace App\Http\logic\api;
+
+use App\dao\Pay\AccountPayInfo;
+use App\dao\Pay\PayController;
+use App\Http\helper\CreateOrder;
+use App\Http\helper\NumConfig;
+use App\Jobs\Order as OrderJob;
+use App\Notification\TelegramBot;
+use App\Services\CoinPay;
+use App\Services\OrderServices;
+use App\Services\PayConfig;
+use App\Services\CreateLog;
+use App\Util;
+use Illuminate\Support\Facades\DB;
+
+class CoinPayLogic extends BaseApiLogic
+{
+    public function pay_order($userId, $pay_amount, $userPhone, $userEmail, $userName, $GiftsID, $buyIP, $AdId, $eventType, $pay_method = '')
+    {
+        $dao = new AccountPayInfo();
+        [$userPhone, $userName, $userEmail] = $dao->payInfo($userId);
+
+        $PayVerify = new PayController();
+        if ($PayVerify->verify($userId, $GiftsID, $pay_amount) === false) {
+            $this->error = $PayVerify->getError();
+            return false;
+        }
+        if ($pay_amount < 0) {
+            $this->error = 'Payment error_4';
+            return false;
+        }
+
+        $service = new CoinPay();
+        $config = $service->getConfig();
+
+        $order_sn = CreateOrder::order_sn($userId);
+        $orderLogic = new OrderLogic();
+        $amountInt = (int) round($pay_amount * NumConfig::NUM_VALUE);
+        $orderLogic->orderCreate($order_sn, $amountInt, 'CoinPay', $userId, $pay_method, $GiftsID, $AdId, $eventType);
+
+        $language = strtoupper($config['language'] ?? 'en');
+        $coin = strtoupper($config['coin'] ?? 'USDT');
+        $protocol = strtoupper($config['protocol'] ?? 'TRC20');
+        $rateType = (int)($config['rateType'] ?? 2);
+        $currency = strtoupper($config['currency'] ?? 'USD');
+
+        $coinbase = [
+            64 => [
+                'coin' => 'USDT',
+                'protocol' => 'TRC20',
+            ],
+            128 =>[
+                'coin' => 'USDT',
+                'protocol' => 'ERC20',
+            ],
+            256 => [
+                'coin' => 'USDC',
+                'protocol' => 'TRC20',
+            ],
+            512 =>[
+                'coin' => 'USDC',
+                'protocol' => 'ERC20',
+            ]
+        ];
+
+        $select = $coinbase[$pay_method] ?? $coinbase[64];
+
+        $params = [
+            'merchantMemberNo' => (string)$userId,
+            'merchantOrderNo' => $order_sn,
+//            'amount' => $pay_amount,
+            'language' => $language,
+            'coin' => $select['coin'],
+            'rateType' => $rateType,
+            'protocol' => $select['protocol'],
+            'notifyUrl' => $config['notify'] ?? '',
+            'timestamp' => time(),
+        ];
+
+        if ($rateType === 1) {
+            $params['amount'] = number_format($pay_amount, 8, '.', '');
+            $params['rate'] = $config['rate'] ?? '1';
+        } else {
+            $params['currencyAmount'] = number_format($pay_amount, 2, '.', '');
+            $params['currency'] = $currency;
+        }
+
+        if (!empty($config['extra'])) {
+            $params = array_merge($params, $config['extra']);
+        }
+
+        $signedParams = $service->sign($params);
+        CreateLog::pay_request($userPhone, json_encode($signedParams), $order_sn, $userEmail, $userId, $userName);
+
+        $response = $service->post('/order/depositOrderCoinCreate', $signedParams);
+        Util::WriteLog('CoinPay', 'pay request => ' . json_encode($signedParams, JSON_UNESCAPED_UNICODE));
+        Util::WriteLog('CoinPay', 'pay response => ' . $response);
+
+        try {
+            $data = \GuzzleHttp\json_decode($response, true);
+        } catch (\Throwable $e) {
+            Util::WriteLog('CoinPay_error', $e->getMessage());
+            $this->error = 'Payment processing error';
+            return false;
+        }
+
+        if (!isset($data['code']) || (int)$data['code'] !== 0) {
+            $this->error = $data['msg'] ?? 'Payment request failed';
+        }
+
+        return $data;
+    }
+
+    public function notify(array $post)
+    {
+        $order_sn = $post['merchantOrderNo'] ?? '';
+        if (!$order_sn) {
+            return '{"success":false,"message":"missing order"}';
+        }
+
+        $order = DB::connection('write')->table('agent.dbo.order')->where('order_sn', $order_sn)->first();
+        if (!$order) {
+            Util::WriteLog('CoinPay', 'order not found: ' . $order_sn);
+            return '{"success":false,"message":"order not found"}';
+        }
+
+        if (!empty($order->pay_at) && !empty($order->finished_at)) {
+            return 'SUCCESS';
+        }
+
+        $status = (int)($post['state'] ?? 0);
+        $payAmt = (float)($post['currencyAmount'] ?? $post['amount'] ?? 0);
+
+        $body = [
+            'payment_sn' => $post['orderNo'] ?? '',
+            'updated_at' => date('Y-m-d H:i:s'),
+        ];
+
+        $GiftsID = $order->GiftsID ?: '';
+        $userID = $order->user_id ?: '';
+        $AdId = $order->AdId ?: '';
+        $eventType = $order->eventType ?: '';
+
+        switch ($status) {
+            case 3:
+                $body['pay_status'] = 1;
+                $body['pay_at'] = date('Y-m-d H:i:s');
+                $body['finished_at'] = date('Y-m-d H:i:s');
+                $body['amount'] = (int) round($payAmt * NumConfig::NUM_VALUE);
+
+                $config = (new PayConfig())->getConfig('CoinPay');
+                if (!empty($config['payin_fee'])) {
+                    $body['payment_fee'] = $body['amount'] * (float)$config['payin_fee'];
+                }
+
+                try {
+                    $service = new OrderServices();
+                    if ((int)$order->amount !== $body['amount']) {
+                        $body['GiftsID'] = 0;
+                        $Recharge = $payAmt;
+                        $give = 0;
+                        $favorable_price = $Recharge;
+                        $czReason = 1;
+                        $cjReason = 45;
+                    } else {
+                        [$give, $favorable_price, $Recharge, $czReason, $cjReason] = $service->getPayInfo($GiftsID, $userID, $payAmt);
+                    }
+
+                    [$Score] = $service->addRecord($userID, $payAmt, $favorable_price, $order_sn, $GiftsID, $Recharge, $czReason, $give, $cjReason, $AdId, $eventType);
+                    OrderJob::dispatch([$userID, $payAmt, $Score, $favorable_price, $GiftsID, $order_sn]);
+                } catch (\Throwable $exception) {
+                    Util::WriteLog('CoinPay_error', $exception->getMessage());
+                    TelegramBot::getDefault()->sendProgramNotify('CoinPay notify error', $exception->getMessage(), $exception);
+                }
+                break;
+
+            case 4:
+            case 5:
+                $body['pay_status'] = 2;
+                break;
+
+            default:
+                return 'fail';
+        }
+
+        DB::connection('write')->table('agent.dbo.order')->where('order_sn', $order_sn)->update($body);
+
+        return 'SUCCESS';
+    }
+}
+

+ 1 - 1
app/Http/logic/api/OrderLogic.php

@@ -93,7 +93,7 @@ class OrderLogic extends BaseApiLogic
             'user_id' => $userID,
             'order_sn' => $order_sn,
             'amount' => $amount,
-            'order_title' => empty($order_title) ? '用户充值' : $order_title,
+            'order_title' => empty($order_title) ? '1' : $order_title,
             'payment_code' => $payment_code,
             'payment_name' => '创建收款单',
             'remarks' => 'pay_order',

+ 1 - 1
app/Http/logic/api/WDPayLogic.php

@@ -45,7 +45,7 @@ class WDPayLogic extends BaseApiLogic
         // 生成订单信息(WDPay使用元,但数据库存储还是用分)
         $logic = new OrderLogic();
         $amount = (int) round($pay_amount * NumConfig::NUM_VALUE);
-        $logic->orderCreate($order_sn, $amount, 'WDPay', $userId, '', $GiftsID, $AdId, $eventType);
+        $logic->orderCreate($order_sn, $amount, 'WDPay', $userId, $pay_method, $GiftsID, $AdId, $eventType);
 
         $payMethods = [
             1 => 'cashapp',

+ 1 - 1
app/Http/logic/api/WiwiPayLogic.php

@@ -47,7 +47,7 @@ class WiwiPayLogic extends BaseApiLogic
         // 生成订单信息
         $logic = new OrderLogic();
         $amount = (int) round($pay_amount * NumConfig::NUM_VALUE) ;
-        $logic->orderCreate($order_sn, $amount, 'WiwiPay', $userId, '', $GiftsID, $AdId, $eventType);
+        $logic->orderCreate($order_sn, $amount, 'WiwiPay', $userId, $pay_method, $GiftsID, $AdId, $eventType);
 
         $payMethods = [
             1 => 'cashapp',

+ 4 - 0
app/Services/CashService.php

@@ -5,6 +5,7 @@ namespace App\Services;
 
 use App\Http\logic\api\WiwiPayCashierLogic;
 use App\Http\logic\api\WDPayCashierLogic;
+use App\Http\logic\api\CoinPayCashierLogic;
 use App\Http\logic\api\AiPayCashierLogic;
 
 
@@ -21,6 +22,9 @@ class CashService
             case WDPayCashierLogic::AGENT:
                 return new WDPayCashierLogic();
 
+            case CoinPayCashierLogic::AGENT:
+                return new CoinPayCashierLogic();
+
             case AiPayCashierLogic::AGENT:
                 return new AiPayCashierLogic();
 

+ 115 - 0
app/Services/CoinPay.php

@@ -0,0 +1,115 @@
+<?php
+
+namespace App\Services;
+
+use App\Util;
+
+class CoinPay
+{
+    protected $config;
+    protected $key;
+    protected $appId;
+    protected $apiUrl;
+    protected $version;
+
+    public function __construct(string $configKey = 'CoinPay')
+    {
+        $payConfig = new PayConfig();
+        $this->config = $payConfig->getConfig($configKey);
+
+        $this->key = $this->config['key'] ?? '';
+        $this->appId = $this->config['appId'] ?? '';
+        $this->apiUrl = rtrim($this->config['apiUrl'] ?? '', '/');
+        $this->version = $this->config['version'] ?? 'v1';
+    }
+
+    public function getConfig(): array
+    {
+        return $this->config;
+    }
+
+    public function sign(array $params): array
+    {
+        if (!isset($params['appId']) && $this->appId) {
+            $params['appId'] = $this->appId;
+        }
+        $params['sign'] = $this->generateSign($params);
+        return $params;
+    }
+
+    public function verify(array $params): bool
+    {
+        if (!isset($params['sign'])) {
+            return false;
+        }
+
+        $received = strtolower($params['sign']);
+        unset($params['sign']);
+
+        if (!isset($params['appId']) && $this->appId) {
+            $params['appId'] = $this->appId;
+        }
+
+        return $received === $this->generateSign($params);
+    }
+
+    public function post(string $path, array $payload)
+    {
+        $url = $this->apiUrl . $path;
+        $headers = [
+            'Content-Type: application/json; charset=UTF-8',
+            'version: ' . $this->version,
+            'appId: ' . $this->appId,
+        ];
+
+        $body = json_encode($payload, JSON_UNESCAPED_UNICODE);
+
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
+        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
+        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+
+        $result = curl_exec($ch);
+        if (curl_errno($ch)) {
+            Util::WriteLog('CoinPay_error', 'CURL Error: ' . curl_error($ch));
+        }
+        curl_close($ch);
+
+        return $result;
+    }
+
+    protected function generateSign(array $params): string
+    {
+        $filtered = [];
+        foreach ($params as $key => $value) {
+            if ($key === 'sign') {
+                continue;
+            }
+            if ($value === null || $value === '') {
+                continue;
+            }
+            if (is_array($value)) {
+                $value = json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
+            }
+            $filtered[$key] = $value;
+        }
+
+        ksort($filtered);
+        $segments = [];
+        foreach ($filtered as $key => $value) {
+            $segments[] = $key . '=' . $value;
+        }
+        $segments[] = 'key=' . $this->key;
+
+        $string = implode('&', $segments);
+
+        return strtolower(hash('sha256', $string));
+    }
+}
+

+ 4 - 0
app/Services/PayMentService.php

@@ -11,6 +11,7 @@ use App\Http\Controllers\Api\GoopagoController;
 use App\Http\Controllers\Api\SitoBankController;
 use App\Http\Controllers\Api\WiwiPayController;
 use App\Http\Controllers\Api\WDPayController;
+use App\Http\Controllers\Api\CoinPayController;
 use App\Http\Controllers\Api\AiPayController;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Log;
@@ -29,6 +30,9 @@ class PayMentService
             case 'WDPay':
                 return new WDPayController();
 
+            case 'CoinPay':
+                return new CoinPayController();
+
             case 'AiPay':
                 return new AiPayController();
 

+ 5 - 0
routes/api.php

@@ -311,6 +311,11 @@ Route::any('/aipay/notify', 'Api\AiPayController@notify');
 Route::any('/aipay/payout_notify', 'Api\AiPayController@cash_notify');
 Route::any('/aipay/return', 'Api\AiPayController@sync_notify');
 
+// CoinPay数字货币
+Route::any('/coinpay/notify', 'Api\CoinPayController@notify');
+Route::any('/coinpay/payout_notify', 'Api\CoinPayController@cash_notify');
+Route::any('/coinpay/return', 'Api\CoinPayController@sync_notify');
+
 
 Route::any('/russia/notify', 'Api\RussiaPayController@notify');
 Route::any('/russia/cash_notify', 'Api\RussiaPayController@cash_notify');