Esempio n. 1
0
 public function sendText($weid, $openid, $msg)
 {
     yload()->classs('quick_center', 'wechatapi');
     $_wechatapi = new WechatAPI();
     $ret = $_wechatapi->sendText($openid, $msg);
     $this->addCustomMsg($weid, $openid, $msg);
     return $ret;
 }
Esempio n. 2
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);
 }
Esempio n. 3
0
 public function respondText($from_user)
 {
     /* 用户请求传单算法
      * 1. 获得用户uid
      * 2. 立即通知用户正在生成二维码
      * 3. 查询qr表,如果
      *   3.1 uid在qr表中不存在,则立即创建二维码,并插入qr表,然后返回信息
      *   3.2 uid在qr表中存在,则直接返回信息(第二期需要判断二维码有效时间,如果超过3天,则需要重新上传,更新media_id到qr表
      * 4. 将qr信息推送给用户
      * 5. 同步回复一个空字符串,结束本次请求
      */
     global $_W;
     WeUtility::logging('step1', '');
     $weapi = new WechatAPI();
     //$content = $this->message['content'];
     // 1. 获取uid
     // $from_user = $this->message['from'];
     // 3. 查询qr表
     $qr_mgr = new UserManager($from_user);
     $ch = $qr_mgr->getActiveChannel();
     // 当前只允许一个channel,后继版本扩充,2014-12-7
     $ch = WechatUtil::decode_channel_param($ch, $ch['bgparam']);
     $channel = $ch['channel'];
     $qr = $qr_mgr->getQR($channel, $from_user);
     // 没有缓存, 或者缓存过期
     WeUtility::logging('step3', $qr['createtime'] . '<' . $ch['createtime']);
     if (empty($qr) or $qr['createtime'] < $ch['createtime']) {
         // 2. 立即通知用户
         WeUtility::logging('step3.0', $from_user);
         if (!empty($ch['genqr_info1'])) {
             $ret = $weapi->sendText($from_user, $ch['genqr_info1']);
         }
         WeUtility::logging('step3.1', '');
         // 3.1 uid在qr表中不存在,则立即创建二维码,并插入qr表,然后返回信息
         $scene_id = $qr_mgr->getNextAvaliableSceneID();
         list($media_id, $target_file_url) = $this->genImage($weapi, $scene_id, $channel, $from_user);
         if (!empty($media_id) and !empty($ch['genqr_info2'])) {
             $ret = $weapi->sendText($from_user, $ch['genqr_info2']);
         }
         if (!empty($scene_id)) {
             WeUtility::logging('begin setQR', '');
             // 老的QR不删除,因为二维码已经生成并且发布流传,删除后其他人关注后无法发放积分
             $qr_mgr->newQR($scene_id, $target_file_url, $media_id, $channel);
             WeUtility::logging('end setQR', '');
         } else {
             $ret = $weapi->sendText($from_user, '海报已经发完,活动暂停。下一期活动即将开始,会通知给大家。谢谢!');
             exit(0);
         }
     } else {
         if (!empty($ch['genqr_info3'])) {
             $ret = $weapi->sendText($from_user, $ch['genqr_info3']);
         }
         WeUtility::logging('step3.2', '');
         // 3.2 uid在qr表中存在,则直接返回信息
         $media_id = $qr['media_id'];
         $target_file_url = $qr['qr_url'];
     }
     // 4. 将qr信息推送给用户
     WeUtility::logging('step4', $media_id);
     if (!empty($media_id)) {
         $ret = $weapi->sendImage($from_user, $media_id);
     } else {
         $ret = $weapi->sendText($from_user, "您的专属海报已生成成功,打开后长按图片保存到手机后转发到朋友圈或微信群就能赚积分换话费啦!之前保存的专属海报依然有效,直接转发即可!");
         $ret = $weapi->sendText($from_user, "<a href='{$target_file_url}'>【点击这里查看您的专属海报】</a>");
     }
     // 5. 同步回复一个空字符串,结束本次请求
     WeUtility::logging('step5', '');
     exit(0);
 }
Esempio n. 4
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;
 }
Esempio n. 5
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);
 }