Commit f015636f authored by zhuwei's avatar zhuwei

分享办公楼

parent 04393e43
<?php
namespace app\index\controller;
use app\api\controller\WxSdk;
use app\api\untils\WxCallbackUntils;
use app\index\extend\Basic;
use app\index\service\UserService;
use app\model\UWxInfo;
use Think\Log;
/**
* Created by PhpStorm.
* User : zhwuei
* Date : 2018-11-14
* Time : 11:29:52
* Intro:
*/
class ShareOfficeRoom extends Basic
{
private $url;
private $_wxApi;
private $wxInfoModel;
public function __construct()
{
parent::__construct();
$this->_wxApi = new WxCallbackUntils();
$this->wxInfoModel = new UWxInfo();
$this->url = CURRENT_URL . "index/ShareOfficeRoom";
}
public function ShareOfficeRoom()
{
$browser_type = $this->isWeiChatBrowser();
$params = $this->params;
$is_user = true;
if($browser_type == 1){
//dump('微信浏览器');
$code = empty($_GET['code']) ? null : $_GET['code'];
if (!$code) {
$this->_wxApi->getWxCode($this->url.'?'.http_build_query($params));
} else {
$userInfo = $this->_wxApi->getUserInfoByAccessToken($code);
//dump($userInfo);exit;
if (!$userInfo['wx_open_id']) {
$this->_wxApi->getWxCode($this->url.'?'.http_build_query($params));
}else{
$wx_union_id = $userInfo['wx_union_id'] ? $userInfo['wx_union_id'] : $userInfo['wx_open_id'];
if(!$userInfo['wx_union_id']){
$userInfo['wx_union_id'] = $userInfo['wx_open_id'];
}
$user_service = new UserService();
$is_user = $user_service->isUserByweiXin($wx_union_id);
$userInfo["source"] = 0;
// 验证open_id是否已经存在,存在则更新
$wxInfoObj = $this->wxInfoModel->getWxInfoByOpenId($wx_union_id);
if ($wxInfoObj && count($wxInfoObj) > 0) {
$userInfo["id"] = $wxInfoObj[0]["id"];
$id = $this->wxInfoModel->updateWxInfo($userInfo);
} else {
$id = $this->wxInfoModel->addWxInfo($userInfo);
}
$params['is_user'] = $is_user;
$params['wx_union_id'] = $wx_union_id;
$params['device_id'] = $this->createOrderNumber();
}
}
}
$this->assign('data',json_encode($params));
return view("share_detail");
}
public function yindaoAndroid()
{
return view("yindao_android");
}
public function yindaoIos()
{
return view("yindao_ios");
}
/**
* 随机数
* @return string
*/
private function createOrderNumber()
{
return time() . mt_rand(10000, 99999);
}
/**
* 浏览器判断
* @return int
*/
function isWeiChatBrowser(){
$ua = $_SERVER['HTTP_USER_AGENT'];
//MicroMessenger 是android/iphone版微信所带的
//Windows Phone 是winphone版微信带的 (这个标识会误伤winphone普通浏览器的访问)
if(strpos($ua, 'MicroMessenger') == false && strpos($ua, 'Windows Phone') == false){
return 0; //普通浏览器
}else{
return 1; //微信浏览器
}
}
}
\ No newline at end of file
...@@ -74,7 +74,7 @@ class ShareShop extends Basic ...@@ -74,7 +74,7 @@ class ShareShop extends Basic
} }
$this->assign('data',json_encode($params)); $this->assign('data',json_encode($params));
return view("share_detail"); return view("office_detail");
} }
......
...@@ -493,6 +493,8 @@ Route::group('index', [ ...@@ -493,6 +493,8 @@ Route::group('index', [
'getFindShopList' => ['index/FindShop/getFindShopList', ['method' => 'POST|GET']], 'getFindShopList' => ['index/FindShop/getFindShopList', ['method' => 'POST|GET']],
'getFindShopListIsMy' => ['index/FindShop/getFindShopList', ['method' => 'POST|GET']], 'getFindShopListIsMy' => ['index/FindShop/getFindShopList', ['method' => 'POST|GET']],
'ShareOfficeRoom' => ['index/ShareOfficeRoom/ShareOfficeRoom', ['method' => 'POST|GET']],
]); ]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment