/** * @设备绑定页面 * @param DeviceService $deviceService * @param ShakeAroundClient $shakeAroundClient * @param string $sn * @return string */ public function bindPage(DeviceService $deviceService, ShakeAroundClient $shakeAroundClient, $sn = '') { if (!$sn) { return RestHelp::parametersIllegal("sn is required"); } $device = Device::where("sn", $sn)->first(); if (!$device) { return RestHelp::encodeResult(24001, sprintf("sn %s not found", $sn)); } $requestData = json_decode($this->inputData, true); $pageIds = $requestData['page_ids']; if (!$pageIds or !is_array($requestData['page_ids'])) { return RestHelp::encodeResult(24002, 'page_ids must be arrary'); } foreach ($pageIds as $pid) { if (!WeixinPage::find($pid)) { return RestHelp::encodeResult(23001, sprintf("page id :%s not found", $pid)); } } $validator = Validator::make($requestData, ['page_ids' => 'required', 'bind' => 'required|boolean', 'append' => 'required|boolean']); if ($validator->fails()) { return RestHelp::parametersIllegal($validator->messages()->first()); } try { $deviceService->bindPage($shakeAroundClient, WeixinDevice::find($device->wx_device_id), $requestData['page_ids'], $requestData['bind'], $requestData['append']); } catch (\Exception $e) { return RestHelp::encodeResult($e->getCode(), $e->getMessage()); } return RestHelp::success(); }
/** * 绑定页面 * @param DeviceService $deviceService * @param $wxDeviceId * @param $pageIds * @param int $flage * @author zhengqian@dajiayao.cc */ public function bindPages(ShakeAroundClient $shakeAroundClient, DeviceService $deviceService) { $inputData = Input::all(); $wxDeviceId = $inputData['device_id']; $objDev = WeixinDevice::find($wxDeviceId); if (!$objDev) { return redirect(route('adminGetBindPage', [$wxDeviceId]))->with('result', false)->with('msg', "设备id 不存在"); } $pageIds = isset($inputData['page_id']) ? $inputData['page_id'] : []; foreach ($pageIds as $id) { $objPage = WeixinPage::find($id); if (!$objPage) { return redirect(route('adminGetBindPage', [$wxDeviceId]))->with('result', false)->with('msg', sprintf("页面id:%s 不存在", $id)); } } //如果空page_ids,则解绑所有页面 if (empty($pageIds)) { $dp = DB::table('device_page')->where('wx_device_id', $wxDeviceId)->lists('wx_page_id'); try { $deviceService->bindPage($shakeAroundClient, $objDev, $dp, 0, 0, $objDev->mp->appid, $objDev->mp->appsecret); } catch (\Exception $e) { echo $e->getMessage(); exit; } return redirect(route('adminGetBindPage', [$wxDeviceId]))->with('result', true)->with('msg', "操作成功"); } try { $deviceService->bindPage($shakeAroundClient, $objDev, $pageIds, 1, 0, $objDev->mp->appid, $objDev->mp->appsecret); } catch (\Exception $e) { echo $e->getMessage(); exit; } return redirect(route('adminGetBindPage', [$wxDeviceId]))->with('result', true)->with('msg', "操作成功"); }