Skip to content

Instantly share code, notes, and snippets.

@payjscn
Last active April 8, 2019 04:09
Show Gist options
  • Save payjscn/a05b96bf20ecb46dc32bc76c71f09419 to your computer and use it in GitHub Desktop.
Save payjscn/a05b96bf20ecb46dc32bc76c71f09419 to your computer and use it in GitHub Desktop.
PAYJS收银台模式DEMOO
<?php
$mchid = '**************'; // PAYJS 商户号
$key = '**************'; // 通信密钥
// 构造订单参数
$data = [
'mchid' => $mchid,
'body' => '我是一个测试订单标题',
'total_fee' => 1,
'out_trade_no' => 'payjs_jspay_demo_' . time(),
];
// 添加数据签名
$data['sign'] = sign($data, $key);
// 浏览器跳转到收银台
$url = 'https://payjs.cn/api/cashier?' . http_build_query($data);
header('Location: ' . $url);
// 获取签名
function sign($data, $key)
{
array_filter($data);
ksort($data);
return strtoupper(md5(urldecode(http_build_query($data) . '&key=' . $key)));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment