php - 区 block 链 API 问题

标签 php mysql laravel

我正在使用 PHP 7.2 和 laravel 这是我的区 block 链 api 代码

$blockchain_receive_root = "https://api.blockchain.info/";
    $secret = "ABIR";
    $my_api_key = $gateway->account;
    $my_xpub = $gateway->val1;

    $invoice_id = $transaction->hash;
    $callback_url = route('ipn.blockchain', ['invoice_id' => $invoice_id, 'secret' => $secret]);

    $resp = $blockchain_receive_root . "v2/receive?key=" . $my_api_key . "&callback=" . urlencode($callback_url) . "&xpub=" . $my_xpub;

    //BITCOIN API HAVING ISSUE. PLEASE TRY LATER
    if (!$resp) {
        return redirect()->route('account')->with('error', trans('site.blockchain.error'));
        exit;
    }
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $resp);
                curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                $laste = curl_exec($ch);
                curl_close($ch);

    $response = json_decode($laste);

    $var = "bitcoin:$response->address?amount=$transaction->btc_amo";
    $code =  "<img src=\"https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=$var&choe=UTF-8\" title='' style='width:300px;' />";

这是我的回调 URL 文件

        if($request->input('invoice_id') && $request->input('secret')) {

        $track = $request->input('invoice_id');
        $secret = $request->input('secret');
        $value = $request->input('value');
        $confirmations = $request->input('confirmations');
        $value_in_btc = $value / 100000000;
        $trx_hash = $request->input('transaction_hash');

        $order = Transaction::where('hash',$track)->first();

        if($order->status == 0){

            if ($order->btc_amo==$value_in_btc && $secret=="ABIR" && $confirmations >= 1){
                $savedata['confirmation'] = $trx_hash;
                $savedata['gateway_response'] = json_encode($request->all());
                $savedata['status'] = 'paid';

                //Update product sales
                $this->salesupdate($order->product_id);
                //Save order
                $this->neworder($order->user_id,$order->product_id,$order->price,$order->hash,$order->id);
                //Save user transaction
                $this->newusertransaction($order->user_id,$order->price);
                //Credit seller
                $this->creditseller($order->product_id);


                $order->update($savedata);
                 $request->session()->flash('success',trans('Your payments has been done!'));
                  return redirect()->route('account.mypurchases',$track);
            }
        }
    }

现在的问题是回调 URL 不执行他内部的功能 例如向卖家信用并更新产品销售

当我检查我的日志时,我发现了这个

[2018-09-15 04:27:07] production.ERROR: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '119' for key 'transaction_id' (SQL: insert into buys (user_id, product_id, price, hash, transaction_id, updated_at, created_at) values (2, 104, 0.20, 92b6564b75f60396590d744e5efacbbe, 119, 2018-09-15 04:27:07, 2018-09-15 04:27:07)) {"exception":"[object] (Illuminate\Database\QueryException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '119' for key 'transaction_id' (SQL: insert into buys (user_id, product_id, price, hash, transaction_id, updated_at, created_at) values (2, 104, 0.20, 92b6564b75f60396590d744e5efacbbe, 119, 2018-09-15 04:27:07, 2018-09-15 04:27:07)) at /srv/data/web/vhosts/heliux.pw/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '119' for key 'transaction_id' at /srv/data/web/vhosts/heliux.pw/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458) [stacktrace]

请有人告诉我错误在哪里以及如何修复

最佳答案

看起来 buys 表在 transaction_id 上有一个唯一索引,并且表中已经有此 transaction_id。

关于php - 区 block 链 API 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52341597/

相关文章:

php - 使用 ajax json 动态响应设置 webos 列表选择器选项

php - 如何获得共同好友并在 while 循环中显示结果

Php 文件离线连接到本地 SQL 文件。

php - 如何计算属于用户标识的所有行?

mysql - SQL 从行中选择数据如果存在否则创建行

php laravel - 如何传递 Controller 输出以查看 iframe 源

php - 在返回 "Oops! This link appears to be broken."的 PHP 404 header 之后包含

php - 将 PHP 表单插入到 MySQL 数据库会产生重复的意外结果

php - 如何在不等待一个结束执行的情况下执行多个 artisan 命令?

laravel - 如何在 Laravel 中使用 paginator::make() 在 View 中显示结果集?