PHP code example of jpaypp / jpay-php

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

    

jpaypp / jpay-php example snippets






\MasJPay\MasJPay::setDebug(true); //调试模式   true /false
\MasJPay\MasJPay::setApiMode('sandbox'); //环境  live 线上,sandbox 沙盒
\MasJPay\MasJPay::setClientId('10000000');   // 设置 CLIENT ID
\MasJPay\MasJPay::setApiKey('BQokikJOvBiI2HlWgH4olfQ2');    // 设置 API Key
try {
    $ch = \MasJPay\Charge::create([
        'channel'   => '901',                // 支付使用的第三方支付渠道取值
        'out_order_no' => time(),  //外部订单号 ,为空时由系统生成
        'product' =>[  //商品信息
            'subject'      => '测试商品',   //商品名称
            'body'      => '测试商品',   //商品描述
            'amount'    => '1',   // 订单总金额
            'quantity'  => '1'  //商品数量
        ],
        'extra'    =>[     //扩展信息
            'mode'      => 'mweb',  //微信渠道901 ,支付模式,jsapi 微信公众号、native 扫码支付、mweb H5 支付 ,link 返回支付链接跳转
            'format'    => 'json', //返回方式 from 表单直接提交/ json 返回
        ],
        'metadata'  => '自定义数据',
        'client_ip' => '1.1.1.1',   //客户端发起支付请求的IP
        'description' => '测试数据', //订单备注说明
        'notify'=> 'http://localhost/notify.html',   //异步通知地址
        'return'=>'http://localhost/callback.html',  //同步地址
     ]);
    echo $ch;                                       // 输出 返回的支付凭据 Charge
} catch (\MasJPay\Error\Base $e) {
    // 捕获报错信息
    if ($e->getHttpStatus() != null) {
        header('Status: ' . $e->getHttpStatus());
        echo $e->getHttpBody();
    } else {
        echo $e->getMessage();
    }
}


bash
composer 
bash
./vendor/bin/phpunit tests/UtilTest.php