Esempio n. 1
0
 /**
  * 组装包含支付信息的url(模式2)
  */
 public function get_payurl()
 {
     require_once BASE_PATH . '/api/payment/wxpay/lib/WxPay.Api.php';
     require_once BASE_PATH . '/api/payment/wxpay/WxPay.NativePay.php';
     require_once BASE_PATH . '/api/payment/wxpay/log.php';
     $logHandler = new CLogFileHandler(BASE_DATA_PATH . '/log/wxpay/' . date('Y-m-d') . '.log');
     $Logwx = Logwx::Init($logHandler, 15);
     //统一下单
     $input = new WxPayUnifiedOrder();
     $input->SetBody($this->_order_info['pay_sn'] . '订单');
     //         $input->SetBody(C('site_name').'订单');
     $input->SetAttach($this->_order_info['order_type'] == 'vr_order' ? 'v' : 'r');
     $input->SetOut_trade_no($this->_order_info['pay_sn']);
     $input->SetTotal_fee($this->_order_info['api_pay_amount'] * 100);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 3600));
     $input->SetGoods_tag('');
     $input->SetNotify_url(SHOP_SITE_URL . '/api/payment/wxpay/notify_url.php');
     $input->SetTrade_type("NATIVE");
     //$input->SetOpenid($openId);
     $input->SetProduct_id($this->_order_info['pay_sn']);
     $result = WxPayApi::unifiedOrder($input);
     //         header("Content-type:text/html;charset=utf-8");
     //         print_R($result);exit;
     Logwx::DEBUG("unifiedorder-:" . json_encode($result));
     return $result["code_url"];
 }
Esempio n. 2
0
/**
 * 生成支付接口内容
 * @param $data
 * @param bool $debug
 * @return json
 */
function jsapipay($data, $debug = false)
{
    // C('weixin.weixin_')
    //①、获取用户openid
    $tools = new JsApiPay();
    //    $openId = $tools->GetOpenid();
    if (!empty($data['openid'])) {
        $openId = $data['openid'];
    } else {
        echo "empty openid";
        die;
    }
    //②、统一下单
    $input = new WxPayUnifiedOrder();
    $input->SetBody($data['body']);
    $input->SetAttach($data['attach']);
    $input->SetOut_trade_no($data['order_sn']);
    $input->SetTotal_fee($data['total_fee']);
    $input->SetTime_start(date("YmdHis"));
    $input->SetTime_expire(date("YmdHis", time() + 600));
    $input->SetGoods_tag($data['goods_tag']);
    $input->SetNotify_url("http://{$_SERVER[HTTP_HOST]}/weixin/notify.html");
    $input->SetTrade_type("JSAPI");
    $input->SetOpenid($openId);
    $order = WxPayApi::unifiedOrder($input);
    if ($debug) {
        echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';
        printf_info($order);
    }
    $jsApiParameters = $tools->GetJsApiParameters($order);
    return $jsApiParameters;
}
Esempio n. 3
0
 /**
  * 生成微信支付二维码
  */
 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"];
 }
Esempio n. 4
0
 /**
  * jsapi支付
  * @param string  $user_id    用户id
  * @param int     $order_id
  * @param string  $order_sn   订单号
  * @param int     $total_fee  费用
  * @param string  $body       商品或支付单简要描述
  * @param string  $goods_tag  商品标记
  * @param string  $attach     自定义数据
  * @return array
  */
 public function JsApiPay($user_id, $order_id, $order_sn, $total_fee, $body = '', $goods_tag = '', $attach = '')
 {
     if (empty($user_id) || empty($total_fee)) {
         return ['status' => -1, 'message' => '数据错误'];
     }
     $tools = new JsApiPay();
     $openId = UserModel::instance()->getOpenId($user_id);
     if (empty($openId)) {
         $openId = $tools->GetOpenid();
         //             return ['status'=> -2 , 'message'=>'user_id错误'];
     }
     $input = new \WxPayUnifiedOrder();
     $input->SetBody($body);
     $input->SetAttach($attach);
     $input->SetOut_trade_no($order_sn);
     //\WxPayConfig::MCHID.date("YmdHis")
     $input->SetTotal_fee($total_fee);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetGoods_tag($goods_tag);
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = \WxPayApi::unifiedOrder($input);
     if ($order['return_code'] != 'SUCCESS') {
         return ['status' => -10, 'message' => $order['return_msg']];
     }
     $jsApiParameters = $tools->GetJsApiParameters($order);
     $this->addPayLog($openId, $order_id, $input);
     return ['status' => 1, 'message' => $jsApiParameters];
 }
Esempio n. 5
0
 public function unifiedorder($openId, $product_id)
 {
     //得到支付金额
     $order_pay_info = Model('order')->getOrderPayInfo(array('pay_sn' => $product_id));
     if (empty($order_pay_info)) {
         $condition = array();
         $condition['order_sn'] = $product_id;
         $condition['order_state'] = ORDER_STATE_NEW;
         $order_info = Model('vr_order')->getOrderInfo($condition, 'sum(order_amount-rcb_amount-pd_amount) as order_amount');
         $attach = 'v';
     } else {
         $condition = array();
         $condition['pay_sn'] = $product_id;
         $condition['order_state'] = ORDER_STATE_NEW;
         $order_info = Model('order')->getOrderInfo($condition, array(), 'sum(order_amount-rcb_amount-pd_amount) as order_amount');
         $attach = 'r';
     }
     //统一下单
     $input = new WxPayUnifiedOrder();
     $input->SetBody($product_id . '订单');
     // 		$input->SetBody(C('site_name').'订单');
     $input->SetAttach($attach);
     $input->SetOut_trade_no($product_id);
     $input->SetTotal_fee($order_info['order_amount'] * 100);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 3600));
     $input->SetGoods_tag('');
     $input->SetNotify_url(SHOP_SITE_URL . '/api/payment/wxpay/notify_url.php');
     $input->SetTrade_type("NATIVE");
     // 		$input->SetOpenid($openId);
     $input->SetProduct_id($product_id);
     $result = WxPayApi::unifiedOrder($input);
     Log::DEBUG("unifiedorder:" . json_encode($result));
     return $result;
 }
Esempio n. 6
0
 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);
 }
Esempio n. 7
0
 public function wxJsPay()
 {
     $list = isset($_SESSION['orderinfo']) ? $_SESSION['orderinfo'] : array();
     if (!isset($_SESSION['orderinfo'])) {
         header("Location:" . appurl('getMeOrder'));
         die;
     }
     //验证是否能预定
     if (isset($_SESSION['orderList'])) {
         foreach ($_SESSION['orderList'] as $key => $value) {
             $this->checkCanSum($value['bookid'], $value);
             if (!$this->checkBook($value['bookid'])) {
                 $this->alert($value['title'] . '已经售卖结束');
                 exit;
             }
         }
     }
     //初始化日志
     $logHandler = new CLogFileHandler("../logs/" . date('Y-m-d') . '.log');
     $log = Log::Init($logHandler, 15);
     //①、获取用户openid
     $tools = new JsApiPay();
     $openId = $tools->GetOpenid();
     //②、统一下单
     //价钱转成分
     $totalFee = $list['allPrice'] * 100;
     $input = new WxPayUnifiedOrder();
     $input->SetBody("订单");
     $input->SetAttach("订单");
     $input->SetOut_trade_no($list['orderid']);
     $input->SetTotal_fee($totalFee);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetGoods_tag("订单");
     $input->SetNotify_url(appurl('callBack'));
     // "http://paysdk.weixin.qq.com/example/notify.php"
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = WxPayApi::unifiedOrder($input);
     echo '<font color="#f00"><b>支付中,客官请稍后....</b></font><br/>';
     // $this->printf_info($order);
     $jsApiParameters = $tools->GetJsApiParameters($order);
     //获取共享收货地址js函数参数
     $editAddress = $tools->GetEditAddressParameters();
     //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
     /**
      * 注意:
      * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功
      * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”,
      * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html)
      */
     $data = array('jsApiParameters' => $jsApiParameters, 'editAddress' => $editAddress, 'orderid' => $list['orderid'], 'pageTitle' => '支付');
     unset($_SESSION['orderinfo']);
     $this->layoutRender('/wxpay', $data);
 }
Esempio n. 8
0
function getPrepayId($total_amount, $order_number, $attach)
{
    $input = new WxPayUnifiedOrder();
    $input->SetBody("美果优鲜订单");
    $input->SetAttach("缤纷水果");
    $input->SetOut_trade_no($attach);
    $input->SetTotal_fee($total_amount * 100);
    $input->SetAttach($order_number);
    $input->SetTime_start(date("YmdHis"));
    $input->SetTime_expire(date("YmdHis", time() + 600));
    $input->SetGoods_tag("商品标签");
    $input->SetNotify_url("https://dev1.meiguoyouxian.com/magento/custom/api/util/wx.php");
    $input->SetTrade_type("APP");
    $order = WxPayApi::unifiedOrder($input);
    return $order;
}
Esempio n. 9
0
 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;
 }
 public function unifiedorder($openId, $product_id)
 {
     //统一下单
     $input = new WxPayUnifiedOrder();
     $input->SetBody("test");
     $input->SetAttach("test");
     $input->SetOut_trade_no(WxPayConfig::MCHID . date("YmdHis"));
     $input->SetTotal_fee("1");
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetGoods_tag("test");
     $input->SetNotify_url(Config::API_NOTIFY_URL);
     $input->SetTrade_type("NATIVE");
     $input->SetOpenid($openId);
     $input->SetProduct_id($product_id);
     $result = WxPayApi::unifiedOrder($input, Config::API_TIMEOUT);
     Log::DEBUG("unifiedorder:" . json_encode($result));
     return $result;
 }
Esempio n. 11
0
 public function unifiedorder($openId, $product_id)
 {
     //统一下单
     $input = new WxPayUnifiedOrder();
     $input->SetBody("test");
     $input->SetAttach("test");
     $input->SetOut_trade_no(WxPayConfig::MCHID . date("YmdHis"));
     $input->SetTotal_fee("1");
     $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->SetOpenid($openId);
     $input->SetProduct_id($product_id);
     $result = WxPayApi::unifiedOrder($input);
     Log::DEBUG("unifiedorder:" . json_encode($result));
     return $result;
 }
 /**
  * [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();
 }
Esempio n. 13
0
File: Api.php Progetto: hejxing/jt
 /**
  * 统一下单
  *
  * @param $amount
  *
  * @return string
  */
 private function getUnifiedOrder($amount)
 {
     $tools = new \JsApiPay();
     $openId = $tools->GetOpenid();
     //获取用户openID
     $outTradeNo = \tools\Tools::uuid();
     $input = new \WxPayUnifiedOrder();
     $input->SetBody($this->data['memo']);
     $input->SetAttach($this->data['id']);
     $input->SetOut_trade_no($outTradeNo);
     $input->SetTotal_fee($this->amount);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetGoods_tag($this->data['memo']);
     $input->SetNotify_url($this->notify_url);
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = \WxPayApi::unifiedOrder($input);
     $jsApiParameters = $tools->GetJsApiParameters($order);
     //获取共享收货地址js函数参数
     $editAddress = $tools->GetEditAddressParameters();
     return ['jsApiParameters' => $jsApiParameters, 'editAddress' => $editAddress, 'amount' => $amount, 'orderId' => $this->data['id']];
 }
Esempio n. 14
0
 /**
  * 统一下单接口
  * 
  * @param array $order 站内订单数组
  * @param string $openId openid
  * @return string
  */
 public static function unifiedOrder(array $order, $openId = '')
 {
     if (empty($order)) {
         return '';
     }
     include_once WXPAY_SDK_ROOT . "unit/WxPay.JsApiPay.php";
     //获取用户openid
     $tools = new JsApiPay();
     if (empty($openId)) {
         $openId = $tools->GetOpenid();
     }
     $wx_order_body = '女神送花(' . $order['player_id'] . '号)';
     $order_detail = ($order['goods_type'] == 'flower' ? "送花(" : "送吻(") . $order['goods_amount'] . ")";
     /*
     if (!empty($order['order_goods'])) {
       foreach ($order['order_goods'] As $g) {
         $order_detail .= $g['goods_name'].'('.$g['goods_price'].'x'.$g['goods_number'].")\n";
         if (''==$wx_order_body) {
           $wx_order_body = mb_truncate($g['goods_name'], 27);
         }
       }
       $order_detail = rtrim($order_detail,"\n");
     }
     */
     //统一下单
     if (1 || empty($order['pay_data1'])) {
         //订单状态可能会被后台更改,所以同一订单每次支付都要重新生成提交信息
         if ('' == $wx_order_body) {
             $wx_order_body = '微信支付商品';
         }
         $now = time();
         $input = new WxPayUnifiedOrder();
         $input->SetBody($wx_order_body);
         $input->SetDetail($order_detail);
         $input->SetAttach('simphp');
         //商家自定义数据,原样返回
         $input->SetOut_trade_no($order['order_sn']);
         $input->SetTotal_fee(intval($order['order_amount'] * 100));
         //'分'为单位
         $input->SetTime_start(date('YmdHis', $now));
         $input->SetTime_expire(date('YmdHis', $now + 60 * 15));
         //15分钟内支付有效
         $input->SetGoods_tag('');
         //商品标记,代金券或立减优惠功能的参数
         $input->SetNotify_url(self::NOFIFY_URL);
         $input->SetTrade_type(self::TRADE_TYPE_JSAPI);
         $input->SetOpenid($openId);
         $order_wx = WxPayApi::unifiedOrder($input);
         //trace_debug('wxpay_order_wx', $order_wx);
         if ('SUCCESS' == $order_wx['return_code'] && 'SUCCESS' == $order_wx['result_code']) {
             //保存信息以防再次重复提交
             $wxpay_data = ['appid' => $order_wx['appid'], 'mch_id' => $order_wx['mch_id'], 'trade_type' => $order_wx['trade_type'], 'prepay_id' => $order_wx['prepay_id']];
             if (isset($order_wx['code_url'])) {
                 $wxpay_data['code_url'] = $order_wx['code_url'];
             }
             Goods::orderUpdate(['pay_data1' => json_encode($wxpay_data)], $order['order_id']);
         }
     } else {
         $order_wx = json_decode($order['pay_data1'], true);
     }
     $jsApiParameters = $tools->GetJsApiParameters($order_wx);
     return $jsApiParameters;
 }
Esempio n. 15
0
<?php

require dirname(dirname(dirname(__FILE__))) . '/include/common.inc.php';
require_once SLINEINC . "/view.class.php";
$pv = new View();
require_once "lib/WxPay.Api.php";
require_once "example/WxPay.NativePay.php";
require_once 'example/log.php';
$notify = new NativePay();
$input = new WxPayUnifiedOrder();
$input->SetBody($_POST['subject']);
$input->SetAttach("");
$input->SetOut_trade_no($_POST['ordersn']);
$input->SetTotal_fee($_POST['price'] * 100);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("");
$input->SetNotify_url($GLOBALS['cfg_basehost'] . '/thirdpay/weixinpay/notify.php');
$input->SetTrade_type("NATIVE");
$input->SetProduct_id($_POST['ordersn']);
$result = $notify->GetPayUrl($input);
$url2 = urlencode($result["code_url"]);
$templet = SLINEROOT . '/thirdpay/weixinpay/tpl/native.htm';
$pv->SetTemplet($templet);
$pv->Display();
exit;
?>

Esempio n. 16
0
    foreach ($data as $key => $value) {
        echo "<font color='#00ff55;'>{$key}</font> : {$value} <br/>";
    }
}
//①、获取用户openid
$tools = new JsApiPay();
$openId = $tools->GetOpenid();
//②、统一下单
$input = new WxPayUnifiedOrder();
$input->SetBody("6dygjsapi");
$input->SetAttach("6dygjsapi");
$input->SetOut_trade_no(WxPayConfig::MCHID . date("YmdHis"));
$input->SetTotal_fee("1");
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("6dygjsapi");
$input->SetNotify_url("http://mm.lmcity.cn/weipay/example/notify.php");
$input->SetTrade_type("JSAPI");
$input->SetOpenid($openId);
$order = WxPayApi::unifiedOrder($input);
echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';
printf_info($order);
$jsApiParameters = $tools->GetJsApiParameters($order);
//获取共享收货地址js函数参数
$editAddress = $tools->GetEditAddressParameters();
//③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
/**
 * 注意:
 * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功
 * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”,
 * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html)
Esempio n. 17
0
//模式二
/**
 * 流程:
 * 1、调用统一下单,取得code_url,生成二维码
 * 2、用户扫描二维码,进行支付
 * 3、支付完成之后,微信服务器会通知支付成功
 * 4、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php)
 */
$input = new WxPayUnifiedOrder();
$input->SetBody($title_name);
$input->SetAttach($title_name);
$input->SetOut_trade_no(WxPayConfig::MCHID . date("YmdHis"));
$input->SetTotal_fee("1");
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag($title_name);
$input->SetNotify_url("http://mm.lmcity.cn/weipay/example/notify.php");
$input->SetTrade_type("NATIVE");
$input->SetProduct_id($dingdannum);
$result = $notify->GetPayUrl($input);
$out_trade_no = WxPayConfig::MCHID . date("YmdHis");
$url2 = $result["code_url"];
$_SESSION['wei_out_trade_no'] = $out_trade_no;
// require_once "system/libs/model.class.php";
// $a = "select * from go_member_addmoney_record where code = 'C14447124090462440'";
// $b = mysql_query($a);
// $c = mysql_fetch_array($b);
// $a = model::weitest();
// print_r($a);
// exit();
?>
Esempio n. 18
0
 * 流程:
 * 1、调用统一下单,取得code_url,生成二维码
 * 2、用户扫描二维码,进行支付
 * 3、支付完成之后,微信服务器会通知支付成功
 * 4、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php)
 */
require_once 'getorderinfo.php';
try {
    $input = new WxPayUnifiedOrder();
    $input->SetBody($body);
    $input->SetAttach($body);
    $input->SetOut_trade_no($order_sn);
    $input->SetTotal_fee($money_paid);
    $input->SetTime_start($time_start);
    $input->SetTime_expire($time_expire);
    $input->SetGoods_tag($goods_tag);
    $input->SetNotify_url($notify_url);
    $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>
Esempio n. 19
0
     $event_reduce = $order_info['minus_amount'] + $order_info['pay_reduce'];
     $input = new WxPayUnifiedOrder();
     $input->SetBody(Config::WX_ORDER_TITLE);
     // 商品或支付单简要描述
     $input->SetAttach(PAY_ENV);
     // 设置附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
     $input->SetOut_trade_no($order_info['id']);
     // 商户系统内部的订单号,32个字符内
     $input->SetTotal_fee($pay_toatal_price);
     // 订单支付总金额,整数,以分为单位
     //$input->SetTotal_fee(1);
     $input->SetTime_start(date("YmdHis"));
     // 订单生成时间,格式为yyyyMMddHHmmss
     $input->SetTime_expire(date("YmdHis", time() + Config::WX_ORDER_TIMEOUT));
     // 订单失效时间,格式为yyyyMMddHHmmss
     $input->SetGoods_tag(Config::WX_ORDER_TAG);
     // 设置商品标记
     $input->SetNotify_url(Config::API_NOTIFY_URL);
     // 接收微信支付异步通知回调地址
     $input->SetTrade_type("JSAPI");
     // 交易类型
     $input->SetOpenid($openId);
     // 微信用户的Openid
     $order = WxPayApi::unifiedOrder($input, Config::API_TIMEOUT, Config::API_NOTIFY_URL);
     // 创建预付订单
     $jsApiParameters = $tools->GetJsApiParameters($order);
     // 获取共享收货地址js函数参数
     //$editAddress = $tools->GetEditAddressParameters();
 } else {
     throw new Exception('order_info requrired,but empty be given');
 }
Esempio n. 20
0
 /**
  *
  */
 public function jsApiParametersGet_action($mpid, $order)
 {
     $user = $this->getUser($mpid);
     $order = $this->model('app\\merchant\\order')->byId($order);
     if (false === $order) {
         return new \ResponseError('订单不存在');
     }
     $products = array();
     $order->products = json_decode($order->products);
     foreach ($order->products as $prod) {
         $products[] = $prod->name;
     }
     $products = implode(',', $products);
     $notifyUrl = "http://" . $_SERVER['HTTP_HOST'];
     $notifyUrl .= "/rest/op/merchant/payok/notify";
     $tools = $this->model('mpproxy/WxPayJsApi');
     $wxPayConfig = new \WxPayConfig($mpid);
     $input = new \WxPayUnifiedOrder();
     $input->SetBody($products);
     $input->SetAttach("测试附加信息");
     $input->SetOut_trade_no($order->trade_no);
     $input->SetTotal_fee($order->order_total_price);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetGoods_tag("测试标签");
     $input->SetNotify_url($notifyUrl);
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($user->openid);
     $order = \WxPayApi::unifiedOrder($mpid, $input);
     if ($order['result_code'] === 'FAIL') {
         return new \ResponseError($order['err_code_des']);
     }
     $jsApiParameters = $tools->GetJsApiParameters($mpid, $order);
     //获取共享收货地址js函数参数
     $editAddress = $tools->GetEditAddressParameters($mpid);
     $rsp = array('jsApiParameters' => $jsApiParameters, 'editAddress' => $editAddress);
     return new \ResponseData($rsp);
 }
Esempio n. 21
0
 public function index()
 {
     //初始化日志
     $this->load->library('wxpaylog');
     $this->logHandler = new CLogFileHandler(DIR_LOGS . "wxpaylogs/" . date('Y-m-d') . '.log');
     $log = WxPayLog::Init($this->logHandler, 15);
     $this->language->load('payment/wxpay');
     $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');
     $amount = $order_info['total'];
     $currency_value = $this->currency->getValue('CNY');
     $price = $amount * $currency_value;
     $price = number_format($price, 2, '.', '');
     $notify_url = HTTPS_SERVER . 'catalog/controller/payment/wxpay_callback.php';
     //$total_fee = $price;
     $total_fee = "0.01";
     $out_trade_no = $this->session->data['order_id'];
     $subject = $item_name . ' ' . $this->language->get('text_order') . ' ' . $order_id;
     //打印输出数组信息
     function printf_info($data)
     {
         foreach ($data as $key => $value) {
             echo "<font color='#00ff55;'>{$key}</font> : {$value} <br/>";
         }
     }
     //①、获取用户openid
     $this->load->library('wxpayapipay');
     $this->tools = new WxPayApiPay();
     $openId = $this->tools->GetOpenid();
     //②、统一下单
     $input = new WxPayUnifiedOrder();
     $input->SetBody($subject);
     $input->SetAttach("YANKEE");
     $input->SetOut_trade_no(WxPayConfig::MCHID . date("YmdHis"));
     $input->SetTotal_fee($total_fee);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetGoods_tag("test");
     $input->SetNotify_url($notify_url);
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     //$input->SetOpenid("oCrCkwElKC4YuFiAYe0EvPKa-OEg");
     $this->load->library('wxpayapi');
     $this->wxpayapi = new WxPayApi();
     $order = $this->wxpayapi->unifiedOrder($input);
     //echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';
     //printf_info($order);
     $jsApiParameters = $this->tools->GetJsApiParameters($order);
     //获取共享收货地址js函数参数
     $editAddress = $this->tools->GetEditAddressParameters();
     //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
     /**
      * 注意:
      * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功
      * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”,
      * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html)
      */
     //$data['html_text'] = $this->alipaydtsubmit->buildRequestForm($parameter,"get", $this->language->get('button_confirm'));
     $data['jsApiParameters'] = isset($jsApiParameters) ? $jsApiParameters : "111";
     $data['editAddress'] = isset($editAddress) ? $editAddress : "111";
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/wxpay.tpl')) {
         return $this->load->view($this->config->get('config_template') . '/template/payment/wxpay.tpl', $data);
     } else {
         return $this->load->view('default/template/payment/wxpay.tpl', $data);
     }
 }
Esempio n. 22
0
//模式二
/**
 * 流程:
 * 1、调用统一下单,取得code_url,生成二维码
 * 2、用户扫描二维码,进行支付
 * 3、支付完成之后,微信服务器会通知支付成功
 * 4、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php)
 */
$input = new WxPayUnifiedOrder();
$input->SetBody("pay1");
$input->SetAttach("pay1");
$input->SetOut_trade_no(WxPayConfig::MCHID . date("YmdHis"));
$input->SetTotal_fee("1");
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("pay1");
$input->SetNotify_url("http://mm.lmcity.cn/pay1/example/notify.php");
$input->SetTrade_type("NATIVE");
$input->SetProduct_id($dingdan);
$result = $notify->GetPayUrl($input);
$url2 = $result["code_url"];
?>

<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1" /> 
    <title>微信支付样例-退款</title>
</head>
<body>
	<!--<div style="margin-left: 10px;color:#556B2F;font-size:30px;font-weight: bolder;">扫描支付模式一</div><br/>
 protected function create_order($user_id, $trade_type, $attach, $fee, $open_id = null)
 {
     // 商户号 + 用户id + uniqid生成的随机字符串
     $out_trade_no = WxPayConfig::MCHID . uniqid($user_id);
     // 需重置下当前时区,PHP配置文件不知为何不起作用
     //date_default_timezone_set('PRC');
     // 统一下单
     $input = new WxPayUnifiedOrder();
     $input->SetBody("挂号费");
     $input->SetAttach($attach);
     $input->SetOut_trade_no($out_trade_no);
     // 测试用1分钱
     $input->SetTotal_fee(1);
     $current_time = time();
     $start = date('YmdHis', $current_time);
     $expire = date('YmdHis', $current_time + 3600);
     // 下单时间:当前时间
     $input->SetTime_start($start);
     // 失效时间:测试用一个小时
     $input->SetTime_expire($expire);
     $input->SetGoods_tag("挂号费");
     $input->SetNotify_url("http://test.zerioi.com/pay/wxpay_notify");
     $input->SetTrade_type($trade_type);
     // JSAPI调用支付需设置open_id
     if ($open_id) {
         $input->SetOpenid($open_id);
     }
     $record = new WeixinPay();
     $record->trade_no = $out_trade_no;
     $record->trade_type = $trade_type;
     $record->time_start = $start;
     $record->time_expire = $expire;
     $record->user_id = $user_id;
     $record->open_id = $open_id;
     $record->attach = $attach;
     $record->total_fee = $fee;
     $record->status = 'UNFINISHED';
     if (!$record->save()) {
         throw new Exception("Could not save pay parameters");
     }
     return WxPayApi::unifiedOrder($input);
 }
Esempio n. 24
0
 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);
     }
 }
 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');
     }
 }
Esempio n. 26
0
 public function doMobileAjaxpay()
 {
     global $_GPC, $_W;
     load()->func('communication');
     $fromopenid = $_GPC['fromopenid'];
     $myopenid = $_W['openid'];
     $num = 1;
     $content = $_GPC['content'];
     include_once '../addons/beauty_zhongchou/WxPay.Api.php';
     $WxPayApi = new WxPayApi();
     $input = new WxPayUnifiedOrder();
     //				$key=$this->module['config']['apikey'];//商户支付秘钥(API秘钥)
     $key = 'xLeBESmggiQMGpba2ieADmRQDlDPmIL8';
     $account_info = pdo_fetch("select * from" . tablename('account_wechats') . "where uniacid={$_W['uniacid']}");
     //身份标识(appid)
     $appid = $account_info['key'];
     //$mchid=$this->module['config']['mchid'];//微信支付商户号(mchid)
     $mchid = '1239385202';
     $input->SetAppid($appid);
     $input->SetMch_id($mchid);
     $input->SetBody("test");
     $input->SetAttach("test");
     $input->SetOut_trade_no($mchid . date("YmdHis"));
     $input->SetTotal_fee($num);
     $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("JSAPI");
     $input->SetOpenid($myopenid);
     $result = $WxPayApi->unifiedOrder($input, 6, $key);
     //随机字符串
     $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
     $str = "";
     for ($i = 0; $i < 32; $i++) {
         $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
     }
     //签名
     $sign = $input->SetSign($key);
     $data = array();
     $data['pack'] = $result['prepay_id'];
     $data['appId'] = $appid;
     $data['timeStamp'] = TIMESTAMP;
     $data['nonceStr'] = $str;
     $data['signType'] = "MD5";
     $data['paySign'] = $sign;
     //生成订单
     //		$data2 = array(
     //			'uniacid' => $_W['uniacid'],
     //			'openid' => $myopenid,
     //			'ordersn' => date('Ymd').substr(time(), -5).substr(microtime(), 2, 5).sprintf('%02d', rand(0, 99)),
     //			'content'=>$content,
     //			'num' => $num,
     //			'status' => 0,//订单状态,-1取消状态,0普通状态,1为已付款,2为已发货,3为成功
     //			'fromopenid'=>$fromopenid,
     //			'content'=>
     //			'createtime' => TIMESTAMP
     //		);
     pdo_insert('beatuty_zhongchou_orders', $data2);
     $orderid = pdo_insertid();
     $order = pdo_fetch("SELECT * FROM " . tablename('beatuty_zhongchou_orders') . " WHERE id ={$orderid}");
     $params['tid'] = $order['ordersn'];
     $params['user'] = $_W['fans']['from_user'];
     $params['fee'] = $order['num'];
     $params['title'] = $_W['account']['name'];
     $params['ordersn'] = $order['ordersn'];
     $params['module'] = "beatuty_zhongchou";
     //转成json
     $dataall = array('data' => $data, 'params' => $params);
     return json_encode($dataall);
 }
Esempio n. 27
0
 public function index()
 {
     //echo "one";
     $this->load->library('wxpayexception');
     //echo "two";
     $this->load->library('wxpayconfig');
     //echo "three";
     $this->load->library('wxpaydata');
     //echo "four";
     $this->load->library('wxpayapi');
     //echo "five";
     $this->load->library('wxpayjsapipay');
     //echo "six";
     //echo "1";
     /*
     WxPayConfig::$APPID = $this->config->get('wxpay_appid');
     	    WxPayConfig::$MCHID = $this->config->get('wxpay_mchid');
     	    WxPayConfig::$KEY = $this->config->get('wxpay_key');
     WxPayConfig::$APPSECRET = $this->config->get('wxpay_appsecret');
     WxPayConfig::$SSLCERT_PATH = DIR_SYSTEM.'helper/wxpay_key/apiclient_cert.pem';
     WxPayConfig::$SSLKEY_PATH = DIR_SYSTEM.'helper/wxpay_key/apiclient_key.pem';
     */
     //echo "2";
     $this->language->load('payment/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/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
     $tools = new JsApiPay();
     //$openId = $tools->GetOpenid();
     $openId = $this->session->data['weixin_openid'];
     //echo "4<br>";
     //echo $openId;
     //②、统一下单
     $input = new WxPayUnifiedOrder();
     //echo "5";
     $input->SetBody($subject);
     $input->SetAttach("test by yang");
     $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("test goods tags");
     $input->SetNotify_url($notify_url);
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     //echo "6";
     $order = WxPayApi::unifiedOrder($input);
     //print_r($order);
     //echo "7";
     //echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';
     //printf_info($order);
     $data['jsApiParameters'] = $tools->GetJsApiParameters($order);
     //echo "8";
     //获取共享收货地址js函数参数
     $data['editAddress'] = $tools->GetEditAddressParameters();
     //echo "9";
     $data['return_url'] = $this->url->link('checkout/success');
     $data['checkout_url'] = $this->url->link('checkout/checkout');
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/wxpay.tpl')) {
         return $this->load->view($this->config->get('config_template') . '/template/payment/wxpay.tpl', $data);
     } else {
         return $this->load->view('default/template/payment/wxpay.tpl', $data);
     }
 }
Esempio n. 28
0
  private function wxJsPay($request)
  {
    $state = $request->input('state');

    $decodeObject = json_decode($state);

    $user = Auth::user();

    $order_code = $decodeObject->order_code;

    $order = Order::where('code', '=', $order_code)->first();

    if (empty($order->id)) {
    
      //todo
    
    } else if ($order->status > 0) {
    
      return view('mobile/payed');
    
    }

    $good = Good::where('id', '=', $order->gid)->first();

    $orderPrice = OrderPrice::where('oid', '=', $order->id)->first();

    $receiver = ReceiverInfo::find($order->rid);

    require_once "lib/WxPay.Api.php";  

    require_once "lib/WxPay.JsApiPay.php";

    $notify_url = $this->debug ? "http://www.51linpai.com:8000/order/wxpay/" : "http://www.51linpai.com/order/wxpay/";

    $tools = new \JsApiPay();

    $openId = $tools->GetOpenid("", null);

    $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("JSAPI");
    $input->SetOpenid($openId);
    $jsWxOrder = \WxPayApi::unifiedOrder($input);
    $jsApiParameters = $tools->GetJsApiParameters($jsWxOrder);

    //获取共享收货地址js函数参数
    $editAddress = $tools->GetEditAddressParameters();

    $data = [

        'editAddress' => $editAddress,

        'jsApiParameters' => $jsApiParameters,

        'order_code' => $order->code,

        'price' => $orderPrice->final_price,

        'address' =>  $receiver->city . ' ' . $receiver->district . ' ' . $receiver->address,

        'step' => 4,

        'header' => '支付订单'
      
      ];
    
    return view('mobile/wechat_js_pay', $data);
  
  }
Esempio n. 29
0
if ($bag != 0) {
    $str .= '手提袋x' . $bag . ',';
}
if ($battery != 0) {
    $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>
Esempio n. 30
0
    file_put_contents("log.txt", "\n\n参数错误", FILE_APPEND);
    echo json_encode(array("code" => 0, "msg" => "参数错误"));
    return false;
}
//①、获取用户openid
//$tools = new JsApiPay();
//$openId = $tools->GetOpenid();
//②、统一下单   请求微信预下单
$input = new WxPayUnifiedOrder();
$input->SetBody($goodsName);
$input->SetAttach("test");
$input->SetOut_trade_no(WxPayConfig::MCHID . date("YmdHis"));
$input->SetTotal_fee($totalFee);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 7200));
$input->SetGoods_tag("test_goods");
$input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php");
$input->SetTrade_type("APP");
//$input->SetOpenid($openId);
$order = WxPayApi::unifiedOrder($input);
//echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';
//printf_info($order);
//判断微信生成预支付后的返回值-----
//返回状态码	return_code
//返回信息	return_msg
if ($order['return_code'] == 'FAIL') {
    file_put_contents("log.txt", "\n\n" . print_r("统一下单失败,请查看微信统一下单文档相关说明", 1), FILE_APPEND);
    echo json_encode(array('code' => 0, 'msg' => $order['return_msg']));
    return false;
} else {
    //这里是写入数据库业务逻辑(信息在统一订单接口文档中)