# 代码示例(仅用于参考!) PHP 获取Openid案例 ~~~ <?php $param = [ 'appid'=>'123456', 'mchid'=>'123456', 'redirect_url'=>urlencode('http://baidu.com') ]; $key = '8BDF48C6519425'; $url = 'http://api.cmyzf.cn'; ksort($param); $sign = ''; foreach ($param as $k => $v) { $sign.=$k.'='.$v.'&'; } $sign = trim($sign,'&'); $sign = md5($sign.$key); $url = $url.'?appid='.$param['appid'].'&redirect_url='.$param['redirect_url'].'&mchid='.$param['mchid'].'&sign='.$sign; echo $url; ~~~ * * * PHP 拉起JsPay案例 ~~~ <?php $param = [ 'appid'=>'123456', 'name'=>'cs', 'type'=>'jsapi', 'money'=>'0.01', 'out_trade_no'=>'15732093209338', 'notify_url'=>'http://bai.com', 'mchid'=>'123456', 'openid'=>'通过Openid接口获取', ]; $key = '8BDF48C65144C7A309425'; $url = 'http://api.cmyzf.cn'; ksort($param); $sign = ''; foreach ($param as $k => $v) { $sign.=$k.'='.$v.'&'; } $sign = trim($sign,'&'); $param['sign'] = md5($sign.$key); $row_curl = curl_init(); curl_setopt($row_curl, CURLOPT_URL, $url); curl_setopt($row_curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($row_curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($row_curl, CURLOPT_CONNECTTIMEOUT , 30); curl_setopt($row_curl, CURLOPT_TIMEOUT, 30); curl_setopt($row_curl, CURLOPT_POST, 1); curl_setopt($row_curl, CURLOPT_POSTFIELDS, $param); curl_setopt($row_curl, CURLOPT_ENCODING, "gzip"); curl_setopt($row_curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($row_curl); curl_close($row_curl); $packge = json_decode($data,true)['data']['packge']; ?> <script> //调用微信JS api 支付 function jsApiCall() { WeixinJSBridge.invoke( 'getBrandWCPayRequest', <?php echo $packge;?>, function(res){ console.log('这里可写检测是否支付完成代码') } ); } function callpay() { if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener('WeixinJSBridgeReady', jsApiCall, false); }else if (document.attachEvent){ document.attachEvent('WeixinJSBridgeReady', jsApiCall); document.attachEvent('onWeixinJSBridgeReady', jsApiCall); } }else{ jsApiCall(); } } window.onload = callpay(); </script> ~~~ PHP 支付宝当面付(获取支付链接)案例 ~~~ <?php $param = [ 'appid'=>'123456', 'name'=>'cs', 'type'=>'alipay', 'money'=>'0.01', 'out_trade_no'=>'123456', 'notify_url'=>'http://bai.com', 'mchid'=>'123456', ]; $key = '123456'; $url = 'http://api.cmyzf.cn'; ksort($param); $sign = ''; foreach ($param as $k => $v) { $sign.=$k.'='.$v.'&'; } $sign = trim($sign,'&'); $param['sign'] = md5($sign.$key); $row_curl = curl_init(); curl_setopt($row_curl, CURLOPT_URL, $url); curl_setopt($row_curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($row_curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($row_curl, CURLOPT_CONNECTTIMEOUT , 30); curl_setopt($row_curl, CURLOPT_TIMEOUT, 30); curl_setopt($row_curl, CURLOPT_POST, 1); curl_setopt($row_curl, CURLOPT_POSTFIELDS, $param); curl_setopt($row_curl, CURLOPT_ENCODING, "gzip"); curl_setopt($row_curl, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($row_curl); curl_close($row_curl); $json = json_decode($data,true); if(isset($json['data']['code_url'])){ echo $json['data']['code_url']; // OK 支付链接 }else{ echo $json['msg']; // 失败 显示错误信息 } ~~~ PHP 支付宝当面付(收银台H5)案例 ,微信收银台同理 更改type参数为cashier即可 ~~~ <?php $param = [ 'appid'=>'123456', 'name'=>'cs', 'type'=>'alipay', 'money'=>'0.01', 'out_trade_no'=>'123456', 'notify_url'=>'http://bai.com', //收银台必须传入return_url参数 'return_url'=>'http://bai.com', 'mchid'=>'123456', ]; $key = '123456'; $url = 'http://api.cmyzf.cn'; ksort($param); $sign = ''; foreach ($param as $k => $v) { $sign.=$k.'='.$v.'&'; } $sign = trim($sign,'&'); $param['sign'] = md5($sign.$key); ?> <form id='alipaysubmit' name='alipaysubmit' method="post" action="<?php echo $url;?>"> <?php foreach ($param as $k => $v) { echo "<input type='hidden' name=\"".$k."\" value=\"".$v."\">"; } ?> <input type="submit" value="正在发起支付...."> </form> <script>document.forms['alipaysubmit'].submit();</script> ~~~ * * * ## **demo下载:[http://8rr.co/29AQ](http://8rr.co/29AQ)**