小编fro*_*fat的帖子

PHP Guzzle POST 请求返回空值

我正在为此绞尽脑汁 - 请求在 Postman 中运行良好,但我无法使用 Guzzle 访问正文。

$client = new \GuzzleHttp\Client();

        $res = $client->request('POST',  'https://apitest.authorize.net/xml/v1/request.api', [
            'headers' => [
                'Content-Type' => 'application/json',
            ],
            'body' => json_encode([
                'createTransactionRequest' => [
                    'merchantAuthentication' => [
                        'name' => '88VuW****',
                        'transactionKey' => '2xyW8q65VZ*****'
                    ],
                    'transactionRequest' => [
                        'transactionType' => 'authCaptureTransaction',
                        'amount' => "5.00",
                        'payment' => [
                            'opaqueData' => [
                                'dataDescriptor' => 'COMMON.ACCEPT.INAPP.PAYMENT',
                                'dataValue' => $_POST['dataValue']
                            ]
                        ]
                    ]
                ]
            ])
        ]);

        dd(json_decode($res->getBody()));
Run Code Online (Sandbox Code Playgroud)

以上返回null - 没有错误,只是null。下面是 Postman 中的相同请求,使用 body 成功。

在此处输入图片说明

任何想法将不胜感激,谢谢!

php post guzzle

3
推荐指数
1
解决办法
2312
查看次数

在 Laravel 中添加字符串类型的外键时出错

我有两张桌子,一张代金券和一张订单。凭证需要有16个字符串作为ID,随机创建。当 ID 作为整数递增时一切正常,但是当更改为字符串时,我无法让它添加外键,出现此错误:

 [Illuminate\Database\QueryException]
 SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL
 : alter table `orders` add constraint `orders_voucher_id_foreign` foreign k
 ey (`voucher_id`) references `vouchers` (`id`))

 [PDOException]
 SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
Run Code Online (Sandbox Code Playgroud)

这是我的表:

    Schema::create('vouchers', function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->string('id');
        $table->integer('value');
        $table->string('status');
        $table->timestamps();
    });

    Schema::create('orders', function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->increments('id');
        $table->integer('user_id')->unsigned();
        $table->integer('event_id')->unsigned();
        $table->string('voucher_id');
        $table->timestamps();      

        $table->foreign('user_id')->references('id')->on('users');
        $table->foreign('event_id')->references('id')->on('events');
        $table->foreign('voucher_id')->references('id')->on('vouchers');
    });
Run Code Online (Sandbox Code Playgroud)

任何反馈将不胜感激。提前致谢。

php mysql foreign-keys laravel eloquent

1
推荐指数
1
解决办法
1427
查看次数

标签 统计

php ×2

eloquent ×1

foreign-keys ×1

guzzle ×1

laravel ×1

mysql ×1

post ×1