//---------------价格(1代表1分钱,1块钱就*100)--------------- $total_fee = 1; //回调地址 $notify_url = 'http://www.baidu.com'; //dump($notify_url);exit; //使用统一支付接口,获取prepay_id $wxp = new WxPay($config['KEY']); $wxp->setParameter("openid", $openid); $wxp->setParameter("appid", $config['APPID']); $wxp->setParameter("mch_id", $config['MCHID']); $wxp->setParameter("notify_url", $notify_url); $wxp->setParameter("body", $body); $wxp->setParameter("out_trade_no", $out_trade_no); $wxp->setParameter("total_fee", $total_fee); $wxp->setParameter("trade_type", 'JSAPI'); $jsApiParameters = $wxp->getParameters(); //var_dump($jsApiParameters);die(); $html = array(); $html[] = '<script language="javascript">'; $html[] = "\tfunction jsApiCall(){"; //$html[] = " alert(JSON.stringify(".$jsApiParameters."));"; $html[] = "\t\tWeixinJSBridge.invoke("; $html[] = "\t\t\t'getBrandWCPayRequest',"; $html[] = $jsApiParameters . ","; $html[] = "\t\t\tfunction(res){"; //$html[] = " alert(res.err_msg);"; $html[] = "\t\t\t\tWeixinJSBridge.log(res.err_msg);"; //$html[] = " alert(res.err_code+res.err_desc+res.err_msg);"; $html[] = "\t\t\t\tif(res.err_msg == 'get_brand_wcpay_request:ok'){"; $html[] = "\t\t\t\t\tvar url = '" . $notify_url . "';"; $html[] = "\t\t\t\t\twindow.location.href=url;";
<?php //微信支付 header("Content-type: application/json; charset=utf-8"); header("Access-Control-Allow-Origin:*"); include_once "wx.pay.php"; $wxPay = new WxPay(); $getUrlParam = function ($key) { if (isset($_GET[$key])) { return $_GET[$key]; } elseif (isset($_POST[$key])) { return $_POST[$key]; } else { $errObj['code'] = -1; $errObj['msg'] = $key . '不存在'; $errObj['data'] = null; echo Util::getJsonString($errObj); exit; } }; $code = $getUrlParam('code'); $product_id = $getUrlParam('product_id'); $price = $getUrlParam('price'); $title = $getUrlParam('title'); $unifiedOrder["product_id"] = $product_id; $unifiedOrder["total_fee"] = $price; $unifiedOrder["body"] = $title; $wxPayArgsObj = $wxPay->getParameters($code, $unifiedOrder); echo Util::getJsonString($wxPayArgsObj);