dogpay / chain
DogPay PHP,一个用于调用DogPay支付通道的面向对象库
v1.0.2
2024-08-16 22:15 UTC
Requires
- php: >=7.0
README
安装
推荐通过 Composer 安装PHP-DogPay。
$ composer require dogpay/chain
创建用户
require 'vendor/autoload.php'; 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);
创建钱包
require 'vendor/autoload.php'; 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);
提现
require 'vendor/autoload.php'; 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);
通知回调
require 'vendor/autoload.php'; 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));
提现订单二次审核
require 'vendor/autoload.php'; 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));