PHP code example of nason / xrtpay

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

    

nason / xrtpay example snippets


use Nason\Xrtpay\Weixin\WeixinJsPay;
use Nason\Xrtpay\Xrtpay;

$payOptions = [
    'mch_id'        => 'xxxxxxxxxx', // 信瑞泰商户号
    'sub_appid'     => 'xxxxxxxxxx', // 微信公众号或者微信小程序 appid
    'notify_url'    => 'http://127.0.0.1/notify', // 接收支付回调通知的url,需绝对路径,255字符内
    'out_trade_no'  => 'xxxxxxxxxx', // 商户订单号
    'body'          => '测试商品', // 商品描述
    'sub_openid'    => 'xxxxxxxxxx', // 用户 openid
    'total_fee'     => '123', // 支付金额,单位:分
    'mch_create_ip' => '127.0.0.1', // 订单生成的机器 IP
];
// 信瑞泰密钥
$key = 'xxxxxxxxxx'; 

$weixinJsPay = new WeixinJsPay($key, $payOptions);
// 可设置其他非必需参数
$weixinJsPay->attach('product')->raw()->limitCreditPay();

try {
    $result = Xrtpay::pay($weixinJsPay);
} catch (\Exception $e) {
    // todo
}

use Nason\Xrtpay\Weixin\WeixinJsPay;

$jsUrl = WeixinJsPay::getJsPayUrl($tokenId);

use Nason\Xrtpay\XrtpayReverse;

$options = [
    'mch_id'       => 'xxxxxxxxxx', // 信瑞泰商户号
    'out_trade_no' => 'xxxxxxxxxx', // 商户订单号
];
// 信瑞泰密钥
$key = 'xxxxxxxxxx';

$xrtpayReverse = new XrtpayReverse($key, $options);
$result = $xrtpayReverse->reverse();

use Nason\Xrtpay\Xrtpay;

// 信瑞泰密钥
$key = 'xxxxxxxxxx'; 
// 信瑞泰回调通知数据
$notifyData = [];

// true or false
$result = Xrtpay::verifySign($key, $notifyData);