/** * * 生成直接支付url,支付url有效期为2小时,模式二 * @param UnifiedOrderInput $input */ public static function getPayUrl($input) { $notify = new NativePay(); $result = $notify->GetPayUrl($input); $url = $result["code_url"]; return $url; }
function get_pay_url($charge_type, $pay_amount, $payment_config, $subject, $order_id, $model_id = null, $obj_id = null, $service = null, $sign_type = 'MD5', $show_url = 'index.php?do=user&view=finance&op=details') { global $_K, $uid, $username; $charge_type == 'order_charge' and $t = "订单充值" or $t = "余额充值"; $body = $t . "(from:" . $username . ")"; $notify = new NativePay(); $WxPayCfg = new WxPayCfg(); $Out_trade_no = $WxPayCfg->_mchid . date("YmdHis"); $attach = "charge-{$charge_type}-{$uid}-{$obj_id}-{$order_id}-{$model_id}-" . time(); $input = new WxPayUnifiedOrder(); $input->SetBody($body); $input->SetDetail($body); $input->SetAttach($attach); $input->SetOut_trade_no($Out_trade_no); $input->SetFee_type("CNY"); $input->SetTotal_fee($pay_amount * 100); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetNotify_url(BASE_WXPAY_URL . "notify.php"); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($obj_id); $result = $notify->GetPayUrl($input); $url2 = $result["code_url"]; keke_order_class::create_order_charge('online_charge', 'wxpay', null, $obj_id, $uid, $username, $pay_amount, 'wait', '用户充值', $Out_trade_no, null, $attach); $baseUrl = urlencode($url2); $data = array(); $data['url'] = BASE_WXPAY_URL . "qrcode.php?data=" . $baseUrl; $data['out_trade_no'] = $Out_trade_no; return $data; }
public function topup() { $orderInfo = session('orderInfo'); Vendor('WxPayApi.unit.log'); Vendor('WxPayApi.lib.WxPayApi'); Vendor('WxPayApi.unit.WxPayNativePay'); //模式一 $notify = new \NativePay(); $input = new \WxPayUnifiedOrder(); $input->SetBody("会员充值"); $input->SetAttach("topup"); $input->SetOut_trade_no($orderInfo['orderNo']); $input->SetTotal_fee("1"); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetNotify_url("http://www.tyrolland.cn/Weixin/Pay/notify"); $input->SetTrade_type("NATIVE"); $input->SetProduct_id('TOPUP_' . $orderInfo['price']); $result = $notify->GetPayUrl($input); $url2 = $result["code_url"]; $userInfo = session('userInfo'); $this->assign('orderInfo', $orderInfo); $this->assign('userInfo', $userInfo); $this->assign('url', urlencode($url2)); $this->display(); }
/** * 生成微信支付二维码 */ public static function qrcode($product_id, $body, $total_fee, $attach = '', $detail = '', $goods_tag = '') { // 处理金额 if (ENV_SCENE == 'dev') { $total_fee = 0.01; } $total_fee *= 100; $notify = new NativePay(); /** * 流程: * 1、调用统一下单,取得code_url,生成二维码 * 2、用户扫描二维码,进行支付 * 3、支付完成之后,微信服务器会通知支付成功 * 4、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php) */ $input = new WxPayUnifiedOrder(); $input->SetBody($body); $input->SetAttach($product_id); if (!empty($detail)) { $input->SetDetail($detail); } $input->SetOut_trade_no(WxPayConfig::$APPID . substr($product_id, 1)); $input->SetTotal_fee($total_fee); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); if (!empty($goods_tag)) { $input->SetGoods_tag($goods_tag); } $input->SetNotify_url(WxPayConfig::$NOTIFY_URL); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($product_id); $result = $notify->GetPayUrl($input); return $result["code_url"]; }
public function index() { require_once DIR_SYSTEM . 'library/wxpay/wxpayexception.php'; define('WXPAY_APPID', trim($this->config->get('wxpay_appid'))); define('WXPAY_MCHID', trim($this->config->get('wxpay_mchid'))); define('WXPAY_KEY', trim($this->config->get('wxpay_key'))); define('WXPAY_APPSECRET', trim($this->config->get('wxpay_appsecret'))); define('WXPAY_SSLCERT_PATH', DIR_SYSTEM . 'helper/wxpay_key/apiclient_cert.pem'); define('WXPAY_SSLKEY_PATH', DIR_SYSTEM . 'helper/wxpay_key/apiclient_key.pem'); define('WXPAY_CURL_PROXY_HOST', "0.0.0.0"); define('WXPAY_CURL_PROXY_PORT', 0); define('REPORT_LEVENL', 1); require_once DIR_SYSTEM . 'library/wxpay/wxpayconfig.php'; require_once DIR_SYSTEM . 'library/wxpay/wxpaydata.php'; require_once DIR_SYSTEM . 'library/wxpay/wxpayapi.php'; require_once DIR_SYSTEM . 'library/wxpay/wxpaynativepay.php'; $this->load->language('extension/payment/qrcode_wxpay'); $data['button_confirm'] = $this->language->get('button_confirm'); $this->load->model('checkout/order'); $order_id = $this->session->data['order_id']; $order_info = $this->model_checkout_order->getOrder($order_id); $item_name = $this->config->get('config_name'); $fullname = $order_info['payment_fullname']; $this->load->model('account/order'); $shipping_cost = 0; $totals = $this->model_account_order->getOrderTotals($order_id); foreach ($totals as $total) { if ($total['title'] == 'shipping') { $shipping_cost = $total['value']; } } $notify_url = HTTPS_SERVER . 'catalog/controller/extension/payment/qrcode_wxpay_callback.php'; $out_trade_no = $this->session->data['order_id']; $subject = $item_name . ' ' . $this->language->get('text_order') . ' ' . $order_id; $amount = $order_info['total']; $currency_value = $this->currency->getValue('CNY'); $price = $amount * $currency_value; $price = number_format($price, 2, '.', ''); $total_fee = $price * 100; //乘100去掉小数点,以传递整数给微信支付 $notify = new NativePay(); $input = new WxPayUnifiedOrder(); $input->SetBody($subject); $input->SetAttach("mycncart"); $input->SetOut_trade_no($order_id); $input->SetTotal_fee($total_fee); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag("mycncart"); $input->SetNotify_url(HTTPS_SERVER . "catalog/controller/extension/payment/qrcode_wxpay_callback.php"); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($order_id); $result = $notify->GetPayUrl($input); $this->session->data['code_url'] = $result['code_url']; $data['redirect'] = $this->url->link('checkout/qrcode_wxpay_success'); return $this->load->view('extension/payment/qrcode_wxpay', $data); }
public function pay($title, $price) { $notify = new NativePay(); $input = new WxPayUnifiedOrder(); $input->SetBody($title); $input->SetAttach($title); $input->SetOut_trade_no(WxPayConfig::MCHID . date("YmdHis")); $input->SetTotal_fee($price); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag("test"); $input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php"); $input->SetTrade_type("NATIVE"); $input->SetProduct_id("123456789"); $result = $notify->GetPayUrl($input); $url2 = $result["code_url"]; return $url; }
/** * [paymenttList 微信支付页面] * @Author 罗江涛 * @DateTime 2016-03-07T17:01:37+0800 */ public function weixinPayment() { $title = I("title"); $price = I("price"); $reportId = I("reportId"); $userId = I("userId"); ini_set('date.timezone', 'Asia/Shanghai'); require "./Application/Index/Service/weixinPayApi/WxPay.Api.php"; require "./Application/Index/Service/weixinPayApi/WxPay.NativePay.php"; //模式二 $notify = new \NativePay(); /** * 流程: * 1、调用统一下单,取得code_url,生成二维码 * 2、用户扫描二维码,进行支付 * 3、支付完成之后,微信服务器会通知支付成功 * 4、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php) */ // $input = new \Index\Service\weixinPayApi\lib\WxPayUnifiedOrder(); $input = new \WxPayUnifiedOrder(); $input->SetBody($title); $input->SetAttach($userId . "|" . $reportId); $input->SetOut_trade_no(\WxPayConfig::MCHID . date("YmdHis")); // $input->SetOut_trade_no($reportId); $input->SetTotal_fee($price); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag("SetGoods_tag"); // $input->SetNotify_url("http://qingdao.luojiangtao.com/index.php/Api/Payment/getWeixinPaymentInfo"); // $input->SetNotify_url(U("Api/Payment/getWeixinPayPost")); $input->SetNotify_url("http://qingdao.luojiangtao.com/vcbeat/index.php/Api/Payment/getWeixinPayPost"); $input->SetTrade_type("NATIVE"); $input->SetProduct_id("123456789"); // p($_SERVER);die; $result = $notify->GetPayUrl($input); $url2 = $result["code_url"]; // p($result);die; // $this->assign("url2", $url2); $this->url2 = $url2; $this->display(); }
/** * 订单微信支付 * @author 李东 * @date 2015-07-21 */ public function index() { /*获取微信支付配置信息*/ $wxpay_config = C('payment.wxpay'); $notify = new \NativePay(); //$url1 = $notify->GetPrePayUrl("123456789"); $input = new \WxPayUnifiedOrder(); $input->SetBody("test"); /*设置商品或支付单简要描述*/ $input->SetAttach("test"); /*设置附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据*/ $input->SetOut_trade_no($wxpay_config['mchid'] . date("YmdHis")); /*设置商户系统内部的订单号,32个字符内、可包含字母*/ $input->SetTotal_fee("1"); /*设置订单总金额,只能为整数;如0.01元,设置为1*/ $input->SetTime_start(date("YmdHis")); /*设置订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。*/ $input->SetTime_expire(date("YmdHis", time() + 600)); /*设置订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。*/ $input->SetGoods_tag("test"); /*设置商品标记,代金券或立减优惠功能的参数*/ $input->SetNotify_url('http://' . I('server.HTTP_HOST') . U('notify')); /*设置接收微信支付异步通知回调地址*/ $input->SetTrade_type("NATIVE"); /*设置支付方式,取值如下:JSAPI,NATIVE,APP;*/ $input->SetProduct_id("123456789"); /*设置trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。*/ $result = $notify->GetPayUrl($input); /*获取返回参数*/ $url = 'http://' . I('server.HTTP_HOST') . U('create_code') . '?data=' . urlencode($result["code_url"]); /*返回的支付二维码图片地址*/ $result['show_code'] = $url; $data['result'] = $result; $this->assign($data); $this->display(); }
$str .= '移动电源x' . $battery . ','; } $body = trim($str, ','); try { $input = new WxPayUnifiedOrder(); $input->SetBody("奇艺果定制商品"); $input->SetAttach("奇艺果定制商品"); $input->SetOut_trade_no($order_sn); $input->SetTotal_fee($money_paid); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag("test"); $input->SetNotify_url(URL . "pays/wxpay_saoma/example/notify.php"); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($order_id); $result = $notify->GetPayUrl($input); $url2 = $result["code_url"]; } catch (Exception $e) { echo "系统繁忙,请稍后再试。"; exit; } ?> <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta name="renderer" content="webkit"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
public function finishOrder() { $userInfo = session('userInfo'); if (!$userInfo) { return; } $orderNo = I('get.orderno'); $orderInfo = $this->getOrderInfoByNo($orderNo); if (!$orderInfo && !$orderInfo['tmp']) { return; } $userInfo = $this->getUserNewInfo($userInfo['id']); Vendor('WxPayApi.unit.log'); Vendor('WxPayApi.lib.WxPayApi'); Vendor('WxPayApi.unit.WxPayNativePay'); //模式一 $notify = new \NativePay(); $input = new \WxPayUnifiedOrder(); $input->SetBody("蒂罗尔曲奇商城订单"); $input->SetAttach("goods"); $input->SetOut_trade_no($orderInfo['orderNo']); $input->SetTotal_fee("1"); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetNotify_url("http://www.tyrolland.cn/Weixin/Pay/notify"); $input->SetTrade_type("NATIVE"); $input->SetProduct_id('TOPUP_' . $orderInfo['price']); $result = $notify->GetPayUrl($input); $url2 = $result["code_url"]; $this->assign('orderInfo', $orderInfo); $this->assign('userInfo', $userInfo); $this->assign('url', urlencode($url2)); $this->display(); }
public function index() { //echo "one"; $this->load->library('wxpayexception'); define('APPID', $this->config->get('wxpay_appid')); define('MCHID', $this->config->get('wxpay_mchid')); define('KEY', $this->config->get('wxpay_key')); define('APPSECRET', $this->config->get('wxpay_appsecret')); //echo "three"; $this->load->library('wxpaydata'); //echo "four"; $this->load->library('wxpayapi'); //echo "five"; $this->load->library('wxpaynativepay'); //echo "six"; $this->language->load('payment/qrcode_wxpay'); $data['button_confirm'] = $this->language->get('button_confirm'); $this->load->model('checkout/order'); $order_id = $this->session->data['order_id']; $order_info = $this->model_checkout_order->getOrder($order_id); $item_name = $this->config->get('config_name'); $fullname = $order_info['payment_fullname']; $this->load->model('account/order'); $shipping_cost = 0; $totals = $this->model_account_order->getOrderTotals($order_id); foreach ($totals as $total) { if ($total['title'] == 'shipping') { $shipping_cost = $total['value']; } } $notify_url = HTTPS_SERVER . 'catalog/controller/payment/qrcode_wxpay_callback.php'; $out_trade_no = $this->session->data['order_id']; $subject = $item_name . ' ' . $this->language->get('text_order') . ' ' . $order_id; $amount = $order_info['total']; $currency_value = $this->currency->getValue('CNY'); $price = $amount * $currency_value; $price = number_format($price, 2, '.', ''); $total_fee = $price * 100; //乘100去掉小数点,以传递整数给微信支付 //$total_fee = 1; //echo "Total Fee: ".$total_fee."<br>"; //echo "3"; //$openId = $this->session->data['weixin_openid']; $notify = new NativePay(); $input = new WxPayUnifiedOrder(); $input->SetBody($subject); $input->SetAttach("mycncart"); $input->SetOut_trade_no($order_id); $input->SetTotal_fee($total_fee); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag("mycncart"); $input->SetNotify_url(HTTP_SERVER . "catalog/controller/payment/qrcode_wxpay_callback.php"); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($order_id); $result = $notify->GetPayUrl($input); //$url2 = $result["code_url"]; $this->session->data['code_url'] = $result['code_url']; $data['redirect'] = $this->url->link('checkout/qrcode_wxpay_success'); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/qrcode_wxpay.tpl')) { return $this->load->view($this->config->get('config_template') . '/template/payment/qrcode_wxpay.tpl', $data); } else { return $this->load->view('default/template/payment/qrcode_wxpay.tpl', $data); } }
*/ // $notify = new NativePay(); // $url1 = $notify->GetPrePayUrl("123456789"); $notify = new NativePay(); $input = new WxPayUnifiedOrder(); $input->SetBody(Config::WX_ORDER_TITLE); $input->SetAttach(PAY_ENV); //测试环境必须加上时间戳,否则会有报商户订单号重复得错误(原因是线上和测试环境都是统一使用微信支付创建支付订单) $input->SetOut_trade_no($order_info['id']); $input->SetTotal_fee($order_info['final_price']); //$input->SetTotal_fee(1); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + Config::WX_ORDER_TIMEOUT)); $input->SetGoods_tag(Config::WX_ORDER_TAG); $input->SetNotify_url(Config::API_NOTIFY_URL); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($order_id); $result = $notify->GetPayUrl($input, Config::API_TIMEOUT); if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { $short_url = $result["code_url"]; QRcode::png($short_url, false, 3, 5, 5); } else { throw new Exception('支付短链接生成异常,异常原因:' . $result['err_code_des']); } } else { throw new Exception('order_id required'); } } catch (Exception $e) { Log::ERROR(sprintf('run exceptin:%s|file:%s|line:%s', $e->getMessage(), $e->getFile(), $e->getLine())); echo $e->getMessage(); }
private function wechatPay ($order, $good, $orderPrice) { require_once('lib/WxPay.Api.php'); require_once('WxPay.NativePay.php'); require_once('log.php'); require_once('lib/phpqrcode.php'); $notify = new \NativePay(); $notify_url = $this->debug ? "http://www.51linpai.com:8000/order/wxpay/" : "http://www.51linpai.com/order/wxpay"; $input = new \WxPayUnifiedOrder(); $input->SetBody($good->name); $input->SetAttach($good->code); $input->SetOut_trade_no($order->code); $input->SetTotal_fee($orderPrice->final_price * 100); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag($good->code); $input->SetNotify_url($notify_url); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($good->id . '_' . $good->code); $result = $notify->GetPayUrl($input); $url2 = $result["code_url"]; $path = storage_path() . '/app/pay_code/'; $file = $order->code . '.png'; if (!is_dir($path)) { mkdir($path, 0777, true); } $png = \QRcode::png($url2, $path . $file); $qrcode = '/imgs/wxpay_qrcode/' . $file; Session::put('unpayed_order', $order->code); return view('wxpay', [ 'qrcode' => $qrcode, 'price' => $orderPrice->final_price, 'good' => $good, 'order_code' => $order->code ]); }
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'); } }
/** *函数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"; } }
/** * 获取微支付CodeUrl * @param $out_trade_no * @param $goods * @param $total_fee * @param $body * @param $attach * @param $notify_url * @param string $product_id * @return \成功时返回 */ public static function GrantWxpayCodeUrl($out_trade_no, $goods, $total_fee, $body, $attach, $notify_url, $product_id = '') { require_once __DIR__ . "/../wxpay/WxPay.Api.php"; require_once __DIR__ . "/../wxpay/WxPay.NativePay.php"; require_once __DIR__ . "/../common/log.php"; $notify = new \NativePay(); $input = new \WxPayUnifiedOrder(); $input->SetBody($body); $input->SetAttach($attach); $input->SetOut_trade_no(time() . $out_trade_no); $input->SetTotal_fee(intval($total_fee * 100)); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag($goods); $input->SetNotify_url($notify_url); $input->SetTrade_type("NATIVE"); $input->SetProduct_id($product_id); $result = $notify->GetPayUrl($input); return $result; }