/** * @param Shop $shop * @param $sn * @return bool|mixed * @throws \Exception */ public function bindDevice(Shop $shop, $sn) { $shopDevice = ShopDevice::getBySn($sn); if ($shopDevice->shop_id) { return false; } $shopDevice->shop_id = $shop->id; $shopDevice->device_sn = $sn; $token = $this->mq->getDeviceAccessToken(); $rt = $this->deviceClient->bindDevice($shop->page_id, array($sn), true, true, $token); if ($rt) { $rt = $shopDevice->save(); $shop->status = Shop::STATUS_ACTIVE; $url = Config::get('app.shop_base_url') . $shop->short_id; $token = $this->mq->getDeviceAccessToken(); $page = array('title' => $shop->title, 'description' => $shop->subtitle, 'icon_url' => Config::get('app.domain.oc') . $shop->thumbnail, 'url' => $url, 'comment' => $shop->comment); $pageId = $this->deviceClient->createPage($page, $token); $shop->url = $url; $shop->page_id = $pageId; $shop->save(); } return $rt; }