Example #1
0
 /**
  * 激活 第一步
  * @author Hanxiang
  * @return $this
  */
 public function activateS1()
 {
     $sn = Input::get('sn') ? Input::get('sn') : '';
     $shopDevice = ShopDevice::where('device_sn', $sn)->first();
     if (count($shopDevice) && $shopDevice->shop_id) {
         // TODO
         $shop = Shop::find($shopDevice->shop_id);
         return redirect()->route('shopIndex', $shop->short_id);
     }
     return view('seller.activate')->with('config', $this->getJsapiConfig())->with('sn', $sn);
 }
Example #2
0
 /**
  * @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;
 }