Exemplo n.º 1
0
 /**
  * index
  *
  * @return string
  */
 public function index()
 {
     //return 'BKOnline Wechat Service';
     $app = WechatApp::where('id', 1)->get()->first();
     //UserCache::updateUserCache($app);
     $user = UserCache::getByOpenId($app, 'oCFvTvkmM5joT-h8pr7p-q2F0Dno');
     echo json_encode($user);
 }
Exemplo n.º 2
0
 /**
  * Handler activity by command
  *
  * @param $app WechatApp
  * @param $user User
  * @return string message
  */
 public static function handle($app, $openId, $replyArr)
 {
     $user = UserCache::getByOpenId($app, $openId);
     $eventCode = Event::getEventCode($replyArr['event_id']);
     if (!$user) {
         SysLog::error(__FILE__, __METHOD__, __LINE__, 'user not found by openid');
         return false;
     }
     if (!$user['mobile']) {
         return ReplyFormat::replyText(SysParams::sys_error['error_user_not_register']);
     }
     switch ($eventCode) {
         case self::ACTIVITY_INIT:
             return KshActivity::startKsh($app, $user, $replyArr, $user['time_out']);
             break;
         case self::ACTIVITY_CLOSE:
             return KshActivity::stopKsh($app, $user, $replyArr);
             break;
         case self::ACTIVITY_DRAW:
             return KshActivity::drawKsh($app, $user, $replyArr);
             break;
         case self::QUESTION_BROWSE:
             return KshActivity::browseKshQuestionStore($app, $user, $replyArr);
             break;
         case self::PRIZE_BROWSE:
             return KshActivity::browseKshPrizeStore($app, $user, $replyArr);
             break;
         case self::ACTIVITY_JOIN:
             return KshActivity::joinKsh($app, $user, $replyArr);
             break;
         case self::ACTIVITY_ANSWER:
             return KshActivity::answerKsh($app, $user, $replyArr);
             break;
         case self::QUERY_WINNER:
             return KshActivity::queryWinner($app, $user, $replyArr);
             break;
         case self::QUERY_PRIZE:
             return KshActivity::queryPrize($app, $user, $replyArr);
             break;
             //            case self::QUESTION_CHOOSE:
             //                return Ksh::setActivityQuestion($app, $user, $replyArr);
             //                break;
             //            case self::PRIZE_CHOOSE:
             //                return Ksh::setActivityPrize($app, $user, $replyArr);
             //                break;
         //            case self::QUESTION_CHOOSE:
         //                return Ksh::setActivityQuestion($app, $user, $replyArr);
         //                break;
         //            case self::PRIZE_CHOOSE:
         //                return Ksh::setActivityPrize($app, $user, $replyArr);
         //                break;
         default:
             return false;
             break;
     }
 }
Exemplo n.º 3
0
 private static function refreshUserCache()
 {
     //refresh each wechat app user cache
     $apps = WechatApp::get();
     if ($apps) {
         foreach ($apps as $app) {
             UserCache::updateUserCache($app);
         }
     }
 }
Exemplo n.º 4
0
 private static function registerHandle($app, $user, $mobile)
 {
     $openId = $user['open_id'];
     if ($openId) {
         //新注册用户
         if (!$user['mobile']) {
             //先寻找有无此手机号的代表, 有则绑定手机号和openid
             $manager = ActivityManager::getByMobile($mobile);
             if ($manager->bindManager($app, $openId, $mobile)) {
                 return UserCache::updateUser($app, $openId);
             } else {
                 if (Doctor::createDoctor($app, $openId, $mobile)) {
                     return UserCache::updateUser($app, $openId);
                 }
             }
         } else {
             if ($user['type'] == UserOpenid::TYPE_DOCTOR) {
                 $doctor = Doctor::getById($user['id']);
                 $doctor->mobile = $mobile;
                 $doctor->updated_at = Carbon::now();
                 if ($doctor->save()) {
                     return UserCache::updateUser($app, $openId);
                 }
             }
             if ($user['type'] == UserOpenid::TYPE_MANAGER) {
                 $manager = ActivityManager::getById($user['id']);
                 $manager->mobile = $mobile;
                 $manager->updated_at = Carbon::now();
                 if ($manager->save()) {
                     return UserCache::updateUser($app, $openId);
                 }
             }
         }
     }
     return false;
 }
Exemplo n.º 5
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);
 }