public function test($order_id = '') { vendor('WxPayPubHelper.WxPayPubHelper'); //使用jsapi接口 $jsApi = new \JsApi_pub(); //=========步骤1:网页授权获取用户openid============ //通过code获得openid if (!isset($_GET['code'])) { //触发微信返回code码 $url = $jsApi->createOauthUrlForCode(\WxPayConf_pub::JS_API_CALL_URL . __SELF__); Header("Location: {$url}"); } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } $unifiedOrder = new \UnifiedOrder_pub(); $order_info = M('FxOrder')->find($order_id); $order_info['product_name'] = '中华聚宝分销商城'; $unifiedOrder->setParameter("openid", $openid); //商品描述 $unifiedOrder->setParameter("body", '中华聚宝分销商城共消费¥' . $order_info['price']); //商品描述 //自定义订单号,此处仅作举例 $timeStamp = time(); $out_trade_no = \WxPayConf_pub::APPID . $timeStamp; $unifiedOrder->setParameter("out_trade_no", $order_id . '_' . mt_rand(100, 999)); //商户订单号 if ($openid == 'olEDawig2ZbRO2v2zBNoyxXB32SE' || $openid == 'olEDawtGeisOHSSa539SCY68xqNc') { $unifiedOrder->setParameter("total_fee", $order_info['price']); //总金额 } else { $unifiedOrder->setParameter("total_fee", $order_info['price'] * 100); //总金额 } $unifiedOrder->setParameter("notify_url", \WxPayConf_pub::NOTIFY_URL_FX); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 //非必填参数,商户可根据实际情况选填 // $unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号 // $unifiedOrder->setParameter("device_info","XXXX");//设备号 // $unifiedOrder->setParameter("attach","附加数据");//附加数据 // $unifiedOrder->setParameter("time_start","交易起始时间");//交易起始时间 // $unifiedOrder->setParameter("time_expire","交易结束时间");//交易结束时间 // $unifiedOrder->setParameter("goods_tag","商品标记");//商品标记 $unifiedOrder->setParameter("product_id", $order_id); //商品ID $prepay_id = $unifiedOrder->getPrepayId(); // print_r($unifiedOrder); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); $this->assign('jsApiParameters', $jsApiParameters); $this->assign('order_id', $order_id); $this->display(); }
public function config($config = null) { if (empty($_SERVER['HTTP_USER_AGENT']) || strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === false && strpos($_SERVER['HTTP_USER_AGENT'], 'Windows Phone') === false) { header('Location: ' . WEB_PATH . '/pay/wxpay_web_url/payinfo/nowechat'); die; } include_once dirname(__FILE__) . "/wxpay/WxPayPubHelper.php"; if (empty($config['pay_type_data'])) { $this->db = System::load_sys_class('model'); $pay = $this->db->GetOne("SELECT * from `@#_pay` where `pay_class` = 'wxpay_web'"); $config['pay_type_data'] = unserialize($pay['pay_key']); } WxPayConf_pub::$APPID = $config['pay_type_data']['APPID']['val']; WxPayConf_pub::$MCHID = $config['pay_type_data']['MCHID']['val']; WxPayConf_pub::$KEY = $config['pay_type_data']['KEY']['val']; WxPayConf_pub::$APPSECRET = $config['pay_type_data']['APPSECRET']['val']; $jsApi = new JsApi_pub(); if (!isset($_GET['code'])) { $url = G_WEB_PATH . '/index.php/pay/wxpay_web_url/?money=' . $config['money'] . '&out_trade_no=' . $config['code']; $url = $jsApi->createOauthUrlForCode(urlencode($url)); header("Location: {$url}"); die; } else { $jsApi->setCode($_GET['code']); $openid = $jsApi->getOpenId(); } // var_dump($_GET); // echo $openid;die; WxPayConf_pub::$SSLCERT_PATH = dirname(__FILE__) . '/cacert/apiclient_cert.pem'; WxPayConf_pub::$SSLKEY_PATH = dirname(__FILE__) . '/cacert/apiclient_key.pem'; //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new UnifiedOrder_pub(); //设置统一支付接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 $unifiedOrder->setParameter("openid", $openid); $unifiedOrder->setParameter("body", "购买商品"); //商品描述 $unifiedOrder->setParameter("out_trade_no", $config['code']); //商户订单号 $unifiedOrder->setParameter("total_fee", $config['money'] * 100); //总金额 $unifiedOrder->setParameter("notify_url", $config['NotifyUrl']); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); include 'wxpay_web.html.php'; }
public function index() { $this->isUserLogin(); vendor('Weixinpay.WxPayPubHelper'); //使用jsapi接口 $jsApi = new \JsApi_pub(); //=========步骤1:网页授权获取用户openid============ //通过code获得openid $code = $_GET['code']; $jsApi->setCode($code); $openid = session('WST_USER')['wxId']; $pkey = session('WST_USER')["userId"] . "@" . $_SESSION["orderIds"]; $time = time(); $res = array('order_sn' => $time, 'order_amount' => $_SESSION['needPay']); //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new \UnifiedOrder_pub(); $total_fee = $res['order_amount'] * 100; //$total_fee = 1; $body = "订单支付{$res['order_sn']}"; $unifiedOrder->setParameter("openid", "{$openid}"); //用户标识 $unifiedOrder->setParameter("body", $body); //商品描述 //自定义订单号,此处仅作举例 $out_trade_no = $res['order_sn']; $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}"); //商户订单号 $unifiedOrder->setParameter("total_fee", $total_fee); //总金额 $unifiedOrder->setParameter("attach", "{$pkey}"); //附加数据 $unifiedOrder->setParameter("notify_url", C('WxPayConf_pub.NOTIFY_URL')); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 $unifiedOrder->SetParameter("input_charset", "UTF-8"); //非必填参数,商户可根据实际情况选填 $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); $wxconf = json_decode($jsApiParameters, true); if ($wxconf['package'] == 'prepay_id=') { $this->error('当前订单存在异常,不能使用支付'); } $this->assign('res', $res); $this->assign('jsApiParameters', $jsApiParameters); $this->display('default/payment/wxjsapi/wxpay'); }
function get_payform($order_info) { if (!defined('WXAPPID')) { $_SESSION['order_info'] = $order_info; define("WXAPPID", $this->_config['appid']); define("WXMCHID", $this->_config['mchid']); define("WXKEY", $this->_config['key']); define("WXAPPSECRET", $this->_config['appsecret']); define("WXCURL_TIMEOUT", 30); define('WXNOTIFY_URL', $this->_create_notify_url($order_info["order_id"], $order_info['payment_code'])); define('WXJS_API_CALL_URL', $this->_create_notify_url($order_info["order_id"], $order_info['payment_code'])); define('WXSSLCERT_PATH', ROOT_PATH . '/data/cacert/1/apiclient_cert.pem'); define('WXSSLKEY_PATH', ROOT_PATH . '/data/cacert/1/apiclient_key.pem'); } require_once dirname(__FILE__) . "/WxPayPubHelper/WxPayPubHelper.php"; $unifiedOrder = new UnifiedOrder_pub(); $jsApi = new JsApi_pub(); if (!isset($_GET['code'])) { $baseUrl = urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']); //触发微信返回code码 $urll = $jsApi->createOauthUrlForCode($baseUrl); //echo $url; Header("Location: {$urll}"); } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenid(); } $out_trade_no = $this->_get_trade_sn($order_info); $_SESSION['out_trade_on'] = $out_trade_no; $unifiedOrder->setParameter("body", $out_trade_no); //商品描述 $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}"); //商户订单号 $unifiedOrder->setParameter("attach", $order_info['order_id']); //商户支付日志 $unifiedOrder->setParameter("total_fee", strval(intval($order_info['order_amount'] * 100))); //总金额 $unifiedOrder->setParameter("notify_url", WXNOTIFY_URL); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 $unifiedOrder->setParameter("openid", $openid); $jsApi->prepay_id = $unifiedOrder->getPrepayId(); $unifiedOrderResult = $jsApi->getParameters(); return $unifiedOrderResult; }
public static function getOpenID(array $data) { //使用jsapi接口 $jsApi = new JsApi_pub(); //=========步骤1:网页授权获取用户openid============ //通过code获得openid if (!isset($data['code'])) { //触发微信返回code码 $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL); Header("Location: {$url}"); } else { //获取code码,以获取openid $code = $data['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); return $openid; } }
/** * 生成支付代码 * @param array $order 订单信息 * @param array $payment 支付方式信息 */ function get_code($order, $payment) { $return_url = 'http://' . $_SERVER['HTTP_HOST'] . '/respond.php'; define(APPID, $payment['appId']); // appid define(APPSECRET, $payment['appSecret']); // appSecret define(MCHID, $payment['partnerId']); define(KEY, $payment['partnerKey']); // 通加密串 define(NOTIFY_URL, $return_url); // 成功回调url include_once "weixin/WxPayPubHelper.php"; $selfUrl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']; if (!strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) { return $this->natpayHtml($order); } $jsApi = new JsApi_pub(); if ($_SESSION['user_id']) { $openid = $GLOBALS['db']->getOne("select fake_id from " . $GLOBALS['ecs']->table('weixin_user') . " where ecuid='{$_SESSION['user_id']}'"); } $openid = $openid ? $openid : $_SESSION['wx_openid']; if (!$openid) { if (!isset($_GET['code'])) { // 触发微信返回code码 $url = $jsApi->createOauthUrlForCode($selfUrl); Header("Location: {$url}"); exit; } else { // 获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); $_SESSION['wx_openid'] = $openid; } } $unifiedOrder = new UnifiedOrder_pub(); // 设置统一支付接口参数 $unifiedOrder->setParameter("openid", $openid); $unifiedOrder->setParameter("body", $order['order_sn']); $unifiedOrder->setParameter("out_trade_no", $order['order_id']); // 商户订单号 $unifiedOrder->setParameter("total_fee", $order['order_amount'] * 100); // 总金额 $unifiedOrder->setParameter("notify_url", NOTIFY_URL); // 通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); // 交易类型 $prepay_id = $unifiedOrder->getPrepayId(); $jsApi->setPrepayId($prepay_id); return $jsApi->getParameters(); }
public function member_recharge_pay() { //$cardcode = str_pad(mt_rand(0, 99999999), 8, '0', STR_PAD_RIGHT); /** * JS_API支付demo * ==================================================== * 在微信浏览器里面打开H5网页中执行JS调起支付。接口输入输出数据格式为JSON。 * 成功调起支付需要三个步骤: * 步骤1:网页授权获取用户openid * 步骤2:使用统一支付接口,获取prepay_id * 步骤3:使用jsapi调起支付 */ //include_once("../WxPayPubHelper/WxPayPubHelper.php"); //include_once("../WxPayPubHelper/WxPayPubHelper.php"); import('@.ORG.wxpay.WxPayPubHelper.WxPayPubHelper'); //使用jsapi接口 $jsApi = new JsApi_pub(); //=========步骤1:网页授权获取用户openid============ //通过code获得openid if (!isset($_GET['code'])) { //触发微信返回code码 $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL_RECHARGE); Header("Location: {$url}"); } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new UnifiedOrder_pub(); //取出当前订单的充值信息 $user_recharge = M("user_recharge"); $result = $user_recharge->where('order_recharge_sn = "' . $_SESSION['order_recharge_sn'] . '"')->find(); $charge_remark = "充值:" . int($result['amount']); $unifiedOrder->setParameter("openid", "{$openid}"); //openid $unifiedOrder->setParameter("body", $charge_remark); //商品描述 //自定义订单号,此处仅作举例 $timeStamp = time(); $out_trade_no = WxPayConf_pub::APPID . "{$timeStamp}"; $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}"); //商户订单号 $unifiedOrder->setParameter("total_fee", 0.1 * 100); //总金额 $unifiedOrder->setParameter("notify_url", WxPayConf_pub::NOTIFY_URL_RECHARGE . "/order_recharge_sn/{$_SESSION['order_recharge_sn']}"); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); $this->assign('jsApiParameters', $jsApiParameters); $this->display(); }
public function pay() { //使用jsapi接口 $jsApi = new \JsApi_pub(); //=========步骤1:网页授权获取用户openid============ //通过code获得openid if (!isset($_GET['code'])) { //触发微信返回code码 $url = $jsApi->createOauthUrlForCode(C('WxPayConf_pub.JS_API_CALL_URL')); Header("Location: {$url}"); } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } if (!session('user_info')) { header("Location: http://www.1qjx.com/"); } ini_set('date.timezone', 'Asia/Shanghai'); $order_id = session('order_id'); //$order_id=$_SESSION['order_id']; //var_dump($order_id); //exit; header("Content-Type:text/html;Charset=utf-8"); $order = M("order"); // 实例化User对象 $order_info = $order->where("id = {$order_id}")->select(); if ($order_info[0]['is_paid'] == 1) { echo "<script>alert('该订单已支付,请勿重复支付!');window.location.href='http://www.1qjx.com/';</script>"; exit; } $order_info = $order->where("id = {$order_id}")->find(); /* var_dump($order_info); exit; */ $goods_id = $order_info['goods_id']; $number = $order_info['number']; $Goods = M("Goods"); // 实例化User对象 // 获取ID为 $_REQUEST['id'] 的用户的昵称 /* var_dump($goods_id); exit; */ $goods_info = $Goods->where("id={$goods_id}")->find(); $goods_info['buy_number'] = $number; $goods_info['total_money'] = $goods_info['unit_price'] * $goods_info['buy_number']; $goods_info['remainder'] = $goods_info['number'] - $goods_info['pay_number']; if ($goods_info['remainder'] <= 0) { $this->error('您选择的商品已经达到指定购买人次,您已无法购买!'); } elseif ($number > $goods_info['remainder']) { $this->error('您选择的商品购买人次超过商品剩余人次,请重新选择!'); } $money = round($order_info['money'], 2); $db_money = $money; $money = $money * 100; $notice_sn = $order_info['notice_sn']; //var_dump($notice_sn); //exit; //var_dump($order_info); //exit; $Goods = M("Goods"); // 实例化User对象 // 查找status值为1的用户数据 以创建时间排序 返回10条数据 $goods_info = $Goods->where("id = {$goods_id}")->select(); $goods_name = $goods_info['name']; //$notify_url = "http://www.1qjx.com/index.php/Home/Pay/pay_result/order_id/$order_id"; //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new \UnifiedOrder_pub(); //设置统一支付接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 $unifiedOrder->setParameter("openid", $openid); //商品描述 $unifiedOrder->setParameter("body", "夺宝{$goods_name}"); //商品描述 $unifiedOrder->setParameter("out_trade_no", $notice_sn); //商户订单号 $unifiedOrder->setParameter("total_fee", "{$money}"); //总金额 $unifiedOrder->setParameter("notify_url", C('WxPayConf_pub.NOTIFY_URL')); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 //非必填参数,商户可根据实际情况选填 //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号 //$unifiedOrder->setParameter("device_info","XXXX");//设备号 //$unifiedOrder->setParameter("attach","XXXX");//附加数据 //$unifiedOrder->setParameter("time_start","date("YmdHis")");//交易起始时间 //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间 $unifiedOrder->setParameter("goods_tag", "夺宝系列商品"); //商品标记 //$unifiedOrder->setParameter("openid","XXXX");//用户标识 //$unifiedOrder->setParameter("product_id","XXXX");//商品ID $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); $this->assign('jsApiParameters', $jsApiParameters); $this->assign('db_money', $db_money); $this->display(); //echo $jsApiParameters; }
function get_code($order, $payment) { $jsApi = new JsApi_pub(); if (!isset($_GET['code'])) { $redirect = urlencode($GLOBALS['ecs']->url() . 'flow.php?step=ok&order_id=' . $order['order_sn']); $url = $jsApi->createOauthUrlForCode($redirect); Header("Location: {$url}"); } else { $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } if ($openid) { $unifiedOrder = new UnifiedOrder_pub(); $unifiedOrder->setParameter("openid", "{$openid}"); //商品描述 $unifiedOrder->setParameter("body", $order['order_sn']); //商品描述 $out_trade_no = $order['order_sn']; $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}"); //商户订单号 $unifiedOrder->setParameter("attach", strval($order['log_id'])); //商户支付日志 $unifiedOrder->setParameter("total_fee", strval(intval($order['order_amount'] * 100))); //总金额 $unifiedOrder->setParameter("notify_url", WXNOTIFY_URL); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 $prepay_id = $unifiedOrder->getPrepayId(); $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); $user_agent = $_SERVER['HTTP_USER_AGENT']; $allow_use_wxPay = true; if (strpos($user_agent, 'MicroMessenger') === false) { $allow_use_wxPay = false; } else { preg_match('/.*?(MicroMessenger\\/([0-9.]+))\\s*/', $user_agent, $matches); if ($matches[2] < 5.0) { $allow_use_wxPay = false; } } $html .= '<script language="javascript">'; if ($allow_use_wxPay) { $html .= "function jsApiCall(){"; $html .= "WeixinJSBridge.invoke("; $html .= "'getBrandWCPayRequest',"; $html .= $jsApiParameters . ","; $html .= "function(res){"; $html .= "if(res.err_msg == 'get_brand_wcpay_request:ok'){window.location.href='" . $GLOBALS['ecs']->url() . "respond.php'}"; //$html .= "WeixinJSBridge.log(res.err_msg);"; $html .= "}"; $html .= ");"; $html .= "}"; $html .= "function callpay(){"; $html .= 'if (typeof WeixinJSBridge == "undefined"){'; $html .= "if( document.addEventListener ){"; $html .= "document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);"; $html .= "}else if (document.attachEvent){"; $html .= "document.attachEvent('WeixinJSBridgeReady', jsApiCall); "; $html .= "document.attachEvent('onWeixinJSBridgeReady', jsApiCall);"; $html .= "}"; $html .= "}else{"; $html .= "jsApiCall();"; $html .= "}}"; } else { $html .= 'function callpay(){'; $html .= 'alert("您的微信不支持支付功能,请更新您的微信版本")'; $html .= "}"; } $html .= '</script>'; $html .= '<button class="c-btn4" type="button" onclick="callpay()">微信支付</button>'; return $html; } else { $html .= '<script language="javascript">'; $html .= 'function callpay(){'; $html .= 'alert("请在微信中使用微信支付")'; $html .= "}"; $html .= '</script>'; $html .= '<button type="button" onclick="callpay()" class="pay_bottom">微信支付</button>'; return $html; } }
public function setbalance() { //登录验证 $this->checkSessionUser(); $this->layout = 'default_full'; //引入模版 $this->pageTitle = $this->ld['user_deposit'] . ' - ' . $this->configs['shop_title']; Configure::write('debug', 0); $this->loadModel('PaymentApiLog'); if (!empty($_GET['code']) && !empty($_GET['other_data'])) { $other_data_str = $_GET['other_data']; $other_data_arr = explode("_", $other_data_str); $payment_api_id = isset($other_data_arr[2]) ? $other_data_arr[2] : 0; $payment_log_info = $this->PaymentApiLog->find('first', array('conditions' => array('PaymentApiLog.id' => $payment_api_id))); $this->data['pay']['money'] = isset($other_data_arr[1]) ? $other_data_arr[1] : 0; $this->data['pay']['payment_type'] = isset($other_data_arr[0]) ? $other_data_arr[0] : 0; } if ($this->RequestHandler->isPost() || isset($this->data['pay'])) { if (isset($this->data)) { $this->data = $this->clean_xss($this->data); } $pay_url = ''; $message = '操作失败'; $code = '0'; if (isset($this->data['pay']) && !empty($this->data['pay'])) { $this->data['pay']['payment_type'] = intval($this->data['pay']['payment_type']); $this->data['pay']['money'] = floatval($this->data['pay']['money']); $payment = $this->Payment->find('first', array('conditions' => array('Payment.id' => $this->data['pay']['payment_type'], 'Payment.status' => '1'))); if (isset($payment) && !empty($payment)) { //用户Id $user_id = $_SESSION['User']['User']['id']; //获取用户信息 $user_info = $this->User->find('first', array('conditions' => array('User.id' => $user_id))); //定义路径 $host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''); $this->set('payment_code', $payment['Payment']['code']); if ($payment['Payment']['code'] == 'weixinpay') { $payment_amount = $this->data['pay']['money']; $amount_money = $payment_amount; //在线支付增加api日志 $payment_api_log = array('id' => isset($payment_log_info['PaymentApiLog']['id']) ? $payment_log_info['PaymentApiLog']['id'] : 0, 'payment_code' => $payment['Payment']['code'], 'type' => 2, 'type_id' => $user_id, 'order_currency' => 'CHY', 'amount' => $payment_amount); $this->PaymentApiLog->save($payment_api_log); $payment_api_log['id'] = $this->PaymentApiLog->id; $payment_config = unserialize($payment['Payment']['config']); $amt = $amount_money * 100; try { $wechatpay_type = false; if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) { App::import('Vendor', 'Weixinpay', array('file' => 'WxPayPubHelper.php')); $jsApi = new JsApi_pub($payment_config['APPID'], $payment_config['MCHID'], $payment_config['KEY'], $payment_config['APPSECRET']); if (empty($_GET['code'])) { $request_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $other_data = $this->data['pay']['payment_type'] . "_" . $this->data['pay']['money'] . "_" . $payment_api_log['id']; $request_url .= "?other_data=" . $other_data; //触发微信返回code码 $wechat_pay_url = $jsApi->createOauthUrlForCode($request_url); Header("Location: {$wechat_pay_url}"); } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } if (!empty($openid)) { $unifiedOrder = new UnifiedOrder_pub($payment_config['APPID'], $payment_config['MCHID'], $payment_config['KEY'], $payment_config['APPSECRET']); $unifiedOrder->setParameter("openid", "{$openid}"); //商品描述 $unifiedOrder->setParameter("body", "用户充值[金额:" . $payment_amount . "]"); //商品描述 //自定义订单号,此处仅作举例 $timeStamp = time(); $out_trade_no = $payment_api_log['id']; $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}"); //商户订单号 $unifiedOrder->setParameter("total_fee", $amt); //总金额 $unifiedOrder->setParameter("notify_url", 'http://' . $host . $this->webroot . 'responds/weixin_balance'); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 $prepay_id = $unifiedOrder->getPrepayId(); $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); if (!empty($jsApiParameters)) { $json_result = json_decode($jsApiParameters); $code_url = isset($json_result->paySign) ? $jsApiParameters : ''; } } else { throw new SDKRuntimeException("支付失败,OpenId 获取失败"); } } else { Configure::write('debug', 0); $this->layout = 'ajax'; $wechatpay_type = true; App::import('Vendor', 'Weixinpay', array('file' => 'WxPay.Api.php')); App::import('Vendor', 'Phpqcode', array('file' => 'phpqrcode.php')); $input = new WxPayUnifiedOrder(); $input->SetKey($payment_config['KEY']); $input->SetBody("用户充值[金额:" . $payment_amount . "]"); $input->SetAttach("用户充值"); $input->SetOut_trade_no($payment_api_log['id'] . "_" . time() . "_" . rand(0, 1000)); $input->SetAppid($payment_config['APPID']); $input->SetMch_id($payment_config['MCHID']); $input->SetTotal_fee($amt); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag("用户充值"); $input->SetNotify_url('http://' . $host . $this->webroot . 'responds/weixin_balance'); $input->SetProduct_id($payment_api_log['id']); $input->SetTrade_type("NATIVE"); $notify = new NativePay(); $result = $notify->GetPayUrl($input); $code_url = isset($result["code_url"]) ? $result["code_url"] : ''; } $this->set('wechatpay_type', $wechatpay_type); $message = ''; $code = '1'; } catch (Exception $e) { $message = '支付失败,Caught exception: ' . $e->getMessage(); $code = '0'; } } else { //判断支付方式是否存在 $payment['Payment']['code'] = strtolower($payment['Payment']['code']); try { $payment_config = unserialize($payment['Payment']['config']); App::import('Vendor', 'payments/' . $payment['Payment']['code']); $balance_payment = new $payment['Payment']['code'](); if ($payment['Payment']['is_online'] == 1) { //在线支付增加api日志 $payment_api_log = array('payment_code' => $payment['Payment']['code'], 'type' => 2, 'type_id' => $user_id, 'order_currency' => 'CHY', 'amount' => $this->data['pay']['money']); $this->PaymentApiLog->save($payment_api_log); //记录支付日志Id $payment_api_log['id'] = $this->PaymentApiLog->id; } $payment_api_log['name'] = $user_info['User']['name']; $payment_api_log['payerAdderss'] = $user_info['User']['address_id']; $payment_api_log['payerName'] = $user_info['User']['name']; $payment_api_log['created'] = date('Y-m-d H:i:s', time()); $payment_config['cancel_return'] = 'http://' . $host . $this->webroot; $payment_config['return_url'] = 'http://' . $host . $this->webroot . 'responds/return_code/' . $payment['Payment']['code']; //描述 $payment_api_log['subject'] = '[' . $user_info['User']['name'] . ']用户充值'; $payment_api_log['host'] = $host; if ($payment['Payment']['code'] == 'money' || $payment['Payment']['code'] == 'bank_trans' || $payment['Payment']['code'] == 'pos_pay') { $payment_config['co'] = ''; } $api_code = $balance_payment->go2($payment_api_log, $payment_config); $_SESSION['api_code'] = $api_code; $message = ''; $code = '1'; } catch (Exception $e) { $message = '支付失败,Caught exception: ' . $e->getMessage(); $code = '0'; } } } else { $message = '该支付方式无效或不可用!'; $code = '0'; } } if (isset($api_code)) { $this->layout = null; $result['pay_url'] = isset($api_code) ? $api_code : $pay_url; $this->set('pay_url', $api_code); } else { if (isset($code_url) && $code_url != "") { $this->set('pay_url', $code_url); $this->set('payment_api_id', $payment_api_log['id']); } else { //跳转到提示页 $this->flash($message, '/users/deposit', ''); } } } else { $this->redirect('/users/deposit'); } }
public function get_payment_code($payment_notice_id) { $payment_notice = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment_notice where id = " . $payment_notice_id); $order_info = $GLOBALS['db']->getRow("select deal_ids from " . DB_PREFIX . "deal_order where id = " . $payment_notice['order_id']); $order_sn = $payment_notice['notice_sn']; $money = round($payment_notice['money'], 2); $payment_info = $GLOBALS['db']->getRow("select id,config,logo from " . DB_PREFIX . "payment where id=" . intval($payment_notice['payment_id'])); $payment_info['config'] = unserialize($payment_info['config']); $wx_config = $payment_info['config']; $sql = "select name from " . DB_PREFIX . "deal where id =" . intval($order_info['deal_ids']); $title_name = $GLOBALS['db']->getOne($sql); $subject = $order_sn; include APP_ROOT_PATH . "system/payment/Wxjspay/WxPayPubHelper.php"; $notify_url = get_domain() . APP_ROOT . "/wxpay_web/notify_url.php?order_id=" . intval($payment_notice['order_id']) . "&out_trade_no=" . $order_sn; //."&out_trade_no={$data.walipay.out_trade_no}"; $notify_url = str_replace("/sjmapi", "", $notify_url); $notify_url = str_replace("/mapi", "", $notify_url); $order_id = $order_sn; //网页支付的订单在订单有效期内可以进行多次支付请求,但是需要注意的是每次请求的业务参数都要一致,交易时间也要保持一致。否则会报错“订单与已存在的订单信息不符” $data_return_url = get_domain() . APP_ROOT . "/wap/index.php?ctl=pay_order&order_id=" . intval($payment_notice['order_id']); //$return['notify_url']=$notify_url; $data_return_url = str_replace("/sjmapi", "", $data_return_url); $data_return_url = str_replace("/mapi", "", $data_return_url); $return['notify_url'] = $data_return_url; $return['is_wap'] = 1; $return['is_wap_url'] = 0; $return['show_pay_wxbtn'] = 1; $return['pay_code'] = 'Wwxjspay'; $return['body'] = $title_name; $return['total_fee'] = $money; $return['total_fee_format'] = format_price($money); $return['out_trade_no'] = $payment_notice['notice_sn']; $money_fen = intval($money * 100); if ($wx_config['type'] == 'V2') { require_once APP_ROOT_PATH . 'system/extend/ip.php'; $iplocation = new iplocate(); $user_ip = $iplocation->getIP(); $unifiedOrder = new UnifiedOrder_pub(); $unifiedOrder->update_config($wx_config['appid'], $wx_config['appsecret'], $wx_config['mchid'], $wx_config['partnerid'], $wx_config['partnerkey'], $wx_config['key'], $wx_config['sslcert'], $wx_config['sslkey']); $unifiedOrder->setParameter("input_charset", "GBK"); $unifiedOrder->setParameter("bank_type", "WX"); $unifiedOrder->setParameter("body", $title_name); $unifiedOrder->setParameter("partner", $wx_config['partnerid']); //$unifiedOrder->setParameter("out_trade_no", $unifiedOrder->create_noncestr()); $unifiedOrder->setParameter("out_trade_no", $order_sn); $unifiedOrder->setParameter("total_fee", "{$money_fen}"); $unifiedOrder->setParameter("fee_type", "0"); $unifiedOrder->setParameter("notify_url", $notify_url); $unifiedOrder->setParameter("spbill_create_ip", $user_ip); $unifiedOrder->setParameter("input_charset", "GBK"); $jsApiParameters = $unifiedOrder->create_biz_package(); } elseif ($wx_config['type'] == 'V3') { $jsApi = new JsApi_pub(); $jsApi->update_config($wx_config['appid'], $wx_config['appsecret'], $wx_config['mchid'], $wx_config['partnerid'], $wx_config['partnerkey'], $wx_config['key'], $wx_config['sslcert'], $wx_config['sslkey']); if (!isset($_REQUEST['code'])) { //触发微信返回code码 $url = $jsApi->createOauthUrlForCode(urlencode($return['notify_url'])); //header("Location:".$url); $return['is_wap_url'] = 1; $return['wap_notify_url'] = $url; return $return; } else { //获取code码,以获取openid $code = $_REQUEST['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } $unifiedOrder = new UnifiedOrder_pub(); $unifiedOrder->update_config($wx_config['appid'], $wx_config['appsecret'], $wx_config['mchid'], $wx_config['partnerid'], $wx_config['partnerkey'], $wx_config['key'], $wx_config['sslcert'], $wx_config['sslkey']); $unifiedOrder->setParameter("openid", "{$openid}"); //商品描述 $unifiedOrder->setParameter("body", substr($title_name, 0, 50)); //商品描述 $timeStamp = NOW_TIME; $unifiedOrder->setParameter("out_trade_no", "{$order_sn}"); //商户订单号 $unifiedOrder->setParameter("total_fee", $money_fen); //总金额 $unifiedOrder->setParameter("notify_url", $notify_url); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); //file_put_contents(APP_ROOT_PATH."/sjmapi/log/log_xml_1.txt",print_r($prepay_id,1)); $jsApiParameters = $jsApi->getParameters(); //$deal_url=get_domain().APP_ROOT."/wap/index.php"; //$deal_url = str_replace("/sjmapi", "", $deal_url); //$deal_url = str_replace("/mapi", "", $deal_url); //$jsApiParameters=str_replace('deal_url',$deal_url,$jsApiParameters); } $return['parameters'] = $jsApiParameters; //echo $jsApiParameters; return $return; }
public function get_payment_code($payment_notice_id) { $payment_notice = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "payment_notice where id = " . $payment_notice_id); $order_sn = $payment_notice['notice_sn']; $money = round($payment_notice['money'], 2); $payment_info = $GLOBALS['db']->getRow("select id,config,logo from " . DB_PREFIX . "payment where id=" . intval($payment_notice['payment_id'])); $payment_info['config'] = unserialize($payment_info['config']); $wx_config = $payment_info['config']; $sql = "select name " . "from " . DB_PREFIX . "deal " . "where id =" . intval($payment_notice['deal_id']); $title_name = $GLOBALS['db']->getOne($sql); if (!$payment_notice['order_id']) { $title_name = '充值'; } $subject = $order_sn; include APP_ROOT_PATH . "system/payment/Wxjspay/WxPayPubHelper.php"; // $data_notify_url = get_domain().APP_ROOT.'/wx_web/yjwap_response.php'; // $data_return_url = get_domain().APP_ROOT.'/wx_web/yjwap_notify.php'; // // $data_notify_url = str_replace("/sjmapi", "", $data_notify_url); // $data_notify_url = str_replace("/mapi", "", $data_notify_url); // $data_notify_url = str_replace("/wap", "", $data_notify_url); $data_return_url = str_replace("/sjmapi", "", $data_return_url); $data_return_url = str_replace("/mapi", "", $data_return_url); $data_return_url = str_replace("/wap", "", $data_return_url); $notify_url = get_domain() . REAL_APP_ROOT . "/wxpay_web/notify_url.php?order_id=" . intval($payment_notice['order_id']) . "&out_trade_no=" . $order_sn; //."&out_trade_no={$data.walipay.out_trade_no}"; $order_id = $order_sn; //网页支付的订单在订单有效期内可以进行多次支付请求,但是需要注意的是每次请求的业务参数都要一致,交易时间也要保持一致。否则会报错“订单与已存在的订单信息不符” $return['notify_url'] = url_wap("cart#wx_jspay", array("id" => $payment_notice_id)); $money_fen = intval($money * 100); if ($wx_config['type'] == 'V2') { require_once APP_ROOT_PATH . 'system/extend/ip.php'; $iplocation = new iplocate(); $user_ip = $iplocation->getIP(); $unifiedOrder = new UnifiedOrder_pub(); $unifiedOrder->update_config($wx_config['appid'], $wx_config['appsecret'], $wx_config['mchid'], $wx_config['partnerid'], $wx_config['partnerkey'], $wx_config['key'], $wx_config['sslcert'], $wx_config['sslkey']); $unifiedOrder->setParameter("input_charset", "GBK"); $unifiedOrder->setParameter("bank_type", "WX"); $unifiedOrder->setParameter("body", $title_name); $unifiedOrder->setParameter("partner", $wx_config['partnerid']); //$unifiedOrder->setParameter("out_trade_no", $unifiedOrder->create_noncestr()); $unifiedOrder->setParameter("out_trade_no", $order_sn); $unifiedOrder->setParameter("total_fee", "{$money_fen}"); $unifiedOrder->setParameter("fee_type", "0"); $unifiedOrder->setParameter("notify_url", $notify_url); $unifiedOrder->setParameter("spbill_create_ip", $user_ip); $unifiedOrder->setParameter("input_charset", "GBK"); $jsApiParameters = $unifiedOrder->create_biz_package(); } elseif ($wx_config['type'] == 'V3' || $wx_config['type'] == 'V4') { $jsApi = new JsApi_pub(); $jsApi->update_config($wx_config['appid'], $wx_config['appsecret'], $wx_config['mchid'], $wx_config['partnerid'], $wx_config['partnerkey'], $wx_config['key'], $wx_config['sslcert'], $wx_config['sslkey']); if (!isset($_GET['code'])) { //触发微信返回code码 $url = $jsApi->createOauthUrlForCode(urlencode(get_domain() . $return['notify_url'])); Header("Location: {$url}"); $return['notify_url'] = $url; return $return; } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } $unifiedOrder = new UnifiedOrder_pub(); $unifiedOrder->update_config($wx_config['appid'], $wx_config['appsecret'], $wx_config['mchid'], $wx_config['partnerid'], $wx_config['partnerkey'], $wx_config['key'], $wx_config['sslcert'], $wx_config['sslkey']); $unifiedOrder->setParameter("openid", "{$openid}"); //商品描述 $unifiedOrder->setParameter("body", iconv_substr($title_name, 0, 50, 'UTF-8')); //商品描述 $timeStamp = NOW_TIME; $unifiedOrder->setParameter("out_trade_no", "{$order_sn}"); //商户订单号 $unifiedOrder->setParameter("total_fee", $money_fen); //总金额 $unifiedOrder->setParameter("notify_url", $notify_url); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters($wx_config['type']); if ($wx_config['type'] == 'V4') { $jsApiParameters = str_replace('deal_url', url_wap("deal#index", array('id' => $payment_notice['deal_id'])), $jsApiParameters); } } $return['parameters'] = $jsApiParameters; //echo $jsApiParameters; return $return; }
$_SESSION['out_trade_no'] = $_GET['order_sn']; $_SESSION['goods_name'] = $_GET['goods_name']; $_SESSION['order_amount'] = $_GET['order_amount']; } //使用jsapi接口 $jsApi = new JsApi_pub(); //=========步骤1:网页授权获取用户openid============ //通过code获得openid if (!isset($_GET['code'])) { //触发微信返回code码 $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL); Header("Location: {$url}"); } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new UnifiedOrder_pub(); //设置统一支付接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 //ECHO $_SESSION['out_trade_no']."=====>dd";EXIT; $out_trade_no = $_SESSION['out_trade_no']; $goods_name = $_SESSION['goods_name'];
public function wxpay() { $order_sn = $this->_get('order_sn'); $token = $this->token; $wecha_id = $this->wechat_id; //$redirect_url = $this->generateUrl('Shop/orderDetail', array('oid'=>$order_sn)); //$redirect_url = WapAction::generatePayResultUrl('Shop/my', $token, array('token'=> $token, 'branch_id'=>$this->branch_id,'wecha_id'=>$wecha_id)); //$redirect_url = urldecode($this->_get('redirect')); $redirect_url = $_GET['front_url']; Log::record('startWxpay: ' . $token . ':' . $order_sn . ':' . $wecha_id); Log::save(); if (empty($order_sn) || empty($token)) { $this->error('请输入订单号'); } $pay_type = $_GET['pay_type']; if ($pay_type == '1') { $order = M('hotel_order')->where(array('sn' => $order_sn, 'token' => $token, 'order_status' => 3))->find(); } elseif ($pay_type == '2') { $order = M('dine_order')->where(array('sn' => $order_sn, 'token' => $token, 'status' => 2))->find(); } else { $order = M('b2c_order')->where(array('sn' => $order_sn, 'token' => $token, 'branch_id' => $this->branch_id, 'status' => 1))->find(); } if (!$order) { $this->error('订单号不正确'); } //$shop = M('b2c_shop')->where(array('token'=>$token, 'branch_id'=>$this->branch_id))->find(); //if(!$shop) $this->error('商城不存在'); $payment_where = array('token' => $token, 'pay_code' => 'wxpay', 'pay_type' => $pay_type); if (!empty($this->branch_id)) { $payment_where['branch_id'] = $this->branch_id; } $payment = M('b2c_payment')->where($payment_where)->find(); $wxpay_config = unserialize($payment['pay_config']); Log::record('wxpay order:' . $order_sn . ' config:' . print_r($wxpay_config, true)); if (!empty($wxpay_config)) { if ($pay_type == '1') { $order_content = $order['room_type']; $total_fee = intval(floatval($order['prepayment']) * 100); //分 } elseif ($pay_type == '2') { $order_content = '订单'; $total_fee = intval(floatval($order['price']) * 100); //分 } else { $order_content = $this->getOrderDesc($order['order_id']); //'订单'.$order['sn'].'支付'; $total_fee = intval(floatval($order['price']) * 100); //分 } $product_fee = $total_fee; $transport_fee = 0; $bank_type = "WX"; $spbill_create_ip = '127.0.0.1'; //服务器异步通知页面路径 $notify_url = $this->generatePayUrl('wxpay/notify', array('pay_type' => $pay_type), true); //C('site_url').'/index.php/wxpay/notify'; // add audit for WX Pay. $trade = M('b2c_wxtrade')->where(array('order_sn' => $order_sn, 'token' => $token))->find(); if ($trade['n_transaction_id']) { $this->error('已支付'); } include_once LIB_PATH . "ORG/Wpay/WxPayPubHelper.php"; //使用jsapi接口 $jsApi = new JsApi_pub($wxpay_config); //=========步骤1:网页授权获取用户openid============ //通过code获得openid if (!session('wechat_id_' . $token)) { if (!isset($_GET['code'])) { //触发微信返回code码 $redirect_uri = C('site_url') . '/index.php/wxpay/pay?order_sn=' . $order_sn . '&token=' . $token . '&bid=' . $this->branch_id . '&pay_type=' . $pay_type . '&front_url=' . urlencode($redirect_url); $url = $jsApi->createOauthUrlForCode($redirect_uri); Header("Location: {$url}"); } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } } else { $openid = session('wechat_id_' . $token); } //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new UnifiedOrder_pub($wxpay_config); //设置统一支付接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 $unifiedOrder->setParameter("openid", $openid); //商品描述 $unifiedOrder->setParameter("body", $order_content); //商品描述 //自定义订单号,此处仅作举例 //$timeStamp = time(); //$out_trade_no = WxPayConf_pub::APPID."$timeStamp"; $unifiedOrder->setParameter("out_trade_no", $order_sn); //商户订单号 $unifiedOrder->setParameter("total_fee", $total_fee); //总金额 $unifiedOrder->setParameter("notify_url", $notify_url); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 //非必填参数,商户可根据实际情况选填 //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号 //$unifiedOrder->setParameter("device_info","XXXX");//设备号 //$unifiedOrder->setParameter("attach","XXXX");//附加数据 //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间 //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间 //$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记 //$unifiedOrder->setParameter("openid","XXXX");//用户标识 //$unifiedOrder->setParameter("product_id","XXXX");//商品ID $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $biz_pkg_array = $jsApi->getParameters(); $biz_package = json_encode($biz_pkg_array); $this->assign('biz_package', $biz_package); Log::record('wxpay start token:' . $token . ' outorder:' . $order_sn . ' wecha_id:' . $wecha_id . ' biz_package:' . $biz_package, Log::INFO); Log::save(); if (!$trade) { $oParams = json_decode($biz_pkg_array); $time = time(); // 微信参数 $data['token'] = $token; $data['wecha_id'] = $wecha_id; // 协议参数 $data['appId'] = $wxpay_config['APPID']; //$data['appkey'] = $wxpay_config['APPKEY']; $data['partnerId'] = $wxpay_config['PARTNERID']; //$data['partnerkey'] = $wxpay_config['PARTNERKEY']; //$data['appsecret'] = $wxpay_config['APPSERCERT']; $data['timeStamp'] = $oParams->timeStamp; $data['nonceStr'] = $oParams->nonceStr; $data['paySign'] = $oParams->paySign; // 订单详情 $data['order_sn'] = $order_sn; $data['bank_type'] = $bank_type; $data['body'] = $order_content; $data['total_fee'] = $total_fee; $data['transport_fee'] = $transport_fee; $data['product_fee'] = $product_fee; $data['spbill_create_ip'] = $spbill_create_ip; // 订单状态追踪 $data['create_time'] = $time; $data['trade_start_times'] = 1; $this->assign('trade', $data); $ret = M('b2c_wxtrade')->add($data); } else { $this->assign('trade', $trade); $ret = M('b2c_wxtrade')->where(array('id' => $trade['id']))->setInc('trade_start_times'); } if ($ret === FALSE) { Log::record('wxpay fail.r/w db fail. order_sn:' . $order_sn . ' err:' . M('b2c_wxtrade')->getDbError()); Log::save(); $this->error('服务器忙!请稍后重试!'); } $this->assign('receiver', $wxpay_config['name']); $this->assign('redirect_url', $redirect_url); $this->display(); } else { $this->error('商家信息设置有误!请联系商家客服!'); } }
public function pay() { /** * JS_API支付demo * ==================================================== * 在微信浏览器里面打开H5网页中执行JS调起支付。接口输入输出数据格式为JSON。 * 成功调起支付需要三个步骤: * 步骤1:网页授权获取用户openid * 步骤2:使用统一支付接口,获取prepay_id * 步骤3:使用jsapi调起支付 */ $this->load->helper("wxpay"); //使用jsapi接口 $jsApi = new JsApi_pub(); //=========步骤1:网页授权获取用户openid============ //通过code获得openid if (!isset($_GET['code'])) { //触发微信返回code码 $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL); Header("Location: {$url}"); } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new UnifiedOrder_pub(); //设置统一支付接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 $unifiedOrder->setParameter("openid", "{$openid}"); //商品描述 $unifiedOrder->setParameter("body", "上门洗车"); //商品描述 //自定义订单号,此处仅作举例 $timeStamp = time(); //$out_trade_no = WxPayConf_pub::APPID."$timeStamp"; $unifiedOrder->setParameter("out_trade_no", $_SESSION['number']); //商户订单号 $unifiedOrder->setParameter("total_fee", $_SESSION['fee']); //总金额 $unifiedOrder->setParameter("notify_url", WxPayConf_pub::NOTIFY_URL); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 //非必填参数,商户可根据实际情况选填 //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号 //$unifiedOrder->setParameter("device_info","XXXX");//设备号 //$unifiedOrder->setParameter("attach","XXXX");//附加数据 //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间 //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间 //$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记 //$unifiedOrder->setParameter("openid","XXXX");//用户标识 //$unifiedOrder->setParameter("product_id","XXXX");//商品ID $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); $data = array('jsApiParameters' => $jsApiParameters, 'fee' => $_SESSION['fee']); $this->load->view('/home/t', $data); }
/** * 订单详情 */ public function order() { require_once W_LIBRARY_PATH . '/wx/pay/WxPayPubHelper/WxPayPubHelper.php'; //\Core\View::$title = '订单详情'; $id = \Core\URI::kv('id'); $row = \Db\Trade\Order::row(array('order_id' => $id)); $v = new \Model\Validation(); $v->required($row)->message('订单不存在'); //var_dump($row);exit(); if ($v->has_error()) { redirect(\Core\URI::a2p(array('main' => 'tab2'))); } $this->view->content = view('trade/order.php'); $this->view->content->row = $row; if ($row->order_status == 0 && $row->pay_type == 0) { //使用jsapi接口 $jsApi = new \JsApi_pub(); //var_dump(isset($_GET['code']));exit(); //=========步骤1:网页授权获取用户openid============ //通过code获得openid if (!isset($_GET['code'])) { //触发微信返回code码 $url = $jsApi->createOauthUrlForCode(\WxPayConf_pub::JS_API_CALL_URL . "?id={$id}"); Header("Location: {$url}"); exit; } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new \UnifiedOrder_pub(); //设置统一支付接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 $unifiedOrder->setParameter("openid", "{$openid}"); //商品描述 $unifiedOrder->setParameter("body", "文和友老长沙外卖"); //商品描述 //自定义订单号,此处仅作举例 $timeStamp = time(); //$out_trade_no = \WxPayConf_pub::APPID."$timeStamp"; //$unifiedOrder->setParameter("out_trade_no","$out_trade_no");//商户订单号 $unifiedOrder->setParameter("out_trade_no", "{$id}"); //商户订单号 $unifiedOrder->setParameter("total_fee", $row->total_amount * 100); //总金额 $unifiedOrder->setParameter("notify_url", \WxPayConf_pub::NOTIFY_URL); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 //非必填参数,商户可根据实际情况选填 //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号 //$unifiedOrder->setParameter("device_info","XXXX");//设备号 //$unifiedOrder->setParameter("attach","XXXX");//附加数据 //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间 //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间 //$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记 //$unifiedOrder->setParameter("openid","XXXX");//用户标识 //$unifiedOrder->setParameter("product_id","XXXX");//商品ID $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); $this->view->content->jsApiParameters = $jsApiParameters; } }
public function index() { /** * JS_API支付 * ==================================================== * 在微信浏览器里面打开H5网页中执行JS调起支付。接口输入输出数据格式为JSON。 * 成功调起支付需要三个步骤: * 步骤1:网页授权获取用户openid * 步骤2:使用统一支付接口,获取prepay_id * 步骤3:使用jsapi调起支付 */ /*if(!$xml = file_get_contents("php://input")){ exit('post data required'); }*/ if (isset($_GET['rcode'])) { $request_data = array(); $tmp = explode('-', $_GET['rcode']); foreach ($tmp as $fv) { $t = explode('|', $fv); $request_data[$t[0]] = $t[1]; } if (!($out_trade_no = $request_data['serial_number'])) { exit('serial_number required:' . $out_trade_no); } if (!($user_id = $request_data['user_id'])) { exit('user_id required'); } if (!($order_id = $request_data['order_id'])) { exit('order_id required'); } if (!isset($request_data['cur_stage'])) { exit('cur_stage required'); } if (!($phone = $request_data['phone'])) { exit('phone required'); } $cur_stage = $request_data['cur_stage']; if ($cur_stage < ORDER_STATUS_FIRST || $cur_stage >= ORDER_STATUS_LAST) { exit('cur_stage invalid'); } } else { if (!($out_trade_no = $this->input->post('serial_number'))) { exit('serial_number required:' . $out_trade_no); } if (!($user_id = $this->input->post('user_id'))) { exit('user_id required'); } if (!($order_id = $this->input->post('order_id'))) { exit('order_id required'); } if (!($phone = $this->input->post('phone'))) { exit('phone required'); } if (!isset($_POST['cur_stage'])) { exit('cur_stage required'); } $cur_stage = $this->input->post('cur_stage'); if ($cur_stage < ORDER_STATUS_FIRST || $cur_stage >= ORDER_STATUS_LAST) { exit('cur_stage invalid'); } } //使用jsapi接口 $jsApi = new JsApi_pub(); //=========步骤1:网页授权获取用户openid============ //通过code获得openid if (!isset($_GET['code'])) { //触发微信返回code码 $params_format = "order_id|{$order_id}-user_id|{$user_id}-serial_number|{$out_trade_no}-cur_stage|{$cur_stage}-phone|{$phone}"; $suffix = "rcode={$params_format}"; $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL . '?' . $suffix); Header("Location: {$url}"); exit; } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new UnifiedOrder_pub(); //设置统一支付接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 $unifiedOrder->setParameter("openid", "{$openid}"); //商品描述 $unifiedOrder->setParameter("body", DOMAIN_CHNAME); //商品描述 //自定义订单号,此处仅作举例 $timeStamp = (string) time(); $t = time() % 9; $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}{$cur_stage}{$t}"); //商户订单号 $unifiedOrder->setParameter("total_fee", $this->config->item($cur_stage, 'stage_fee')); //总金额 $unifiedOrder->setParameter("notify_url", BASE_URL . '/pay/notify_wechat'); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 $unifiedOrder->setParameter("attach", "{$order_id}-{$cur_stage}"); //附加数据 $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $data['jsApiParameters'] = $jsApi->getParameters(); $data['order_id'] = $order_id; $data['user_id'] = $user_id; $data['serial_number'] = $out_trade_no; $data['cur_stage'] = $cur_stage; $data['phone'] = $phone; $data['fee'] = $this->config->item($cur_stage, 'stage_fee') * 0.01; $data['fee_name'] = $this->config->item($cur_stage, 'stage_pay_name'); $this->load->view('pay', $data); }
public function new_pay() { //全局引入微信支付类 Vendor('Wxpay.WxPayPubHelper.WxPayPubHelper'); //使用jsapi接口 $jsApi = new \JsApi_pub(); //=========步骤1:网页授权获取用户openid============ //通过code获得openid if (!isset($_GET['code'])) { //触发微信返回code码 $url = $jsApi->createOauthUrlForCode($this->fromurl); Header("Location: {$url}"); } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new \UnifiedOrder_pub(); //设置统一支付接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 $unifiedOrder->setParameter("openid", $openid); //商品描述 $unifiedOrder->setParameter("body", "贡献一分钱"); //商品描述 //自定义订单号,此处仅作举例 $timeStamp = time(); $out_trade_no = \WxPayConf_pub::APPID . $timeStamp; // $out_trade_no = '123456789'; $unifiedOrder->setParameter("out_trade_no", $out_trade_no); //商户订单号 $unifiedOrder->setParameter("total_fee", "1"); //总金额 $unifiedOrder->setParameter("notify_url", \WxPayConf_pub::NOTIFY_URL); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 //非必填参数,商户可根据实际情况选填 //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号 //$unifiedOrder->setParameter("device_info","XXXX");//设备号 //$unifiedOrder->setParameter("attach","XXXX");//附加数据 //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间 //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间 //$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记 //$unifiedOrder->setParameter("openid","XXXX");//用户标识 //$unifiedOrder->setParameter("product_id","XXXX");//商品ID $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); //print_r($jsApiParameters);die(); $this->assign('jsApiParameters', $jsApiParameters); $this->display(); }
/** * 微信红包发放 * $dataArr 提交参数内容 */ function RedPackage($code, $dataArr = array()) { $hongbao = new RedPackage(); $jsApi = new JsApi_pub(); if (!isset($code)) { //触发微信返回code码 $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::RED_API_CALL_URL); Header("Location: {$url}"); } else { //获取code码,以获取openid //$code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } $hongbao->setParameter("mch_billno", $dataArr['mch_billno']); //微信订单号 $hongbao->setParameter("nick_name", $dataArr['nick_name']); //商户退款单号 $hongbao->setParameter("send_name", $dataArr['send_name']); //总金额 $hongbao->setParameter("re_openid", $openid); //退款金额 $hongbao->setParameter("total_amount", $dataArr['total_amount']); //退款金额 $hongbao->setParameter("min_value", $dataArr['min_value']); //退款金额 $hongbao->setParameter("max_value", $dataArr['max_value']); //退款金额 $hongbao->setParameter("total_num", $dataArr['total_num']); //退款金额 $hongbao->setParameter("wishing", $dataArr['wishing']); //退款金额 $hongbao->setParameter("client_ip", $dataArr['client_ip']); //退款金额 $hongbao->setParameter("act_name", $dataArr['act_name']); //退款金额 $hongbao->setParameter("remark", $dataArr['remark']); //退款金额 //调用结果 $hongbaoResult = $hongbao->getResult(); echo "错误代码:" . $hongbaoResult['err_code'] . "<br>"; echo "错误代码描述:" . $hongbaoResult['err_code_des'] . "<br>"; }
function wxpay() { $oid = intval($_REQUEST["oid"]); $type = $_REQUEST["type"]; if ($oid > 0) { $order = M($type . "order")->field("title,paysn,amount,userid")->where(array('id' => $oid, "status" => 0))->find(); if (empty($order["paysn"])) { $psn = "rex" . time() . "u" . $order["userid"]; M($type . "order")->where("id=" . $oid)->setField("paysn", $psn); $order["paysn"] = $psn; } } $this->assign('payid', $this->Config["payid"]); ////////////////微信支付插件开始///////////////// include_once "wxpay/WxPayPubHelper/WxPayPubHelper.php"; require_once "wxpay/js/jssdk.php"; session_start(); $jssdk = new JSSDK(WxPayConf_pub::APPID, WxPayConf_pub::APPSECRET); $signPackage = $jssdk->GetSignPackage(); //print_r($signPackage); //使用jsapi接口 $jsApi = new JsApi_pub(); if (!isset($_GET['code'])) { $_SESSION["order"] = $order; $uri = WxPayConf_pub::JS_API_CALL_URL; $url = $jsApi->createOauthUrlForCode(urlencode($uri)); header("Location: {$url}"); exit; } else { //获取code码,以获取openid $order = $_SESSION["order"]; $this->assign('order', $order); $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); //echo $openid;exit; } //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new UnifiedOrder_pub(); $unifiedOrder->setParameter("openid", $openid); //商品描述 $unifiedOrder->setParameter("body", "订单号:" . $order["paysn"]); //商品描述 //自定义订单号,此处仅作举例 $out_trade_no = WxPayConf_pub::APPID . time(); $map["out_trade_no"] = $order["paysn"]; $map["total_fee"] = $order["amount"] * 100; $map["notify_url"] = WxPayConf_pub::NOTIFY_URL; //echo "out_trade_no:".$out_trade_no; //print_r($map); $unifiedOrder->setParameter("out_trade_no", $map["out_trade_no"]); //商户订单号 $unifiedOrder->setParameter("total_fee", $map["total_fee"]); //总金额 $unifiedOrder->setParameter("notify_url", $map["notify_url"]); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 $prepay_id = $unifiedOrder->getPrepayId(); //echo "prepay_id:".$prepay_id; //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); $data = json_decode($jsApiParameters, true); $this->assign('signPackage', $signPackage); $this->assign('data', $data); ///////////////////////////////////////////////// ////////////////微信支付插件结束//////////////// $this->display(); }
public function actionJspay() { // echo "string"; //使用jsapi接口 $jsApi = new \JsApi_pub(); //如果是直接include过来的要在new 的类名前面加一个 反斜杠 \ 才可以 解析 $form = Yii::$app->request->get(); //获取地址栏中get过来的信息 if (!empty($form['id'])) { $id = $form['id']; } //=========步骤1:网页授权获取用户openid============ //通过code获得openid if (!isset($_GET['code'])) { //触发微信返回code码 $redirect_uri = urlencode(\WxPayConf_pub::JS_API_CALL_URL); $url = $jsApi->createOauthUrlForCode($redirect_uri, $id); // echo $url;exit; return $this->redirect($url); //用yii自带的跳转 // Header("Location: $url"); //这里不会跳转,用yii自带的跳转 } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $session = Yii::$app->session; $session->isActive ? '' : $session->open(); if (!empty($_SESSION['pay']['openid'])) { $openid = $_SESSION['pay']['openid']; } else { $openid = $jsApi->getOpenId(); $_SESSION['pay']['openid'] = $openid; } $form = Yii::$app->request->get(); $id = intval($form['state']); // echo $id.'h';//测试回掉id成功 } /* 通过id获取订单信息 */ $orderBase = Order::find()->where(['id' => $id])->asArray()->one(); $price = $orderBase['totalpay'] * 100; //价格 $mobile = $orderBase['mobile']; $truename = $orderBase['truename']; $address = $orderBase['address']; $out_trade_no = $orderBase['orderno']; // echo $price.'<br />'; // echo $address.'<br />'; // echo $truename.'<br />'; // echo $out_trade_no.'<br />'; // exit; //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new \UnifiedOrder_pub(); //设置统一支付接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 $unifiedOrder->setParameter("openid", "{$openid}"); //商品描述 $unifiedOrder->setParameter("body", "365活动"); //商品描述 //自定义订单号,此处仅作举例 $timeStamp = time(); // $out_trade_no = \WxPayConf_pub::APPID."$timeStamp"; // echo $out_trade_no; // $out_trade_no = $out_trade_no; $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}"); //商户订单号 此处变量要用大括号阔起来 $unifiedOrder->setParameter("total_fee", "{$price}"); //总金额 $unifiedOrder->setParameter("notify_url", \WxPayConf_pub::NOTIFY_URL); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 //非必填参数,商户可根据实际情况选填 //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号 //$unifiedOrder->setParameter("device_info","XXXX");//设备号 //$unifiedOrder->setParameter("attach","XXXX");//附加数据 $unifiedOrder->setParameter("time_start", date('YmdHis')); //交易起始时间 $time_expire = date("YmdHis", strtotime("+7 day")); $unifiedOrder->setParameter("time_expire", "{$time_expire}"); //交易结束时间 // $unifiedOrder->setParameter("time_expire",date('YmdHis'));//交易结束时间 $unifiedOrder->setParameter("goods_tag", "红叶"); //商品标记 //$unifiedOrder->setParameter("openid","XXXX");//用户标识 $unifiedOrder->setParameter("product_id", "0008"); //商品ID // ECHO $openid.'--P1'; $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); $this->layout = false; //调用个人中心的布局 return $this->render('pay', ['jsApiParameters' => $jsApiParameters, 'relprice' => $orderBase['totalpay'], 'mobile' => $mobile, 'truename' => $truename, 'address' => $address, 'out_trade_no' => $out_trade_no]); //显示页面,同时把$jsApiParameters 发送至页面 }
public function action_weixinpay() { /** * JS_API支付demo * ==================================================== * 在微信浏览器里面打开H5网页中执行JS调起支付。接口输入输出数据格式为JSON。 * 成功调起支付需要三个步骤: * 步骤1:网页授权获取用户openid * 步骤2:使用统一支付接口,获取prepay_id * 步骤3:使用jsapi调起支付 */ $GLOBALS['cfg_wxpay_appid'] = Common::getSysConf('value', 'cfg_wxpay_appid', 0); //appid $GLOBALS['cfg_wxpay_mchid'] = Common::getSysConf('value', 'cfg_wxpay_mchid', 0); //mchid $GLOBALS['cfg_wxpay_key'] = Common::getSysConf('value', 'cfg_wxpay_key', 0); //key $GLOBALS['cfg_wxpay_appsecret'] = Common::getSysConf('value', 'cfg_wxpay_appsecret', 0); //secret include_once PUBLICPATH . '/thirdpay/weixinpay/WxPayPubHelper/WxPayPubHelper.php'; /**************************调用授权接口alipay.wap.trade.create.direct获取授权码token**************************/ //使用jsapi接口 $jsApi = new JsApi_pub(); //=========步骤1:网页授权获取用户openid============ //通过code获得openid if (!isset($_GET['code'])) { //触发微信返回code码 $backurl = WxPayConf_pub::JS_API_CALL_URL; $backurl = $backurl . "?ordersn=" . $_POST['ordersn']; $url = $jsApi->createOauthUrlForCode($backurl); Header("Location: {$url}"); exit; } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new UnifiedOrder_pub(); //设置统一支付接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 $out_trade_no = $_GET['ordersn']; $info = ORM::factory('member_order')->where("ordersn='" . $out_trade_no . "'")->find()->as_array(); $goodsname = $info['productname']; $total_fee = intval($info['price']) * intval($info['dingnum']) + intval($info['childprice']) * intval($info['childnum']); $total_fee = $total_fee * 100; $unifiedOrder->setParameter("openid", "{$openid}"); //商品描述 //自定义订单号,此处仅作举例 $timeStamp = time(); $tem_trade = WxPayConf_pub::APPID . "{$timeStamp}"; $unifiedOrder->setParameter("out_trade_no", "{$tem_trade}"); //商户订单号 $unifiedOrder->setParameter("body", "{$goodsname}"); //商品描述 $unifiedOrder->setParameter("total_fee", "{$total_fee}"); //总金额 $unifiedOrder->setParameter("notify_url", WxPayConf_pub::NOTIFY_URL); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 //非必填参数,商户可根据实际情况选填 $unifiedOrder->setParameter("attach", "{$out_trade_no}"); //订单号 //$unifiedOrder->setParameter("device_info","XXXX");//设备号 //$unifiedOrder->setParameter("attach","XXXX");//附加数据 //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间 //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间 //$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记 //$unifiedOrder->setParameter("openid","XXXX");//用户标识 //$unifiedOrder->setParameter("product_id","XXXX");//商品ID $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); $this->assign('jsApiParameters', $jsApiParameters); $this->assign('productname', $goodsname); $this->assign('total_fee', $total_fee / 100); $this->display('public/weixinpaypost'); }
function wxpayOp() { $model = Model('mb_payment'); $params = array('payment_code' => 'wxpay'); $pay = $model->get_payment_info($params); $rt = unserialize($pay['payment_config']); $payconf = array('appid' => $rt['wxpay_appid'], 'appsecret' => $rt['wxpay_appsecret'], 'apikey' => $rt['wxpay_key'], 'mch_id' => $rt['wxpay_mch_id']); include_once BASE_PATH . DS . 'api' . DS . "wxpay/WxPayApi.php"; //使用jsapi接口 $jsApi = new JsApi_pub($payconf); //=========步骤1:网页授权获取用户openid============ //通过code获得openid if (isset($_SESSION['wx_openid']) && $_SESSION['wx_openid']) { $openid = trim($_SESSION['wx_openid']); } else { if (!isset($_GET['code'])) { $redirect_uri = SHOP_SITE_URL . '/index.php?act=mb_payment&op=wxpay&pay_sn=' . $_GET['pay_sn']; //触发微信返回code码 $url = $jsApi->createOauthUrlForCode(urlencode($redirect_uri)); Header("Location: {$url}"); } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); $_SESSION['wx_openid'] = $openid; } } $notify_url = 'http://' . $_SERVER['SERVER_NAME'] . '/wxnotify.php'; //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new UnifiedOrder_pub($payconf); //get order info $model = Model('mb_payment'); $condition['pay_sn'] = $_GET['pay_sn']; $condition['order_state'] = ORDER_STATE_NEW; $order_list = $model->get_order_detail($condition); $total_amount = 0; $shipping_fee = 0; $order_amount = 0; $goods_desc = ''; $order_sn = ''; foreach ($order_list as $row) { $order_amount = $row['order_amount']; $shipping_fee = $row['shipping_fee']; $goods_desc .= $row['goods_name']; $order_sn = $row['order_sn']; } $goods_desc = $this->my_cus_substr($goods_desc, 20); $total_amount = (int) ($shipping_fee * 100 + $order_amount * 100); //设置统一支付接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 $unifiedOrder->setParameter("openid", "{$openid}"); //商品描述 $unifiedOrder->setParameter("body", "{$goods_desc}"); //商品描述 $unifiedOrder->setParameter("out_trade_no", "{$order_sn}"); //商户订单号 $unifiedOrder->setParameter("total_fee", "{$total_amount}"); //总金额 $unifiedOrder->setParameter("notify_url", $notify_url); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 //非必填参数,商户可根据实际情况选填 //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号 //$unifiedOrder->setParameter("device_info","XXXX");//设备号 //$unifiedOrder->setParameter("attach","XXXX");//附加数据 //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间 //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间 //$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记 //$unifiedOrder->setParameter("openid","XXXX");//用户标识 //$unifiedOrder->setParameter("product_id","XXXX");//商品ID $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); $redirect = SHOP_SITE_URL . '/index.php?act=wap_member_order'; echo <<<EOF \t\t\t<html> \t\t\t\t<head> \t\t\t\t <meta http-equiv="content-type" content="text/html;charset=utf-8"/> \t\t\t\t <title>微信安全支付</title> \t\t\t\t \t\t\t\t\t<script type="text/javascript"> \t\t\t\t \t\t\t\t\t\t//调用微信JS api 支付 \t\t\t\t\t\tfunction jsApiCall() \t\t\t\t\t\t{ \t\t\t\t\t\t\tWeixinJSBridge.invoke( \t\t\t\t\t\t\t\t'getBrandWCPayRequest', \t\t\t\t\t\t\t\t{$jsApiParameters}, \t\t\t\t\t\t\t\tfunction(res){ \t\t\t\t\t\t\t\t\t//alert(res.err_msg); \t\t\t\t\t\t\t\t\twindow.location.href = '{$redirect}'; \t\t\t\t\t\t\t\t} \t\t\t\t\t\t\t); \t\t\t\t\t\t} \t\t\t\t \t\t\t\t\t\tfunction callpay() \t\t\t\t\t\t{ \t\t\t\t\t\t\tif (typeof WeixinJSBridge == "undefined"){ \t\t\t\t\t\t\t if( document.addEventListener ){ \t\t\t\t\t\t\t document.addEventListener('WeixinJSBridgeReady', jsApiCall, false); \t\t\t\t\t\t\t }else if (document.attachEvent){ \t\t\t\t\t\t\t document.attachEvent('WeixinJSBridgeReady', jsApiCall); \t\t\t\t\t\t\t document.attachEvent('onWeixinJSBridgeReady', jsApiCall); \t\t\t\t\t\t\t } \t\t\t\t\t\t\t}else{ \t\t\t\t\t\t\t jsApiCall(); \t\t\t\t\t\t\t} \t\t\t\t\t\t} \t\t\t\t\t</script> \t\t\t\t</head> \t\t\t\t<body style="font-size:12px" onLoad="callpay()"></body> \t\t\t\t</html> EOF; }
/** *函数balance_deposit 用于资金存放. */ public function balance_deposit2() { $this->pageTitle = '支付 - ' . $this->configs['shop_title']; if (!empty($_GET['code']) && !empty($_GET['other_data'])) { $other_data_str = $_GET['other_data']; $other_data_arr = explode("_", $other_data_str); $_POST['amount_num'] = isset($other_data_arr[0]) ? $other_data_arr[0] : 0; $_POST['payment_id'] = isset($other_data_arr[1]) ? $other_data_arr[1] : 0; $_POST['invoice'] = isset($other_data_arr[2]) ? $other_data_arr[2] : 0; $_POST['item_name'] = isset($other_data_arr[3]) ? $other_data_arr[3] : 0; } if (!isset($_POST['amount_num']) || !($_POST['amount_num'] > 0) || !isset($_POST['payment_id']) || !($_POST['payment_id'] > 0)) { die('参数错误'); } $orderid = $_POST['invoice']; $order_code = $_POST['item_name']; if (constant('Product') == 'AllInOne') { $orfo = $this->Order->find('first', array('conditions' => array('Order.id' => $orderid))); if (!empty($orfo)) { $orfo['Order']['sub_pay'] = $_POST['payment_id']; $this->Order->save($orfo['Order']); } } $modified = date('Y-m-d H:i:s'); $user_id = $_SESSION['User']['User']['id']; $user_info = $this->User->findbyid($user_id); $user_money = $user_info['User']['balance'] + $_POST['amount_num']; $amount_money = $_POST['amount_num']; $payment_id = $_POST['payment_id']; $payment = $this->Payment->find('first', array('conditions' => array('Payment.id' => $payment_id))); $this->Cookie->write('pay_type', $payment_id); $account_info = array('user_id' => $user_id, 'amount' => $amount_money, 'payment' => $payment_id, 'status' => 0); $this->UserAccount->save($account_info); $account_id = $this->UserAccount->id; $order_id = isset($_SESSION['order']['ever_id']) ? $_SESSION['order']['ever_id'] : $account_id; $host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''); try { $payment_config = unserialize($payment['Payment']['config']); if ($payment['Payment']['code'] == "weixinpay") { $this->layout = 'default'; $amt = $amount_money * 100; $wechatpay_type = false; if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) { App::import('Vendor', 'Weixinpay', array('file' => 'WxPayPubHelper.php')); $jsApi = new JsApi_pub($payment_config['APPID'], $payment_config['MCHID'], $payment_config['KEY'], $payment_config['APPSECRET']); if (empty($_GET['code'])) { $request_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $other_data = $amount_money . "_" . $payment_id . "_" . $orderid . "_" . $order_code; $request_url .= "?other_data=" . $other_data; //触发微信返回code码 $wechat_pay_url = $jsApi->createOauthUrlForCode($request_url); Header("Location: {$wechat_pay_url}"); } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } if (!empty($openid)) { $unifiedOrder = new UnifiedOrder_pub($payment_config['APPID'], $payment_config['MCHID'], $payment_config['KEY'], $payment_config['APPSECRET']); $unifiedOrder->setParameter("openid", $openid); //商品描述 $unifiedOrder->setParameter("body", $order_code); //商品描述 //自定义订单号,此处仅作举例 $timeStamp = time(); $out_trade_no = $order_code; $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}"); //商户订单号 $unifiedOrder->setParameter("total_fee", $amt); //总金额 $unifiedOrder->setParameter("notify_url", 'http://' . $host . $this->webroot . 'responds/weixin_notify'); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 $prepay_id = $unifiedOrder->getPrepayId(); $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); if (!empty($jsApiParameters)) { $json_result = json_decode($jsApiParameters); $code_url = isset($json_result->paySign) ? $jsApiParameters : ''; $this->set('url2', $code_url); } } else { throw new SDKRuntimeException("支付失败,OpenId 获取失败"); } } else { $this->layout = "ajax"; $wechatpay_type = true; App::import('Vendor', 'Weixinpay', array('file' => 'WxPay.Api.php')); App::import('Vendor', 'Phpqcode', array('file' => 'phpqrcode.php')); $input = new WxPayUnifiedOrder(); $notify = new NativePay(); $input->SetKey($payment_config['KEY']); $input->SetBody($order_code); $input->SetAttach($order_code); $input->SetOut_trade_no($order_code); $input->SetAppid($payment_config['APPID']); $input->SetMch_id($payment_config['MCHID']); $input->SetTotal_fee($amt); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag($order_code); $input->SetNotify_url('http://' . $host . $this->webroot . 'responds/weixin_notify'); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($order_code); $result = $notify->GetPayUrl($input); $url2 = isset($result["code_url"]) ? $result["code_url"] : ''; $this->set('url2', $url2); } $this->set('order_code', $order_code); $this->set('wechatpay_type', $wechatpay_type); } else { $pay_form_txt = ""; $host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''); if ($this->RequestHandler->isMobile() && $payment['Payment']['code'] == 'alipay') { //手机支付宝支付访问 $payment_api_log = array('payment_code' => $payment['Payment']['code'], 'type' => 1, 'type_id' => $orderid, 'order_id' => $order_code, 'order_currency' => 'CHY', 'amount' => $amount_money); $this->PaymentApiLog->save($payment_api_log); $alipay_config = array(); //合作身份者id,以2088开头的16位纯数字 $alipay_config['partner'] = isset($payment_config['partner']) ? $payment_config['partner'] : ''; //收款支付宝账号,一般情况下收款账号就是签约账号 $alipay_config['seller_id'] = isset($payment_config['partner']) ? $payment_config['partner'] : ''; //商户的私钥(后缀是.pen)文件相对路径 $alipay_config['private_key_path'] = ROOT . '/vendors/payments/alipaywap/key/rsa_private_key.pem'; //支付宝公钥(后缀是.pen)文件相对路径 $alipay_config['ali_public_key_path'] = ROOT . '/vendors/payments/alipaywap/key/rsa_public_key.pem'; //签名方式 不需修改 $alipay_config['sign_type'] = strtoupper('RSA'); //字符编码格式 目前支持 gbk 或 utf-8 $alipay_config['input_charset'] = strtolower('utf-8'); //ca证书路径地址,用于curl中ssl校验 //请保证cacert.pem文件在当前文件夹目录中 $alipay_config['cacert'] = ROOT . '/vendors/payments/alipaywap/cacert.pem'; //访问模式,根据自己的服务器是否支持ssl访问,若支持请选择https;若不支持请选择http $alipay_config['transport'] = 'http'; if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false && $payment['Payment']['code'] == 'alipay') { $alipay_config['is_wechat'] = '1'; } else { $alipay_config['is_wechat'] = '0'; } $out_trade_no = $this->PaymentApiLog->id . "_" . $order_code; $alipay_parameter = array("service" => "alipay.wap.create.direct.pay.by.user", "partner" => trim($alipay_config['partner']), "seller_id" => trim($alipay_config['seller_id']), "payment_type" => '1', "notify_url" => 'http://' . $host . $this->webroot . 'responds/return_code/' . $payment['Payment']['code'] . '/1/wap', "return_url" => 'http://' . $host . $this->webroot . 'responds/return_code/' . $payment['Payment']['code'] . '/0/wap', "out_trade_no" => $out_trade_no, "subject" => '[' . $payment_api_log['order_id'] . ']' . ' - ' . $orfo['OrderProduct'][0]['product_name'], "total_fee" => $amount_money, "show_url" => '', "body" => '', "it_b_pay" => '', "extern_token" => '', "_input_charset" => trim(strtolower($alipay_config['input_charset']))); $alipaySubmit_classfile = ROOT . "/vendors/payments/alipaywap/alipay_submit.class.php"; include_once $alipaySubmit_classfile; $alipaySubmit = new AlipaySubmit($alipay_config); $html_text = $alipaySubmit->buildRequestForm($alipay_parameter, "get", "支付"); $pay_form_txt = $html_text; } else { App::import('Vendor', 'payments/' . $payment['Payment']['code']); $balance_payment = new $payment['Payment']['code'](); if ($payment['Payment']['is_online'] == 1) { //在线支付增加api日志 $payment_api_log = array('payment_code' => $payment['Payment']['code'], 'type' => 1, 'type_id' => $orderid, 'order_id' => $order_code, 'order_currency' => 'CHY', 'amount' => $amount_money); $this->PaymentApiLog->save($payment_api_log); $payment_api_log['id'] = $this->PaymentApiLog->id; $payment_config['cancel_return'] = 'http://' . $host . $this->webroot; $payment_config['return_url'] = 'http://' . $host . $this->webroot . 'responds/return_code/' . $payment['Payment']['code'] . '/0/pc'; $payment_config['notify_url'] = 'http://' . $host . $this->webroot . 'responds/return_code/' . $payment['Payment']['code'] . '/1/pc'; $payment_config['payerName'] = '[' . $payment_api_log['order_id'] . ']' . ' - ' . $orfo['OrderProduct'][0]['product_name']; $payment_api_log['created'] = date('Y-m-d H:i:s'); $payment_api_log['subject'] = '[' . $payment_api_log['order_id'] . ']' . ' - ' . $orfo['OrderProduct'][0]['product_name']; $payment_config['payerName'] = '[' . $payment_api_log['order_id'] . ']' . ' - ' . $orfo['OrderProduct'][0]['product_name']; if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false && $payment['Payment']['code'] == 'alipay') { $payment_config['is_wechat'] = '1'; } else { $payment_config['is_wechat'] = '0'; } $api_code = $balance_payment->go($payment_api_log, $payment_config); $pay_form_txt = $api_code; } else { $this->layout = 'usercenter'; $this->set('msg', $payment['PaymentI18n']['description']); } } echo "<style type='text/css'>body{display:none;}</style>"; if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false && $payment['Payment']['code'] == 'alipay') { $this->set('pay_form_txt', $pay_form_txt); } else { echo $pay_form_txt; exit; } } } catch (Exception $e) { echo 'Caught exception: ' . $e->getMessage() . "\n"; } }
public function pay() { $order = $this->order; $wxpay_config = $this->wxpay_config; //从数据读取微支付设置 $WxPayConf_pub_data = $this->getConfigData(); include_once APP_PATH . 'Lib/ORG/Weixinpay2/WxPayPubHelper.php'; //使用jsapi接口 $jsApi = new JsApi_pub(); //=========步骤1:网页授权获取用户openid============ //通过code获得openid if (!isset($_GET['code'])) { //触发微信返回code码 $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL); Header("Location: {$url}"); } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } //=========步骤2:使用统一支付接口,获取prepay_id============ //使用统一支付接口 $unifiedOrder = new UnifiedOrder_pub(); //设置统一支付接口参数 //设置必填参数 //appid已填,商户无需重复填写 //mch_id已填,商户无需重复填写 //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 $unifiedOrder->setParameter("openid", "{$openid}"); //商品描述 $unifiedOrder->setParameter("body", "订单:" . $order['orderid']); //商品描述 //自定义订单号,此处仅作举例 $unifiedOrder->setParameter("out_trade_no", $order['orderid']); //商户订单号 $unifiedOrder->setParameter("total_fee", floatval($order['price']) * 100); //总金额 $unifiedOrder->setParameter("notify_url", WxPayConf_pub::NOTIFY_URL); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 //非必填参数,商户可根据实际情况选填 //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号 //$unifiedOrder->setParameter("device_info","XXXX");//设备号 //$unifiedOrder->setParameter("attach","XXXX");//附加数据 //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间 //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间 //$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记 //$unifiedOrder->setParameter("openid","XXXX");//用户标识 //$unifiedOrder->setParameter("product_id","XXXX");//商品ID $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); $this->assign('payurl', $jsApiParameters); $this->assign('returnUrl', $this->orders_url); $this->assign('order', $order); //exit(); /* $commonUtil = new CommonUtil(); $wxPayHelper = new WxPayHelper($this->wxpay_config['appId'],$this->wxpay_config['appKey'],$this->wxpay_config['partnerKey']); $wxPayHelper->setParameter("bank_type", "WX"); $wxPayHelper->setParameter("body", $order['orderid']); $wxPayHelper->setParameter("partner", $wxpay_config['partnerId']); $wxPayHelper->setParameter("out_trade_no",$order['orderid']); $wxPayHelper->setParameter("total_fee", floatval($order['price'])*100); $wxPayHelper->setParameter("fee_type", "1"); $wxPayHelper->setParameter("notify_url", C('site_url').'/wxpay/?g=Wap&m=Wxpay&a=notify_url'); $wxPayHelper->setParameter("spbill_create_ip", $_SERVER['REMOTE_ADDR']); $wxPayHelper->setParameter("input_charset", "GBK"); $payurl=$wxPayHelper->create_biz_package(); $this->assign('payurl',$payurl); $this->assign('returnUrl',$this->orders_url); $this->assign('order',$order);*/ $this->display(); }
/** * author: codeMonkey QQ:631872807 * 支付 */ public function doMobileZf_Demo() { global $_W; $jsApi = new JsApi_pub($this->kjSetting); if (!isset($_GET['code'])) { //触发微信返回code码 $reurl = MonUtil::str_murl($this->createMobileUrl('Zf_Demo', array(), true)); $url = $jsApi->createOauthUrlForCode(urlencode($reurl)); Header("Location: {$url}"); } else { //获取code码,以获取openid $code = $_GET['code']; $jsApi->setCode($code); $openid = $jsApi->getOpenId(); } $unifiedOrder = new UnifiedOrder_pub($this->kjSetting); $unifiedOrder->setParameter("openid", "{$openid}"); //商品描述 $unifiedOrder->setParameter("body", "测试贡献一分钱"); //商品描述 //自定义订单号,此处仅作举例 $timeStamp = time(); $out_trade_no = WxPayConf_pub::APPID . "{$timeStamp}"; $unifiedOrder->setParameter("out_trade_no", "{$out_trade_no}"); //商户订单号 $unifiedOrder->setParameter("total_fee", 1); //总金额 $notifyUrl = $_W['siteroot'] . "addons/" . MON_WKJ . "/notify.php"; $unifiedOrder->setParameter("notify_url", $notifyUrl); //通知地址 $unifiedOrder->setParameter("trade_type", "JSAPI"); //交易类型 //非必填参数,商户可根据实际情况选填 //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号 //$unifiedOrder->setParameter("device_info","XXXX");//设备号 //$unifiedOrder->setParameter("attach","XXXX");//附加数据 //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间 //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间 //$unifiedOrder->setParameter("goods_tag","XXXX");//商品标记 //$unifiedOrder->setParameter("openid","XXXX");//用户标识 //$unifiedOrder->setParameter("product_id","XXXX");//商品ID $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); $jsApiParameters = $jsApi->getParameters(); include $this->template("zf"); }