一、背景:2018年,第三方支付機構(支付寶、微信、百度錢包等)應國家要求,必須接入網聯支付接口apijavascript
二、目的:以【微信jsapi】公衆號支付爲demo,講解微信jsapi支付接入網聯支付api,實現支付成功html
三、代碼:$record['uniontid'] 本身填寫java
function doMobilelist3(){ $post_data['msgSrc']='WWW.***.COM'; $post_data['requestTimestamp']=date('Y-m-d H:i:s'); $post_data['mid']='8***'; $post_data['tid']='5****2'; $post_data['instMid']='Y***T'; $post_data['msgType']='WXPay.jsPay'; $post_data['msgSrcId']='*****'; $post_data['merOrderId']=$post_data['msgSrcId'].$record['uniontid']; $post_data['totalAmount']=$params['fee']*100; // $post_data['totalAmount']=1; $post_data['notifyUrl']=$_W['siteroot'].'app'.ltrim($this->createMobileUrl('notfiy'),'.'); $post_data['returnUrl']=$_W['siteroot'].'app'.ltrim($this->createMobileUrl('list'),'.'); $post_data['expireTime']=date('Y-m-d H:i:s',time()+3*60); $key='****'; $post_data['sign']=$this->makemd5($post_data,$key); $path='https://qr.chinaums.com/netpay-portal/webpay/pay.do'; $this->createform($post_data,$path,$charset='UTF-8','get'); }
/* * 銀聯支付建立簽名 */ private function makemd5($post_data,$key){ ksort($post_data); $sign= strtoupper(md5(urldecode(http_build_query($post_data)).$key)); return $sign; }
private function createform($data,$submitUrl,$charset='UTF-8',$method='POST'){ $inputstr = ""; foreach($data as $key=>$v){ $inputstr .= '<input type="hidden" id="'.$key.'" name="'.$key.'" value="'.$v.'"/>'; } $form = '<form action="'.$submitUrl.'" name="pay" id="pay" method="'.$method.'" accept-charset="'.$charset.'" onsubmit="document.charset=\''.$charset.'\';">'; $form.= $inputstr; $form.= '</form>'; $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>請不要關閉頁面,支付跳轉中.....</title> </head> <body>'; $html.= $form; $html.= '<script type="text/javascript"> document.getElementById("pay").submit(); </script>'; $html.= '</body> </html>'; print_r($html);exit; Mheader('utf-8'); echo $html; exit; }