PHP code example of morton / chinaums

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

    

morton / chinaums example snippets



Morton\Chinaums\Factory;

date_default_timezone_set('PRC');

$config = [
    // 请求网关  https://api-mop.chinaums.com/v1
    'gateway' => 'https://test-api-open.chinaums.com/v1',
    // 商户号
    'mid' => '89********5678',
    // 终端号
    'tid' => '88*****01',
    // 加密 APPID
    'appid' => '10037e************a5e5a0006',
    // 加密 KEY
    'appkey' => '1c4e3****************9e5b312e8',
    // 回调验证需要的md5key
    'md5key' => 'impARTx**************aKXDhCaTCXJ6'
];

$data = [];
// 报文请求时间
$data['requestTimestamp'] = date("YmdHis", time());
// 订单号
$data['merOrderId'] = time() . uniqid();
// 业务类型 机构商户号 MINIDEFAULT|QRPAYDEFAULT|YUEDANDEFAULT
$data['instMid'] = 'MINIDEFAULT';
 // 订单描述 展示在支付截图中
$data['orderDesc'] = '账单描述';
// 支付总金额
$data['totalAmount'] = 2; 
// 微信必填
$data['subAppId'] = 'wx0bd72821b0ce53cb';  
// 微信必填  前端获取用户的openid 传给后台
$data['subOpenId'] = 'o4Sic5HPuB3j-LmnQTVIC4G_oYqY';

//分账
// $subOrders = [];
// $sub['totalAmount'] = 1;      // 支付子金额
// $sub['mid'] = "898127210280001";      //
// $sub1['totalAmount'] = 1;      // 支付子金额
// $sub1['mid'] = "988460101800201";      //
// $subOrders[] = $sub;
// $subOrders[] = $sub1;
// $data['divisionFlag'] = 'true'; //分账标识
// $data['subOrders'] = $subOrders;      //

// 使用方法1
Factory::config($config);
$app = Factory::Wechat()->mini();
$reponse = $app->request($data);
echo 'response:' . $reponse . PHP_EOL;


// 使用方法2
Factory::config($config);
$reponse = Factory::Wechat()->pay($data);
echo 'response:' . $reponse . PHP_EOL;