测试期间不要设置白名单
<?
$appId = 'appId';
$appKey = 'appKey';
$mid = 'mid';
$tid = 'tid';
//业务内容az
$time = time();
$content = [
'requestTimestamp' => date('Y-m-d H:i:s', $time),//报文请求时间
'merOrderId' => '32AF' . date('YmdHis'),//商户订单号
'mid' => $mid,//商户号
'tid' => $tid,//终端号
'instMid' => 'H5DEFAULT',//业务类型
'totalAmount' => '1',//支付总金额
'expireTime' => date('Y-m-d H:i:s', strtotime('+1 day', $time)),//过期时间
'notifyUrl' => '',//支付通知地址
'returnUrl' => ''//网页跳转地址
];
$timestamp = date('YmdHis', $time);
//随机数
$str = md5(uniqid(mt_rand(), true));
$uuid = substr($str, 0, 8) . '-';
$uuid .= substr($str, 8, 4) . '-';
$uuid .= substr($str, 12, 4) . '-';
$uuid .= substr($str, 16, 4) . '-';
$uuid .= substr($str, 20, 12);
$nonce = $uuid;
//签名
$hash = bin2hex(hash('sha256', json_encode($content), true));
$hashStr = $appId . $timestamp . $nonce . $hash;
$signature = base64_encode((hash_hmac('sha256', $hashStr, $appKey, true))); //$appKey银联商户H5支付产品的AppKey
$data = [
'timestamp' => $timestamp,//时间戳
'authorization' => 'OPEN-FORM-PARAM',//认证方式
'appId' => $appId,//APPID
'nonce' => $nonce,//随机数
'content' => urlencode(json_encode($content)),//业务内容
'signature' => urlencode($signature),//签名
];
$options = '';
foreach ($data as $key => $value) {
$options .= $key . '=' . $value .'&';
}
$options = rtrim($options, '&');
//存在转义字符,那么去掉转义
if(get_magic_quotes_gpc()){
$options = stripslashes($options);
}
$url = 'https://api-mop.chinaums.com/v1/netpay/trade/h5-pay?' . $options;
header("Location:$url");
评论 (0)