/** * 统一下单 * * @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']]; }
<?php use Tools\Tools; define('APP_PATH', './Application/'); include_once 'RestPHP/Tools.class.php'; $tool = new Tools(); $tool->makeModel("blog");
/** * 查看带参数二维码列表 * @param $id 公众号ID */ public function action_param_qrcode($id = 0) { $params = array('title' => '微信公众帐户带参二维码列表——微信公众号管理', 'menu' => 'wxaccount', 'action_name' => '微信公众帐户列表 》带参二维码列表'); if (\Input::method() == 'POST') { $data = \Input::post(); $account_id = \Session::get('WXAccount')->id; $table = \DB::table_prefix('wx_accounts_qrcodes'); $time = time(); $sql = "SELECT * FROM {$table} WHERE (`key` = '{$data['key']}' AND `type` = 'TEMP' AND `valid_date` > {$time} AND `account_id` = {$account_id}) OR (`key` = '{$data['key']}' AND `type` = 'LIMIT' AND `account_id` = {$account_id})"; $rows = \DB::query($sql)->execute()->as_array(); if ($rows) { $data = current($rows); die(json_encode(array('status' => 'err', 'msg' => '该参数的二维码已存在', 'errcode' => 10, 'data' => $data ? $data['qrcode'] : ''))); } $result = \impls\wechat\Common::generate_qrcode_ticket($data['key'], strtolower($data['type'])); $array = json_decode($result); $data['url'] = $array->url; $data['ticket'] = $array->ticket; if ($data['type'] == 'TEMP') { $data['valid_date'] = time() + $array->expire_seconds; } else { $data['valid_date'] = 0; } $data['qrcode'] = \tools\Tools::generate_qrcode($data['url'], '/uploads/qrcodes/'); $qrcode = \Model_WXAccountQrcode::forge($data); if ($qrcode->save()) { if (\Input::is_ajax()) { die(json_encode(array('status' => 'succ', 'msg' => '', 'errcode' => 0, 'data' => $data['qrcode']))); } } else { if (\Input::is_ajax()) { die(json_encode(array('status' => 'err', 'msg' => '生成失败', 'errcode' => 20))); } } } $data = \Input::get(); $items = \Model_WXAccountQrcode::query()->where('account_id', $id); $where_args = ''; //是否需要筛选二维码的参数 if (isset($data['key']) && $data['key']) { $items->where('key', $data['key']); $where_args .= "key={$data['key']}&"; } //是否需要筛选二维码的状态 if (isset($data['status']) && $data['status']) { $where_args .= "status={$data['status']}&"; if ($data['status'] == 'valid') { $items->and_where_open()->where('valid_date', '>', time())->where('type', 'TEMP')->and_where_close(); $items->or_where_open()->where('type', 'LIMIT')->or_where_close(); } else { if (in_array(strtoupper($data['status']), array('TEMP', 'LIMIT'))) { $items->where('type', $data['status']); } } } $where_args = $where_args ? "?{$where_args}" : ''; $count = $items->count(); $config = array('pagination_url' => "/admin/wxaccount/param_qrcode/{$id}{$where_args}", 'total_items' => $count, 'per_page' => \Input::get('count', 15), 'uri_segment' => "start", 'show_first' => true, 'show_last' => true, 'name' => 'bootstrap3_cn'); $pagination = new \Pagination($config); $params['pagination'] = $pagination; $params['items'] = $items->rows_offset($pagination->offset)->rows_limit($pagination->per_page)->get(); \View::set_global($params); $this->template->content = \View::forge("ace/wxaccount/qrcodes"); }