示例#1
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];
 }
示例#2
0
文件: weizhao.php 项目: ysc8620/zhima
/**
 * 生成支付接口内容
 * @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;
}
示例#3
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);
 }
示例#4
0
 public function getJsApiParameters($out_trade_no = '', $fee = '', $openId = '')
 {
     $input = new WxPayUnifiedOrder();
     $input->SetBody("购买相册打印服务");
     $input->SetOut_trade_no($out_trade_no);
     $input->SetTotal_fee($fee);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetNotify_url('http://api.dayinxiangsh.com/1.0/pay/callback');
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = WxPayApi::unifiedOrder($input);
     $jsApiParameters = $this->getParameters($order);
     return $jsApiParameters;
 }
 public function createUnifiedOrder($out_trade_no, $subject, $total_fee, $open_id = null)
 {
     //②、统一下单
     $input = new \WxPayUnifiedOrder();
     $input->setWxPayApi($this->wxPayApi);
     $input->SetBody($subject);
     $input->SetOut_trade_no($out_trade_no);
     //        $input->SetTotal_fee($total_fee);
     $input->SetTotal_fee(intval($total_fee * 100));
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetTrade_type($this->trade_type);
     if ($open_id) {
         $input->SetOpenid($open_id);
     }
     $order = $this->wxPayApi->unifiedOrder($input);
     return $order;
 }
示例#6
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;
 }
 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;
 }
示例#8
0
文件: Api.php 项目: 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']];
 }
示例#9
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);
 }
 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);
 }
示例#11
0
 /**
  *
  * jsApi微信支付示例
  * 注意:
  * 1、微信支付授权目录配置如下  http://www.youweihui.net/addon/Wxpay/Index/jsApiPay/mp_id/
  * 2、支付页面地址需带mp_id参数
  * 3、管理后台-基础设置-公众号管理,微信支付必须配置的参数都需填写正确
  * @param array $mp_id 公众号在系统中的ID
  * @return 将微信支付需要的参数写入支付页面,显示支付页面
  */
 public function jsApiPay()
 {
     $uid = get_ucuser_uid();
     //获取粉丝用户uid,一个神奇的函数,没初始化过就初始化一个粉丝
     if ($uid === false) {
         $this->error('只可在微信中访问');
     }
     $user = get_uid_ucuser($uid);
     //获取本地存储公众号粉丝用户信息
     $this->assign('user', $user);
     $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $surl = get_shareurl();
     if (!empty($surl)) {
         $this->assign('share_url', $surl);
     }
     //odata通用订单数据,订单数据可以从订单页面提交过来
     $odata['uid'] = $uid;
     $odata['mp_id'] = $params['mp_id'];
     // 当前公众号在系统中ID
     $odata['order_id'] = "time" . date("YmdHis");
     //
     $odata['order_status'] = 1;
     //不带该字段-全部状态, 2-待发货, 3-已发货, 5-已完成, 8-维权中
     $odata['order_total_price'] = 1;
     //订单总价,单位:分
     $odata['buyer_openid'] = $user['openid'];
     $odata['buyer_nick'] = $user['nickname'];
     $odata['receiver_mobile'] = $user['mobile'];
     $odata['product_id'] = 1;
     $odata['product_name'] = "UCToo";
     $odata['product_price'] = 100;
     //商品价格,单位:分
     $odata['product_sku'] = "UCToo_Wxpay";
     $odata['product_count'] = 1;
     $odata['module'] = MODULE_NAME;
     $odata['model'] = "order";
     $odata['aim_id'] = 1;
     $order = D("Order");
     // 实例化order对象
     $order->create($odata);
     // 生成数据对象
     $result = $order->add();
     // 写入数据
     if ($result) {
         // 如果主键是自动增长型 成功后返回值就是最新插入的值
     }
     //获取公众号信息,jsApiPay初始化参数
     $info = get_mpid_appinfo($odata['mp_id']);
     $this->options['appid'] = $info['appid'];
     $this->options['mchid'] = $info['mchid'];
     $this->options['mchkey'] = $info['mchkey'];
     $this->options['secret'] = $info['secret'];
     $this->options['notify_url'] = $info['notify_url'];
     $this->wxpaycfg = new WxPayConfig($this->options);
     //①、初始化JsApiPay
     $tools = new JsApiPay($this->wxpaycfg);
     $wxpayapi = new WxPayApi($this->wxpaycfg);
     //②、统一下单
     $input = new WxPayUnifiedOrder($this->wxpaycfg);
     //这里带参数初始化了WxPayDataBase
     //  $input->SetAppid($info['appid']);//公众账号ID
     //  $input->SetMch_id($info['mchid']);//商户号
     $input->SetBody($odata['product_name']);
     $input->SetAttach($odata['product_sku']);
     $input->SetOut_trade_no($odata['order_id']);
     $input->SetTotal_fee($odata['order_total_price']);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     // $input->SetGoods_tag("WXG");                      //商品标记,代金券或立减优惠功能的参数
     //  $input->SetNotify_url($info['notify_url']);       //http://test.uctoo.com/index.php/UShop/Index/notify
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($user['openid']);
     $order = $wxpayapi->unifiedOrder($input);
     $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)
      */
     $this->assign('order', $odata);
     $this->assign('jsApiParameters', $jsApiParameters);
     $this->assign('editAddress', $editAddress);
     $this->display();
 }
示例#12
0
 /**
  *
  * 生成预支付订单
  * @param data
  *  + body
  *  + out_trade_no
  *  + total_fee
  *  + product_id
  *  + time_expire
  *  + attach
  *  + openid
  */
 public static function getUnifiedOrder($data)
 {
     $input = new WxPayUnifiedOrder();
     // 商品描述
     $body = '商品付款';
     if ($data['body']) {
         $body = $data['body'];
     }
     $input->SetBody($body);
     // 商户订单号
     $input->SetOut_trade_no($data['out_trade_no']);
     // 订单交易总额
     $input->SetTotal_fee($data['total_fee']);
     // 商品ID
     if ($data['product_id']) {
         $input->SetProduct_id($data['product_id']);
     }
     $input->SetTime_start(date("YmdHis", $data['time_start']));
     // 订单过期时间,微信最长过期时间可设置为 2 小时,最短为5分钟
     $input->SetTime_expire(date("YmdHis", strtotime($data['time_start']) + 7200));
     // 订单通知回调的 url
     $input->SetNotify_url(WxPayConfig::$notify_url);
     // 支付类型:扫码支付
     $input->SetTrade_type($data['trade_type']);
     // 选填参数设置
     if ($data['attach']) {
         $input->SetAttach($data['attach']);
     }
     // 扫码支付模式一,第一次微信回调会带有用户的 openid,请求生成预支付 id 时需要加入到请求参数内
     if ($data['openid']) {
         $input->SetOpenid($data['openid']);
     }
     return $input;
 }
示例#13
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);
  
  }
示例#14
0
 /**
  * 微信支付
  * @param $orderId
  * @return array
  * @throws \WxPayException
  */
 public function weiXinPay($orderId)
 {
     //①、获取用户openid
     $tools = new \JsApiPay();
     $openId = $tools->GetOpenid();
     if ($openId == -1) {
         return false;
     }
     //②、统一下单
     $orderInfo = ChargeOrder::getInstance()->getOne($orderId);
     $goods = ChargeGoods::getInstance()->getOne($orderInfo['charge_goods_id']);
     $input = new \WxPayUnifiedOrder();
     $input->SetBody("嘉瑞百合缘-【" . $goods['name'] . "】");
     $input->SetAttach("手机网站");
     $input->SetOut_trade_no($orderInfo['order_id']);
     $input->SetTotal_fee((string) $orderInfo['money']);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetNotify_url("http://wechat.baihey.com/wap/charge/notify-url");
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = \WxPayApi::unifiedOrder($input);
     $jsApiParameters = $tools->GetJsApiParameters($order);
     return ['orderInfo' => $orderInfo, 'jsApiParameters' => $jsApiParameters];
 }
示例#15
0
 public function pay()
 {
     require_once 'Weixinpay/WxPayData.class.php';
     require_once 'Weixinpay/WxPayApi.class.php';
     require_once 'Weixinpay/WxPayJsApiPay.php';
     // require_once ('Weixinpay/log.php');
     $paymentId = $_GET['paymentId'];
     $token = $_GET['token'];
     $body = $_GET['orderName'];
     $orderNo = $_GET['orderNumber'];
     if ($orderNo == "") {
         $orderNo = $_GET['single_orderid'];
     }
     $totalFee = $_GET['price'] * 100;
     // 单位为分
     // $paytype=$_GET['paytype'];
     $tools = new \JsApiPay();
     // $openId = $tools->GetOpenid();
     // $openId=$_GET['wecha_id'];
     // $openId=get_openid();
     // dump($openId);
     // die();
     // // dump($openId);
     //         $openId='orgF0t-HyMrDJHFOl9GAkENyu6i0';
     // dump('45456');
     $openId = $this->getPaymentOpenid();
     //         dump(session('paymentinfo'));
     //         dump($openId);
     //         dump('1232');die;
     // 统一下单
     import('Weixinpay.WxPayData');
     $input = new \WxPayUnifiedOrder();
     $input->SetBody($body);
     // $input->SetAttach("test");
     $input->SetOut_trade_no($orderNo);
     $input->SetTotal_fee($totalFee);
     // $input->SetTime_start(date("YmdHis"));
     // $input->SetTime_expire(date("YmdHis", time() + 600));
     // $input->SetGoods_tag("test");
     $input->SetNotify_url("Weixinpay/notify.php");
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = \WxPayApi::unifiedOrder($input);
     //         echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';
     //dump($order);
     //         die;
     $jsApiParameters = $tools->GetJsApiParameters($order);
     //  dump($jsApiParameters);
     $returnUrl = addons_url('Payment://Weixin/payOK');
     header('Location:' . SITE_URL . '/WxpayAPI/unifiedorder.php?jsApiParameters=' . $jsApiParameters . '&returnurl=' . $returnUrl . '&totalfee=' . $_GET['price'] . '&paymentId=' . $paymentId);
     // echo $jsApiParameters;
     // die;
     // session('jsaparams',$jsApiParameters);
     // $_COOKIE['jsaparams']=$jsApiParameters;
     // $from=$_GET['from'];
     // if($from!='shop'){
     // $from=$this->doFromStr($_GET['from']);
     // }
     // //$returnUrl = '/index.php?g=Wap&m=' . $from . '&a=payReturn&token=' . $_GET ['token'] . '&wecha_id=' . $_GET ['wecha_id'] . '&orderid=' . $orderNo;
     // $returnUrl=addons_url('Payment://Weixin/payOK');
     // //$this->assign ( 'returnUrl', $returnUrl );
     // $this->assign ( 'jsApiParameters', $jsApiParameters );
     // $this->assign ( 'price', $_GET['price'] );
     // die;
     // header('Location:http://'.$_SERVER['HTTP_HOST'].'/weishi/WxpayAPI/unifiedorder.php?body='.$body.'&out_trade_no='.$orderNo.'&totalfee='.$totalFee.'&openid='.$openId.'&returnurl='.$returnUrl);
 }
示例#16
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);
     }
 }
示例#17
0
文件: main.php 项目: blackloong/Web
//价格列表与财神数量对应
$gMeetPays = array(188, 388, 688, 688, 888, 888, 888);
//$gMeetPays = array(1, 1, 1, 1, 1, 1, 1);
$gMeetNames = array("文财神", "武财神", "北路财神", "南路财神", "西路财神", "东路财神", "偏财神");
$gMeetPayIndex = rand(0, count($gMeetPays) - 1);
$gOrder = new WxPayUnifiedOrder();
$gOrder->SetBody("TestBody");
$gOrder->SetAttach("TestAttach");
$gOrder->SetOut_trade_no(WxPayConfig::MCHID . date("YmdHis"));
$gOrder->SetTotal_fee($gMeetPays[$gMeetPayIndex]);
$gOrder->SetTime_start(date("YmdHis"));
$gOrder->SetTime_expire(date("YmdHis", time() + 600));
$gOrder->SetGoods_tag("testGoodsTag");
$gOrder->SetNotify_url("http://shihaijiang.com/MeetWealthGods/WxPayNotify.php");
$gOrder->SetTrade_type("JSAPI");
$gOrder->SetOpenid($user_info->openid);
//创建统一订单
$gUnifiedOrder = WxPayApi::unifiedOrder($gOrder);
//根据统一订单生成JS订单数据
$gWxPayJsApiParameters = $gWxPayJSApi->GetJsApiParameters($gUnifiedOrder);
//定义js使用的变量
$gAppID = WxBaseConfig::AppID;
echo "<script type='text/javascript'>\n\t\t\t  var appid = '{$gAppID}';\n\t          var nickname = '{$user_info->nickname}';\n\t\t\t  var headimgurl = '{$user_info->headimgurl}';\n\t\t\t  var strTile = '正月十五接财神 一年发大财 ';\n\t\t\t  var strDescription = '我今年的守护财神是' + '{$gMeetNames[$gMeetPayIndex]}' + ',快来请你的财神吧!';\n\t\t\t  var urlIcon = 'http://shihaijiang.com/MeetWealthGods/img/icon.jpg';\n\t\t\t  var urlLink = 'http://shihaijiang.com/MeetWealthGods';\n\t\t\t  var timestamp = '{$gWxShareConfig->timestamp}';\n\t\t\t  var noncestr = '{$gWxShareConfig->noncestr}';\n\t\t\t  var nonceStr = '{$gWxShareConfig->noncestr}';\n\t\t\t  var signature = '{$gWxShareConfig->signature}';\n\t\t\t  var gWxPayJsApiParameters = '{$gWxPayJsApiParameters}';\n\t\t\t  var gMeetPayIndex = '{$gMeetPayIndex}';\n              var gMeetPay = {$gMeetPays[$gMeetPayIndex]};\n\t  </script>";
echo "<script src='http://res.wx.qq.com/open/js/jweixin-1.0.0.js'></script>";
echo "<script src='js/WxShare.Config.js'></script>";
echo "<script src='js/jquery.min.js'></script>";
echo "<script src='js/main_script.js'></script>";
//echo '<pre>';
//print_r(time());
//print_r(435345);
//echo '</pre>';
示例#18
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;
 }
示例#19
0
 public function thirdpay()
 {
     $orderno = $_POST['orderno'] . '';
     if ($orderno) {
         session("orderno", $orderno);
         $Body = $_POST['goodsName'] . '';
         $accountmoney = $_POST['accountmoney'];
         //帐户余额支付
         $accountscore = $_POST['accountscore'];
         //低扣积分
         $tfee = $_POST['amount'];
         //三方支付金额
         $paytype = $_POST['paytype'] . '';
         //三方支付金额
         $mMPay = D('M/MemberPay');
         $dataInfo = $mMPay->GetByPayNo($orderno);
         $dataInfo['amount'] = $tfee;
         $dataInfo['amountStatus'] = 0;
         $dataInfo['accountmoney'] = $accountmoney;
         $dataInfo['accountmoneyStatus'] = 0;
         $dataInfo['accountscore'] = $accountscore;
         $dataInfo['accountscoreStatus'] = 0;
         $dataInfo['thirdpaytype'] = $paytype;
         $rdpay = $mMPay->UpdatePay($dataInfo);
         if ($rdpay['status'] !== 1) {
             echo '更新状态失败。' . $rd['status'];
             $this->display();
             return;
         }
     } else {
         $orderno = session("orderno");
         if (empty($orderno)) {
             $this->display("Pay/error");
             return;
         }
         $mMPay = D('M/MemberPay');
         $dataInfo = $mMPay->GetByPayNo($orderno);
         if (empty($dataInfo)) {
             return;
         }
         $tfee = $dataInfo['amount'];
         $accountmoney = $dataInfo['accountmoney'];
         $accountscore = $dataInfo['accountscore'];
         $paytype = $dataInfo['thirdpaytype'];
     }
     if ($dataInfo["Status"] == 99) {
         $this->display("Pay/success");
         return;
     }
     //		//更新各支付金额
     if ($paytype == "wx") {
         vendor('Weixinpay.WxPayJsApiPay');
         //
         //			//1、获取openid
         $tools = new \JsApiPay();
         $openId = $tools->GetOpenid();
         $this->assign('money', $tfee);
         $tfee = $tfee * 100;
         //整数单位为分
         $uid = (int) session("uid");
         if ($uid == 104) {
             $tfee = 1;
         }
         $this->assign('title', $Body);
         //
         $Body = "订单支付";
         if ($dataInfo["PayType"] == "recharge") {
             $subject = '粗卡充值';
             $body = '粗卡充值';
         }
         $input = new \WxPayUnifiedOrder();
         $input->SetBody($Body);
         $input->SetAttach($orderno);
         $input->SetOut_trade_no(\WxPayConfig::MCHID . date("YmdHis"));
         $input->SetTotal_fee($tfee);
         $input->SetTime_start(date("YmdHis"));
         $input->SetTime_expire(date("YmdHis", time() + 600));
         $input->SetGoods_tag("Goods");
         $input->SetNotify_url("http://cukayun.cn/index.php/M/Pay/notify/");
         //支付回调地址,这里改成你自己的回调地址。
         $input->SetTrade_type("JSAPI");
         $input->SetOpenid($openId);
         //			echo dump($input);
         $order = \WxPayApi::unifiedOrder($input);
         //			echo dump($order);
         $jsApiParameters = $tools->GetJsApiParameters($order);
         $this->jsApiParameters = $jsApiParameters;
         //与用户的openid作一个比较
         $this->display("thirdpay");
     } else {
         header('Location:' . U('PayAli/index', '', '') . "/orderno/{$orderno}");
     }
 }
示例#20
0
文件: jsapi.php 项目: king3388/king
}
//①、获取用户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)
 */
?>
示例#21
0
 public function actionCompany()
 {
     try {
         $list = Yii::app()->user->orderlist;
         $date = Yii::app()->user->orderdate;
         $months = Yii::app()->user->ordermonths;
     } catch (Exception $e) {
         echo 'fail';
         die;
     }
     if (Yii::app()->user->isGuest) {
         $userId = Yii::app()->session['user']['id'];
     } else {
         $userId = Yii::app()->user->id;
     }
     $wechat = Yii::app()->params['partner']['wechat'];
     $jsapi = new WxJsPayHelper();
     $openid = $jsapi->GetOpenid();
     $this->bodyCss = 'orderDetail';
     $totalPrice = 0;
     foreach ($list as &$value) {
         $product = CompanyProduct::model()->findByAttributes(array('id' => $value['id']));
         $value['name'] = $product->name;
         $value['price'] = $product->price;
         $value['type'] = $product->type;
         $totalPrice = $totalPrice + $value['price'] * $value['num'];
     }
     $order = new COrder();
     $newOrder = $order->create(array('userId' => $userId, 'type' => 2, 'price' => $totalPrice, 'orderTime' => date('YmdHis'), 'hubId' => 1));
     $orderId = $newOrder['data']['orderId'];
     $endDate = date('Y-m-d', strtotime($date) + (date('t', strtotime($date)) - 1) * $months * 60 * 60 * 24);
     foreach ($list as $v) {
         $companyProduct = $order->createCompanyProduct(array('cproductId' => $v['id'], 'startDate' => $date, 'endDate' => $endDate, 'orderId' => $orderId, 'num' => $v['num']));
         Coding::makeCode(array('userId' => $userId, 'type' => $v['type'], 'startDate' => $date, 'endDate' => $endDate, 'times' => $v['num'], 'ordercompanyProductId' => $companyProduct['data']['id']));
     }
     $input = new WxPayUnifiedOrder();
     $input->SetBody('Company product');
     // $input->SetAttach(date('Ymd',$date));
     $input->SetOut_trade_no((string) $orderId);
     $input->SetTotal_fee($totalPrice / 100);
     $input->SetTime_start(date('YmdHis'));
     $input->SetTime_expire(Assist::getOrderExpireTime(time()));
     $input->SetProduct_id(1);
     $input->SetNotify_url('http://hubapp.livenaked.com' . $wechat['payment']['notify']);
     $input->SetTrade_type('JSAPI');
     $input->SetOpenid($openid);
     Yii::log(print_r($input->values, 1), CLogger::LEVEL_ERROR, 'input');
     $bill = WxPayApi::unifiedOrder($input);
     $jsApiParameters = $jsapi->GetJsApiParameters($bill);
     $this->render('company', array('list' => $list, 'date' => $date, 'months' => $months, 'totalPrice' => $totalPrice, 'jsparams' => $jsApiParameters));
 }
 public function actionWxpay($order)
 {
     $model = Order::findOne(['order_sn' => $order, 'status' => Order::STATUS_UNPAID]);
     if (!$model) {
         throw new BadRequestHttpException('参数错误!');
     }
     require_once Yii::getAlias('@vendor') . "/payment/wxpay/lib/WxPay.Api.php";
     require_once Yii::getAlias('@vendor') . "/payment/wxpay/lib/WxPay.JsApiPay.php";
     try {
         $tools = new \JsApiPay();
         $openId = $tools->GetOpenid();
         $input = new \WxPayUnifiedOrder();
         $input->SetBody('笑e购(xiaoego.com)订单,' . $model->description);
         $input->SetOut_trade_no($model->order_sn);
         $input->SetTotal_fee(bcmul($model->real_fee, 100));
         $input->SetTime_start(date("YmdHis", $model->created_at));
         $input->SetTime_expire(date("YmdHis", $model->timeout));
         $input->SetNotify_url(Url::to(['/payment/wxpay-order-notify'], true));
         $input->SetTrade_type("JSAPI");
         $input->SetOpenid($openId);
         $orderform = \WxPayApi::unifiedOrder($input);
         $jsApiParameters = $tools->GetJsApiParameters($orderform);
     } catch (\Exception $e) {
         Yii::error("用户请求支付订单失败!订单号:{$order},支付平台:wxpay");
         throw new BadRequestHttpException($e->getMessage());
     }
     Yii::info("用户请求支付订单成功!订单号:{$order},支付平台:wxpay");
     return $this->renderPartial('wxpay', ['model' => $model, 'jsApiParameters' => $jsApiParameters]);
 }
示例#23
0
文件: site.php 项目: noikiy/mygit
 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);
 }
示例#24
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);
     }
 }
示例#25
0
 /**
  * 获取微支付预支付订单
  * @param $out_trade_no
  * @param $goods
  * @param $total_fee
  * @param $body
  * @param $attach
  * @param $notify_url
  * @return \成功时返回
  */
 public static function GrantWxpayUnifiedOrder($out_trade_no, $goods, $total_fee, $body, $attach, $notify_url, $return_url)
 {
     require_once __DIR__ . "/../wxpay/WxPay.Api.php";
     require_once __DIR__ . "/../wxpay/WxPay.JsApiPay.php";
     require_once __DIR__ . "/../common/log.php";
     $tools = new \JsApiPay();
     $openId = $tools->GetOpenid($return_url);
     $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("JSAPI");
     $input->SetOpenid($openId);
     $result['order'] = \WxPayApi::unifiedOrder($input);
     $result['jsApiParameters'] = $tools->GetJsApiParameters($result['order']);
     //获取共享收货地址js函数参数
     //        $result['editAddress'] = $tools->GetEditAddressParameters();
     return $result;
 }