PHP code example of diaojinlong / dpay-request

1. Go to this page and download the library: Download diaojinlong/dpay-request 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/ */

    

diaojinlong / dpay-request example snippets




$config = [
    'host'=>'多支付平台接口域名', //例如:http://127.0.0.1
    'appid'=>'多支付平台AppID',
    'secret'=>'多支付平台Secret'
];

//初始化类
$dPay = new \DpayRequest\Request($config);

$price = 50.00; //支付金额
$payType = 1; //支付方式:1=微信,2=支付宝
$outTradeNo = 'cs1234567890' //商户单号
$notifyUrl = 'http://xxx.xxx.xx/notify'; //请填写自己服务器接收成功推送通知的接口
$returnUrl = 'http://xxx.xxx.xx/return'; //请填写自己服务器成功页面地址
$description = '会员充值'; //填写支付说明
$endPayTime = 5; //创建的订单5分钟后失效

//创建订单
$createOrder = $dPay->createOrders($price, $payType, $outTradeNo, $notifyUrl, $returnUrl, $description, $endPayTime);
var_dump($createOrder);
if($createOrder['code'] == 200){
    echo '创建成功';
}else{
    echo '创建失败';
}
$prepayId = $createOrder['data']['prepay_id']; //支付单号

//商户单号查询订单
$queryOrder = $dPay->queryOrders($outTradeNo);

//支付单号查询订单
$queryOrder = $dPay->queryOrders('', $prepayId);


//验证服务端推送的数据
$res = $dPay->validationPaySign($_POST);
if($res === true){
    echo '验证成功';
}else{
    echo '验证失败';
}