【微信接入网联支付】网联统一支付接口之微信支付

1、背景:2018年,第三方支付机构(支付宝、微信、百度钱包等)应国家要求,必须接入网联支付接口api

2、目的:以【微信jsapi】公众号支付为demo,讲解微信jsapi支付接入网联支付api,实现支付成功

3、代码:$record['uniontid']  自己填写

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;
    }

 

posted @ 2018-09-16 16:34  PHP急先锋  阅读(3717)  评论(0编辑  收藏  举报