예제 #1
0
파일: Wechat.php 프로젝트: noikiy/wowewe
 public function initUser()
 {
     $gh_id = $this->getGhId();
     $FromUserName = $this->getRequest('FromUserName');
     $MsgType = $this->getRequest('MsgType');
     $isNewUser = false;
     $model = MUser::findOne(['gh_id' => $gh_id, 'openid' => $FromUserName]);
     if ($model === null) {
         $isNewUser = true;
         $model = new MUser();
         $model->gh_id = $gh_id;
         $model->openid = $FromUserName;
         $model->msg_cnt = 0;
     }
     if (empty($model->nickname) || !$model->subscribe) {
         $arr = $this->WxGetUserInfoSafe($FromUserName);
         $model->setAttributes($arr, false);
     }
     $model->msg_time = date("Y-m-d H:i:s");
     if ($MsgType == Wechat::MSGTYPE_EVENT) {
         $Event = $this->getRequest('Event');
         if (!in_array($Event, [Wechat::EVENT_SUBSCRIBE, Wechat::EVENT_UNSUBSCRIBE])) {
             $model->msg_cnt += 1;
         }
     } else {
         $model->msg_cnt += 1;
     }
     $this->setUser($model);
     return $isNewUser;
 }