示例#1
0
 private function refreshUserInfo($from_user)
 {
     $follower = $from_user;
     $qr_mgr = new UserManager('');
     $userInfo = $qr_mgr->getUserInfo($follower);
     if (empty($userInfo) or empty($userInfo['nickname']) or empty($userInfo['avatar'])) {
         $weapi = new WechatAPI();
         $userInfo = $weapi->getUserInfo($follower);
         $qr_mgr->saveUserInfo($userInfo);
     }
     WeUtility::logging('refresh', $userInfo);
 }
示例#2
0
 public function refresh($weid, $from_user, $force = false)
 {
     $userInfo = $this->fans_search_by_openid($weid, $from_user);
     if ($userInfo['follow'] == 1) {
         if ($force == true or empty($userInfo['nickname']) or empty($userInfo['avatar'])) {
             yload()->classs('quick_center', 'wechatapi');
             $_weapi = new WechatAPI();
             $info = $_weapi->getUserInfo($from_user);
             $weInfo = array('nickname' => $info['nickname'], 'gender' => $info['sex'], 'residecity' => $info['city'], 'resideprovince' => $info['province'], 'nationality' => $info['country'], 'avatar' => $info['headimgurl']);
             $this->fans_update_by_openid($weid, $from_user, $weInfo);
             $userInfo = $this->fans_search_by_openid($weid, $from_user);
         }
     }
     return $userInfo;
 }
示例#3
0
 private function respondSubscribe()
 {
     /* 有新用户通过二维码订阅本账号, 处理流程如下:
      * 1. 判断是否设置scene id,如果没有设置则直接回复默认消息,如果设置了scene id,则读取scene id
      * 2. 读取qr表,找到分享者uid,channel
      * 3. 将本次引流事件记录到follow表
      * 4. 推送channel指定消息给用户
      */
     $follower = $this->message['from'];
     list($dummy, $scene_id) = explode('_', $this->message['eventkey']);
     /* 记录用户的基本信息:图像,昵称,地址 */
     $qr_mgr = new UserManager('');
     $weapi = new WechatAPI();
     $userInfo = $weapi->getUserInfo($follower);
     $qr_mgr->saveUserInfo($userInfo);
     if (empty($scene_id)) {
         WeUtility::logging('subscribe', 'no scene id');
         return $this->respText('欢迎关注微信号!');
     }
     // 2. 读取qr表,找到分享者uid,channel
     WeUtility::logging('getQRByScene', $scene_id);
     $qr = $qr_mgr->getQRByScene($scene_id);
     if (empty($qr)) {
         WeUtility::logging('subscribe', 'qr not found using scene ' . $scene_id);
         return $this->respText('欢迎关注微信号!');
     }
     // 3. 将本次引流事件记录到follow表
     $leader = $qr['from_user'];
     $qr_mgr = new UserManager($leader);
     // 4. 推送channel指定消息给用户
     $channel = $qr_mgr->getChannel($qr['channel']);
     if (empty($channel)) {
         WeUtility::logging('subscribe', 'channel not found using channel ' . $qr['channel']);
         return $this->respText('欢迎关注微信号!');
     }
     if ($qr_mgr->isNewUser($follower)) {
         WeUtility::logging('record followship', $qr);
         $qr_mgr->processSubscribe($follower, $qr['channel']);
         /* 最后,给上线发一个通知 */
         $this->notifyUpLevel($weapi, $leader);
         $this->notifyLeader($weapi, $leader, $follower);
     } else {
         $this->notifyLeaderScanEvent($weapi, $leader, $follower);
     }
     $response = array();
     $channel['title'] = preg_replace('/\\[nickname\\]/', $userInfo['nickname'], $channel['title']);
     $channel['desc'] = preg_replace('/\\[nickname\\]/', $userInfo['nickname'], $channel['desc']);
     $response[] = array('title' => $channel['title'], 'description' => $channel['desc'], 'picurl' => tomedia($channel['thumb']), 'url' => $this->buildSiteUrl($channel['url']));
     return $this->respNews($response);
 }