GetJsApiParameters() public method

获取jsapi支付的参数
public GetJsApiParameters ( array $UnifiedOrderResult ) : json数据,可直接填入js函数作为参数
$UnifiedOrderResult array 统一支付接口返回的数据
return json数据,可直接填入js函数作为参数
Esempio n. 1
0
 static function build_js_params()
 {
     //①、获取用户openid
     $tools = new JsApiPay();
     $openId = $tools->GetOpenid();
     pt_log($openId);
     //②、统一下单
     $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://demo.ptphp.com/wxpay/example/notify_test");
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = WxPayApi::unifiedOrder($input);
     pt_log($order);
     $jsApiParameters = $tools->GetJsApiParameters($order);
     pt_log($jsApiParameters);
     //获取共享收货地址js函数参数
     return $jsApiParameters;
 }
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 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);
 }
 public function wxpay_js()
 {
     $tools = new JsApiPay();
     if (!Input::has('code')) {
         $data = array('period_id' => Input::get('period_id'), 'user_id' => Session::get('user.id'));
         $base_url = urlencode('http://test.zerioi.com/pay/wxpay_js?' . http_build_query($data, '', '&'));
         //$base_url = urlencode( 'http://test.zerioi.com/pay/wxpay?period_id='.Input::get('period_id') );
         $url = $tools->CreateOauthUrlForCode($base_url);
         return Redirect::to($url);
     }
     $open_id = Session::get('user.open_id');
     if (!isset($open_id)) {
         $open_id = $tools->GetOpenidFromMp(Input::get('code'));
         Session::put('user.open_id', $open_id);
     } else {
         Session::forget('user.open_id');
     }
     // 选择用户默认账户
     $user_id = Input::get('user_id');
     $account = RegisterAccount::where('user_id', $user_id)->first();
     if (!isset($account)) {
         return Response::make('请先申请挂号账户');
     }
     $account_id = $account->id;
     $period_id = Input::get('period_id');
     $period = Period::find($period_id);
     if (!$this->validate_peirod($period)) {
         return Response::make('无效时间段,请重新选择');
     }
     /**
      * 创建订单时先将对应时间段的挂号数加1,
      * 以避免微信支付异步通知顺序不一致导致
      * 挂号记录创建顺序不一致
      */
     $period->start = date('H:i', strtotime($period->start));
     $period->end = date('H:i', strtotime($period->end));
     $schedule = $period->schedule;
     $doctor = $schedule->doctor;
     $possible_period = array('上午', '下午');
     $schedule = array('date' => $schedule->date, 'period' => $possible_period[$schedule->period]);
     // 附加信息
     $attach = array('period_id' => (int) Input::get('period_id'), 'account_id' => $account_id);
     // 创建订单
     $order = $this->create_order(Input::get('user_id'), 'JSAPI', json_encode($attach), (int) ($doctor->register_fee * 100), $open_id);
     $para = $tools->GetJsApiParameters($order);
     $data = array('period' => $period, 'schedule' => $schedule, 'doctor' => $doctor, 'department' => $doctor->department->name, 'para' => $para);
     return View::make('register.pay', $data);
 }
Esempio n. 5
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']];
 }
 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);
 }
Esempio n. 7
0
//②、统一下单
$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)
 */
?>

<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/> 
Esempio n. 8
0
<?php

/** @var $schemes \common\models\Scheme[] */
/** @var $orders */
use common\functions\CommonFunctions;
use common\models\Users;
$this->title = "云豆充值";
$user = Yii::$app->session->get('user');
$userIcon = isset($user['userIcon']) ? $user['userIcon'] : null;
$userIcon = CommonFunctions::createHttpImagePath($userIcon);
$tools = new JsApiPay();
/** @var $jsApiParameters Array //JSON */
$jsApiParameters = [];
foreach ($orders as $order) {
    array_push($jsApiParameters, $tools->GetJsApiParameters($order));
}
?>
<div class="account-header">
    <div class="avatar">
        <img src="<?php 
echo $userIcon;
?>
" alt="head">
        <p><?php 
echo $user['nickname'];
?>
</p>
        <p>云豆余额:<strong><?php 
echo Users::findBitcoin($user['userId']);
?>
</strong></p>
Esempio n. 9
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];
 }
 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]);
 }
Esempio n. 11
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. 12
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}");
     }
 }
Esempio n. 13
0
$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>';
?>

Esempio n. 14
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();
 }
Esempio n. 15
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. 16
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. 17
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;
 }