public function getMp() { if ($this->type == self::TYPE_WEIXIN) { return WeixinMp::where('app_id', $this->id)->first(); } return null; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $token = $request->get('token'); if (!$token or !$this->verifyToken($token)) { return $this->encodeResult(20000, "Permission denied,TOKEN ERROR"); } $app = App::where('access_token', $token)->first(); Session::put('appid', $app->id); $mp = WeixinMp::where('app_id', $app->id)->first(); Session::put('wx_mp_id', $mp->id); Session::put('wx_appid', $mp->appid); Session::put('wx_appsecret', $mp->appsecret); return $next($request); }
public function getMpByAppId($appId) { return WeixinMp::where('app_id', $appId)->first(); }
/** * 获取当前用户拥有的公众号 * @author Hanxiang */ private static function getCurrentWxMps() { $user = Auth::user(); $wx_mps = []; if ($user->role == User::ROLE_COMMON_USER) { $apps = App::where('user_id', $user->id)->get(); if ($apps) { foreach ($apps as $a) { $wx_mps = WeixinMp::where('app_id', $a->id)->get(); } } } else { $wx_mps = WeixinMp::all(); } return $wx_mps; }
/** * 获取微信设备AJAX * @author Hanxiang */ public function wxdevicesAjax() { $input = Input::all(); $sn = $input['sn']; $device = Device::where('sn', $sn)->first(); if (!$device) { return response()->json(['wx_devices' => [], 'first' => new \stdClass()]); } $app_id = DeviceApp::where('device_id', $device->id)->lists('app_id'); $wx_mp_id = WeixinMp::where('app_id', $app_id)->lists('id'); $wxdevices = WeixinDevice::where('wx_mp_id', $wx_mp_id)->get(); if (count($wxdevices) > 0) { foreach ($wxdevices as $wx) { $wx->sn = Device::where("wx_device_id", $wx->id)->get(); } } $firstWxDevice = self::getFirstAvailableWxDevice(); return response()->json(['wx_devices' => $wxdevices->toArray(), 'first' => $firstWxDevice]); }
/** * * @author zhengqian@dajiayao.cc */ public function sync($appid, $appsecret) { $mp_id = WeixinMp::where('appid', $appid)->where('appsecret', $appsecret)->first()->id; $bid = 0; $countPage = 0; //定义缓存数组 $cacheArrayPage = []; while (true) { $ret = $this->syncPage($appid, $appsecret, $bid, 20); $pages = $ret->pages; $bid = $bid + count($pages); if (!$pages) { break; } //开始同步页面 foreach ($pages as $page) { $objPage = WeixinPage::where('page_id', $page->page_id)->first(); if (!$objPage) { $objPage = new WeixinPage(); $objPage->guid = Uuid::v4(false); $objPage->title = $page->title; $objPage->description = $page->description; $objPage->icon_url = $page->icon_url; $objPage->url = $page->page_url; $objPage->comment = $page->comment; $objPage->page_id = $page->page_id; $objPage->wx_mp_id = $mp_id; $objPage->save(); $countPage++; } //生产缓存数组 if (!array_key_exists($page->page_id, $cacheArrayPage)) { $cacheArrayPage[$page->page_id] = $objPage->id; } } } unset($ret); $countDevice = 0; $bid = 0; while (True) { $ret = $this->syncDevice($appid, $appsecret, $bid); $devices = $ret->devices; $bid = $bid + count($devices); if (!$devices) { break; } //开始同步设备 foreach ($devices as $device) { $objWxDevice = WeixinDevice::where('device_id', $device->device_id)->first(); if (!$objWxDevice) { $objWxDevice = new WeixinDevice(); $objWxDevice->uuid = $device->uuid; $objWxDevice->major = $device->major; $objWxDevice->minor = $device->minor; $objWxDevice->comment = $device->comment; $objWxDevice->poi_id = $device->poi_id; $objWxDevice->wx_mp_id = $mp_id; $objWxDevice->device_id = $device->device_id; $objWxDevice->apply_id = $device->device_id; $countDevice++; } $objWxDevice->status = $device->status; $objWxDevice->save(); //处理页面-设备关系 if (!empty($device->page_ids)) { $arrPageIds = explode(',', $device->page_ids); foreach ($arrPageIds as $pageId) { $devicePage = DevicePage::where('wx_device_id', $objWxDevice->id)->where('wx_page_id', $cacheArrayPage[$pageId])->first(); if (!$devicePage) { $devicePage = new DevicePage(); $devicePage->wx_device_id = $objWxDevice->id; $devicePage->wx_page_id = $cacheArrayPage[$pageId]; $devicePage->save(); } } } } } return ['count_page' => $countPage, 'count_device' => $countDevice]; }