Exemplo n.º 1
0
 /**
  * handle user unsubscribe event
  *
  * @param $replyArr
  * @return bool
  */
 public static function unsubscribe($app, $openId)
 {
     UserCache::removeUser($app, $openId);
     return UserOpenid::deleteUser($app['id'], $openId);
 }
Exemplo n.º 2
0
 /**
  * Get user wechat app OpenId
  *
  * @param $app
  * @return string
  */
 public function getOpenId($app)
 {
     if (isset($app)) {
         $model = UserOpenid::where(['wechat_id' => $app['id'], 'user_id' => $this->id])->get()->first();
         if ($model) {
             return $model['open_id'];
         }
     }
     return null;
 }
Exemplo n.º 3
0
 private static function update($app, $openId)
 {
     $key = 'user-cache-' . $app['id'];
     if (Cache::has($key)) {
         $type = UserOpenid::getUserTypeCode($app['id'], $openId);
         $cache = json_decode(base64_decode(Cache::get($key)), true);
         if (self::get($app, $openId)) {
             //先删除
             unset($cache[$openId]);
             //重新获取
             $item = null;
             if ($type == UserOpenid::TYPE_DOCTOR) {
                 $model = Doctor::getDoctor($app['id'], $openId);
                 if ($model) {
                     $item = ['open_id' => $model['open_id'], 'type' => $model['code'], 'id' => $model['id'], 'name' => $model['name'], 'mobile' => $model['mobile']];
                     $cache[$openId] = $item;
                 }
             }
             if ($type == UserOpenid::TYPE_MANAGER) {
                 $model = ActivityManager::getManager($app['id'], $openId);
                 if ($model) {
                     $item = ['open_id' => $model['open_id'], 'type' => $model['code'], 'id' => $model['id'], 'name' => $model['name'], 'mobile' => $model['mobile'], 'time_out' => (int) $model['activity_timeout'] * 60 * 60];
                     $cache[$openId] = $item;
                 }
             }
             //更新
             if ($item) {
                 Cache::forget($key);
                 $value = base64_encode(json_encode($cache));
                 Cache::forever($key, $value);
                 return true;
             }
         }
     }
     return false;
 }