You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

151 lines
3.2 KiB

<?php
// 统一支付接口Demo
// 加载基础类
require_once('../library/Base.php');
$Base = new Base();
// 获取配置信息
$config = $Base->getConfig();
// var_dump('<pre>', $config);
// 接口URL(测试)
$api_url = $config['cancel_url'];
// 加个body字段传中文试试
// 组装交易报文
$reqsn_prefix = date('Ymd');
$trade_data = array(
'orgid' => $config['org_num'],
'cusid' => $config['cusid'],
'branchno' => $config['branchno'],
'termcode' => $config['termcode'],
'version' => $config['version'],
'trxamt' => '1',
'reqsn' => uniqid($reqsn_prefix),
'producp' => 'JX0002',
'transtype' => 'JSP511',
'randomstr' => md5( uniqid() ),
// 'oldreqsn' => '2023072464be31055e0e0',
'oldtrxid' => '100000018608497',
);
// $trade_data = array(
// "cusid" => "10147",
// "branchno" => "44",
// "termcode" => "000000",
// "version" => "11",
// "trxamt" => "1154634",
// "reqsn" => "112094120001088317",
// "producp" => "JX0002",
// "transtype" => "JSP501",
// "paytype" => "W01",
// "randomstr" => md5( uniqid() ),
// "body" => "",
// "remark" => "",
// "validtime" => "",
// "acct" => "",
// "notify_url" => "",
// "limit_pay" => "",
// "sub_appid" => "",
// "goods_tag" => "",
// "benefitdetail" => "",
// "chnlstoreid" => "",
// "extendparams" => "",
// "cusip" => "",
// "front_url" => "",
// "subbranch" => "",
// "idno" => "",
// "truename" => "",
// "asinfo" => "",
// "fqnum" => "",
// "unpid" => "",
// "terminfo" => "",
// // 其他参数...
// );
// $trade_data = array(
// "appid"=>"00000051",
// "cusid"=>"990581007426001",
// "randomstr"=>"82712208",
// "signtype"=>"RSA",
// "trxid"=>"112094120001088317",
// "version"=>"11",
// );
// 生成签名
$sign = $Base->Crypt->makeSign($trade_data);
if($sign === false)
{
echo $Base->Crypt->err_msg;
die();
}
echo "\r\n";
echo "[sign]: {$sign}";
// die();
// 加密交易报文
$crypted_trade_data = $Base->Crypt->encryptTradeData($trade_data);
if($crypted_trade_data === false)
{
echo $Base->Crypt->err_msg;
die();
}
echo "\r\n";
echo "[crypted message]: {$crypted_trade_data}";
// die();
// 发送报文
echo "\r\n";
var_dump($api_url);
$response = $Base->Request->send($api_url, $crypted_trade_data, $sign);
if($response === false)
{
echo $Base->Request->err_msg;
die();
}
echo "\r\n";
echo "[response message]: {$response}";
// 解析响应报文
$response = json_decode($response, true);
$response_data_crypted = $response['data'];
$response_sign = $response['sign'];
echo "\r\n";
echo "[response sign]: {$response_sign}";
echo "\r\n";
echo "[response data (ciphertext)]: {$response_data_crypted}";
// 解密响应密文
$response_data = $Base->Crypt->decryptTradeData($response_data_crypted);
if($response_data === false)
{
echo $Base->Crypt->err_msg;
die();
}
echo "\r\n";
// $response_data = mb_convert_encoding($response_data, 'UTF-8', 'GBK');
echo "[response data(clear text)]: {$response_data}";
// die();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>交易撤销Demo</title>
<style>
body{ word-break: break-word; }
</style>
</head>
<body></body>
</html>