コード例 #1
0
ファイル: home.php プロジェクト: wxl2012/wx
 public function action_login()
 {
     if (\Auth::check()) {
         $redirect = "/admin";
         if (isset($data['to_url'])) {
             $redirect = $data['to_url'];
         }
         \Response::redirect($redirect);
     }
     \View::set_global(array('menu' => 'admin-home', 'title' => '登录系统', 'action' => 'login'));
     if (\Input::method() == 'POST') {
         if (\Auth::login()) {
             if (\Auth::get_user()->username == 'admin') {
                 \Response::redirect('/admin');
             }
             $employee = \Model_Employee::query()->where('parent_id', \Auth::get_user()->id)->get_one();
             if (!$employee) {
                 \Session::set_flash('msg', ['status' => 'err', 'msg' => '非法登录,多次尝试登录,您的帐户将被封锁!', 'title' => '警告', 'sub_title' => '非法登录', 'icon' => 'exclamation-circle', 'color' => '#d9534f']);
                 return $this->not_login_alert();
             }
             // 保存会话信息: 当前登录人员的身份、所属商户、微信公众号信息
             \Session::set('seller', $employee->seller);
             \Session::set('people', $employee->people);
             \Session::set('employee', $employee);
             // 查询当前商户默认公众号信息
             $accounts = \Model_WXAccount::query()->where(['seller_id' => $employee->seller->id])->get();
             $account = false;
             if (count($accounts) > 1) {
                 foreach ($accounts as $item) {
                     if ($account->is_default == 1) {
                         $account = $item;
                         break;
                     }
                 }
             } else {
                 $account = current($accounts);
             }
             \Session::set('WXAccount', $account);
             //获取API访问令牌
             $result = \handler\common\UrlTool::request(\Config::get('base_url') . 'api/token.json?user_id=' . \Auth::get_user()->id);
             $token = json_decode($result->body);
             \Session::set('access_token', $token->access_token);
             $redirect = "/admin";
             if (isset($data['to_url'])) {
                 $redirect = $data['to_url'];
             }
             \Response::redirect($redirect);
         }
         \Session::set_flash('msg', array('status' => 'err', 'msg' => '登录失败', 'errcode' => 20));
     }
     return \Response::forge(\View::forge("ace/login"));
 }
コード例 #2
0
ファイル: templatemsg.php プロジェクト: wxl2012/wx
 /**
  * 发送模板消息
  *
  * $data = [
  *      'first' => [
  *          'value' => '',
  *          'color' => '',
  *      ],
  *      'keynote1' => [
  *          'value' => '',
  *          'color': => '',
  *      ],
  *      'remark' => [
  *          'value' => '',
  *          'color' => ''
  *      ]
  * ]
  *
  * @param $data 模板数据
  * @return mixed 返回发送结果
  */
 public function send($data)
 {
     $params = ['touser' => $this->to, 'template_id' => $this->template_id, 'url' => $this->url, 'data' => $data];
     if ($this->account->temp_token_valid < time()) {
         $result = \handler\mp\Tool::generate_token($this->account->app_id, $this->account->app_secret);
         $this->account->temp_token = $result['token'];
         $this->account->temp_token_valid = $result['valid'];
         $this->account->save();
     }
     $url = "{$this->domain}/cgi-bin/message/template/send?access_token={$this->account->temp_token}";
     $result = \handler\common\UrlTool::request($url, 'POST', json_encode($params), true);
     return json_decode($result);
 }
コード例 #3
0
ファイル: printer.php プロジェクト: wxl2012/wx
 /**
  * 发起打印请求
  *
  * @param $content
  * @param $machine_code
  * @param $mkey
  * @param $time
  */
 public function start_print($content, $machine_code, $mkey, $time)
 {
     $params = ['partner' => $this->user_id, 'machine_code' => $machine_code, 'time' => $time, 'content' => $content];
     $sign = "{$this->api_key}machine_code{$machine_code}partner{$this->user_id}time{$time}{$mkey}";
     $params['sign'] = md5($sign);
     $params['sign'] = strtoupper($params['sign']);
     $result = \handler\common\UrlTool::request($this->domain, 'POST', $params);
     $result = json_decode($result->body);
     if ($result->state == 1) {
         return true;
     }
     $errmsg = [2 => '提交时间超时.验证你所提交的时间戳超过3分钟事拒绝接受', 3 => '参数有误', 4 => 'sign加密检验失败'];
     $this->msg = ['status' => 'err', 'msg' => $errmsg[$result->state], 'errcode' => 90100];
     return false;
 }
コード例 #4
0
ファイル: tool.php プロジェクト: wxl2012/wx
 /**
  * 发起统一支付
  *
  * @param $account  微信公众号对象
  * @param $order    订单对象
  * @param $access   支付配置对象
  * @param $openid   微信Openid
  * @param string $trade_type    支付类型
  * @return bool|\handler\common\Array
  * @throws \Exception
  */
 public static function wxpay_order($account, $order, $access, $openid, $trade_type = 'JSAPI')
 {
     //创建支付记录
     $ip = \Input::real_ip();
     $timestamp = time();
     //创建支付单号
     $order_no = md5("{$order->order_no}{$timestamp}{$ip}");
     $data = array('order_id' => $order->id, 'return_status' => 'NONE', 'out_trade_no' => $order_no, 'remark' => \Input::get('remark', ''), 'name' => \Input::get('name', ''), 'name_stype' => \Input::get('name_style', ''), 'real_money' => \Input::get('total_fee', $order->original_fee), 'openid' => $openid);
     $trade = \Model_OrderTrade::forge($data);
     if (!$trade->save()) {
         \Log::error('微信支付时发生异常,原因:交易记录创建失败');
         die('trade save error!');
     }
     //是否指定收款金额
     $total_fee = $order->original_fee;
     if (\Input::get('total_fee', false)) {
         $total_fee = floatval(\Input::get('total_fee'));
     }
     $params = array('openid' => $openid, 'body' => $order->order_body ? $order->order_body : '', 'out_trade_no' => $order_no, 'total_fee' => $total_fee * 100, 'notify_url' => \Config::get('base_url') . 'services/gateway/notice_wxpay', 'trade_type' => $trade_type, 'appid' => $account->app_id, 'mch_id' => $access->access_id, 'nonce_str' => \Str::random('alnum', 16));
     $params['sign'] = static::getWxPaySign($params, $access->access_key);
     $data = \handler\common\Tool::arrayToXml($params);
     $data = "<xml>{$data}</xml>";
     $result = \handler\common\UrlTool::request_xml('https://api.mch.weixin.qq.com/pay/unifiedorder', 'POST', $data);
     $result = \handler\common\Tool::xmlToArray($result);
     if ($result['return_code'] == 'FAIL') {
         var_dump($result);
         die;
     }
     return $result;
 }
コード例 #5
0
ファイル: wxapi.php プロジェクト: wxl2012/wx
 /**
  * 网页授权获取用户基本信息回调处理方法
  *
  * @access  public
  * @return  Response
  */
 public function action_oauth2_callback()
 {
     $params = \Input::get();
     if (!\Input::get('code', false)) {
         \Session::set_flash('msg', ['status' => 'err', 'msg' => '你拒绝授权,系统无法确认您的身份!系统中止!', 'title' => '错误']);
         return $this->show_message();
     }
     $this->account = \Session::get('WXAccount', \Model_WXAccount::find(1));
     $url = handler\mp\Tool::createOauthUrlForOpenid($this->account->app_id, $this->account->app_secret, $params['code']);
     $result = \handler\common\UrlTool::request($url, 'GET', null, true);
     $result = json_decode($result->body);
     if (!isset($result->openid) || !$result->openid) {
         \Session::set_flash('msg', ['status' => 'err', 'msg' => '未获取到OpenId!', 'title' => '错误']);
         return $this->show_message();
     }
     //跳转参数加openid
     $to_url = \Input::get('to_url', '/');
     $addspan = strpos($to_url, '?') !== false ? '&' : '?';
     $to_url = "{$to_url}{$addspan}openid={$result->openid}";
     //获取openid对象
     $wechatOpenID = \Model_WechatOpenid::query()->where(['openid' => $result->openid])->get_one();
     //openid存在,不需要创建
     if ($wechatOpenID) {
         \Response::redirect($to_url);
         return;
     }
     //拉取用户信息
     $url = handler\mp\Tool::createOauthUrlForUserinfo($result->access_token, $result->openid);
     $result = \handler\common\UrlTool::request($url, 'GET', null, true);
     $result = json_decode($result->body);
     if (isset($result->errcode)) {
         \Session::set_flash('msg', ['status' => 'err', 'msg' => $result->errmsg, 'title' => '错误']);
         return $this->show_message();
     }
     //查询微信用户信息是否存在
     $wechat = \Model_Wechat::query()->where(['nickname' => $result->nickname, 'sex' => $result->sex, 'city' => $result->city, 'province' => $result->province, 'country' => $result->country, 'headimgurl' => $result->headimgurl])->get_one();
     //存在则直接赋值微信信息记录
     if ($wechat) {
         $wechatOpenID->wechat_id = $wechatOpenID->id;
         return;
     }
     //创建openid数据及微信信息
     $wechatOpenID = handler\mp\Account::createWechatAccount($result->openid, $this->account);
     if (!$wechatOpenID) {
         \Session::set_flash('msg', ['status' => 'err', 'msg' => '微信信息保存失败! 缺少必要信息,系统终止!', 'title' => '错误']);
         return $this->show_message();
     }
     $wechat = $wechatOpenID->wechat;
     # 保存拉取到的用户信息
     $wechat->nickname = $result->nickname;
     $wechat->sex = $result->sex;
     $wechat->city = $result->city;
     $wechat->province = $result->province;
     $wechat->country = $result->country;
     $wechat->headimgurl = $result->headimgurl;
     $wechat->language = isset($result->language) ? $result->language : '';
     $wechat->subscribe_time = isset($result->subscribe_time) ? $result->subscribe_time : 0;
     $wechat->subscribe = isset($result->subscribe) ? $result->subscribe : 0;
     $wechat->save();
     \Response::redirect($to_url);
 }