PHP code example of dogpay / chain

1. Go to this page and download the library: Download dogpay/chain library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dogpay / chain example snippets




use Dogpay\Chain\DogPay;

$config = [
    'key' => 'Your Key',
    'secret' => 'Your Secret',
    'public_key' => 'Your RSA Public Key',
    'private_key' => 'Your RSA Private Key',
    'chain_public_key' => 'Chain RSA Public Key',
];
$dogPay = new DogPay($config);

$open_id = 'project100005';

$result = $dogPay->createUser($open_id);



use Dogpay\Chain\DogPay;

$config = [
    'key' => 'Your Key',
    'secret' => 'Your Secret',
    'public_key' => 'Your RSA Public Key',
    'private_key' => 'Your RSA Private Key',
    'chain_public_key' => 'Chain RSA Public Key',
];
$dogPay = new DogPay($config);

$open_id = 'project100000'; //It is recommended to use project name + user unique identifier
$chain_id = 2;  //The Chain ID can be checked through the table below

$result = $dogPay->createWallet($open_id, $chain_id);



use Dogpay\Chain\DogPay;

$config = [
    'key' => 'Your Key',
    'secret' => 'Your Secret',
    'public_key' => 'Your RSA Public Key',
    'private_key' => 'Your RSA Private Key',
    'chain_public_key' => 'Chain RSA Public Key',
];
$dogPay = new DogPay($config);

$open_id = 'project100000';
$token_id = 4;  //The Token ID can be checked through the table below
$amount = 100;  //Amount of withdrawal
$address = 'TQ33qyLenhYxqMDPtVwdS92UhZwRWdD1VL';    //Withdrawal address
$callback_url = 'https://Your callback address';
$safe_check_code = '202408080808081';   //Security verification code for user withdrawal transactions

$result = $dogPay->withdraw($open_id, $token_id, $amount, $address, $callback_url, $safe_check_code);



use Dogpay\Chain\DogPay;

$postData = file_get_contents('php://input');
if(!$postData){
    exit;
}
$postData = json_decode($postData, true);

$config = [
    'key' => 'Your Key',
    'secret' => 'Your Secret',
    'public_key' => 'Your RSA Public Key',
    'private_key' => 'Your RSA Private Key',
    'chain_public_key' => 'Chain RSA Public Key',
];
$dogPay = new DogPay($config);

if(!$dogPay->verifyRsaSignature($postData)){
    //Failed to verify signature
    exit;
}

//The signature verification is successful, and the following business logic is processed
if($postData['type'] == 1){
    //Recharge transaction

}elseif($postData['type'] == 2){
    //Withdrawal transaction

}else{
    //Type Error
    exit;
}


$response = [
    'code' => 0,
    'msg' => 'ok',
    'data' => null,
];
exit(json_encode($response));



use Dogpay\Chain\DogPay;
use Dogpay\Chain\Client;

$postData = file_get_contents('php://input');

if(!$postData){
    exit;
}
$postData = json_decode($postData, true);

$config = [
    'key' => 'Your Key',
    'secret' => 'Your Secret',
    'public_key' => 'Your RSA Public Key',
    'private_key' => 'Your RSA Private Key',
    'chain_public_key' => 'Chain RSA Public Key',
    'chain_withdraw_public_key' => 'Chain withdrawal risk control RSA public key',
];
$dogPay = new DogPay($config);

if(!$dogPay->verifyWithdrawRsaSignature($postData)){
    //Failed to verify signature
    exit;
}


//Verify the order information requested by the platform here. If the information is correct, the corresponding information will be as follows
$response = [
    'code' => 0,
    'timestamp' => time(),
    'message' => '',
];
$client = new Client($config);
$sign = $client->encryption($response);
$response['sign'] = $sign;

exit(json_encode($response));