PHP code example of qfz9527 / saobei-sdk
1. Go to this page and download the library: Download qfz9527/saobei-sdk 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/ */
qfz9527 / saobei-sdk example snippets
//实例化调度器
$sdk = new \Saobei\sdk\Dispatcher();
//配置商户号、终端号、终端token
$sdk->initTerminal('yourMerchantNo', 'yourTerminalId', 'yourAccessToken');
//传入必传参数
$param = array(
'pay_type' => '010', //支付方式:微信、支付宝等
'terminal_trace' => '12345678901234567890123456789012', //客户端唯一流水号,生成须有识别性
'total_fee' => '1', //支付金额(分)
'auth_no' => '12345678901' //付款码
);
//调用方法,方法名大小写不敏感
//$result = $client->barcodepay($param);
$result = $sdk->barcodePay($param);
//实例化调度器
$sdk = new \Saobei\sdk\Dispatcher();
//配置商户号、终端号、终端token
$sdk->initTerminal('yourMerchantNo', 'yourTerminalId', 'yourAccessToken');
//请求转化为数组
$data = json_decode(file_get_contents('php://input'), true);//php-fpm模式接参
//$data = JsonParser::ToArray($request->post());//Request类接参
//传入闭包,处理业务逻辑
$response = $sdk->notify($data, function() use ($data) {
//TODO 业务逻辑
var_dump($data);
//if($data['total_fee'] == '1')echo "Amount checked \n";
/**
* 闭包返回
* @example
* []
* ["status" => true]
* ["status" => true, "errmsg" => "成功"]
* ["status" => false, "errmsg" => "签名失败"]
* */
return array();
});
//额外参数
$response['trace_no'] = $data['trace_no'];
//响应
echo json_encode($response, 256);
//实例化调度器
$sdk = new \Saobei\sdk\Dispatcher();
//配置机构号、KEY
$sdk->initMerchant('yourInstNo', 'yourKey');