**
* jsapi支付 只限于微信浏览器使用
*/
public function wxjspay(){
$notify_url = ""; //异步通知地址
$order_number = I('order_number'); //订单编号
$money = I('orderPrice'); //订单金额
//调用微信支付函数
Vendor('Wxpay.example.WxPay#JsApiPay');
Vendor('Wxpay.lib.WxPay#Api');
Vendor('Wxpay.lib.WxPay#Data');
Vendor('Wxpay.lib.WxPay#Config');
Vendor('Wxpay.lib.WxPay#Exception');
$notify = new \JsApiPay();
$openid = $notify->GetOpenid(); //获取openid 要配置微信公众平台,还要填写APPSECRET参数
$input = new \WxPayUnifiedOrder();
$input->SetBody('订单号:'.$order_number); //描述
$input->SetOut_trade_no($order_number); //订单号
$input->SetTotal_fee($money*100); //单位为分,只能传整数
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 60));
$input->SetNotify_url($notify_url);
$input->SetTrade_type("JSAPI");
$input->SetOpenid($openid);
$order = \WxPayApi::unifiedOrder($input);
if($order['err_code'] == 'INVALID_REQUEST'){
$this->error('该订单已过期,请重新下单');
}
$jsApiParameters = $notify->GetJsApiParameters($order);
$this->assign('jsApiParameters',$jsApiParameters); //将返回结果传到前台页面
$this->display();
}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>weixin</title>
<script type="text/javascript">
//调用微信JS api 支付
function jsApiCall()
{
WeixinJSBridge.invoke(
'getBrandWCPayRequest',
{$jsApiParameters}, //通过js调起微信支付
function(res){
WeixinJSBridge.log(res.err_msg);
alert(res.err_code+res.err_desc+res.err_msg);
}
);
}
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();
}
}
</script>
</head>
<body>
<div align="center">
<button type="button" οnclick="callpay()" >立即支付</button>
</div>
</body>
</html>