创建支付示例

2021-03-23 06:09:33


PHP示例


<?php
	   $data = json_encode([
            'coin' => 'USDT',
            'currency_code' => 'VND',
            'payment_provider' => '',
            'amount' => 888.00,
            'sn' => '9621755adecdc83eb69143f73882e386',
            'notify_url' => 'http://www.youdomain.com/xxxx',
            'timestamp' => 1616305564
        ]);
        $app_id = 1234568;
        $secret = '9621755adecdc83eb69143f73882e380';
        $basicauth = "Basic " . base64_encode($app_id . ":" . $secret);
        $ch = curl_init('http://api.payotc.com/pay/gateway');
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "Authorization:".$basicauth,
            "Content-Type: application/json",
            "Content-Length: " . strlen($data)));
        $result = curl_exec($ch);
        $error = curl_error($ch);
        curl_close($ch);
        if ($error) {
            echo "CURL Error #: $error";
        } else {
            $response = json_decode($result);
            if ($response->status == 'fail')
            {
                return var_dump($response);
            }
            return file_get_contents($response->data->url);
        }
?>