예제 #1
0
 /**
  * 当用户第一次关注公众号的时候,进行数据库插入操作
  * @param referer  0 为搜索关注,1 为二维码关注
  * @param type  二维码类型,1 为临时二维码,2为永久
  */
 public function weixin_subscribe($openid, $referer = 0, $sell_id = 0)
 {
     $sqlUser = new sql_userMod();
     $res = $sqlUser->get_user_openid($openid);
     if ($res) {
         $sqlUser->set_user_subscribe($res['p_id'], $res['sub_time'] + 1);
     } else {
         $r = connectRedis($this->config['RD_HOST'], $this->config['RD_PORT'], $this->config['RD_DB']);
         $token = $r->get('token');
         $wx_res = Weixin::get_user_info($token, $openid);
         if ($wx_res) {
             $res = $sqlUser->add_user_subscribe($wx_res, $referer, str_replace('sell_id', '', $sell_id));
             dump($res);
         }
     }
 }
예제 #2
0
 private function receiveEvent($object)
 {
     $contentStr = '';
     switch ($object->Event) {
         case 'subscribe':
             $weixin = new Weixin();
             $info = $weixin->get_user_info($object->FromUserName);
             $password = rand(100, 999) . rand(100, 999);
             $return = empty($info['nickname']) ? NULL : WeixinData::SetUser($object->FromUserName, $info['nickname'], $password);
             if (isset($return)) {
                 $contentStr = is_array($return) ? '你已经关注且注册过帐号请再扫描二维码登录......帐号是:' . $return[0]['username'] : '******' . $info['nickname'] . '密码:' . $password;
             } else {
                 $contentStr = '不是有效的openid,请在手机端操作!!openid是:' . $object->FromUserName;
             }
             break;
         case 'unsubscribe':
             $contentStr = '取消关注';
             break;
         case 'SCAN':
             $weixin = new Weixin();
             $info = $weixin->get_user_info($object->FromUserName);
             $return = WeixinData::GetUser($object->FromUserName);
             if (!empty($return)) {
                 $login = WeixinData::SetweixinUser($object->FromUserName, $info['nickname'], $object->EventKey);
                 $contentStr = empty($login) ? '由于数据处理错误,登录失败!' : $info['nickname'] . '在AliceBlog的帐号已经登录啦,请等待跳转~登录数字:' . $object->EventKey;
             } else {
                 $contentStr = 'sorry,网站并没有你的帐号,请联系管理员。openid是:' . $object->FromUserName;
             }
             break;
         case 'LOCATION':
             $contentStr = '上传位置:纬度 ' . $object->Latitude . ';经度 ' . $object->Longitude;
             break;
         case 'CLICK':
             switch ($object->EventKey) {
                 case 'company':
                     $contentStr[] = array('Title' => '个人简介', 'Description' => '我的个人微博及个人Blog', 'PicUrl' => 'http://discuz.comli.com/weixin/weather/icon/cartoon.jpg', 'Url' => 'http://520.leunico.sinaapp.com/');
                     break;
                 case '游戏':
                     $contentStr[] = array('Title' => 'OAuth2.0网页授权演示', 'Description' => 'OAuth2.0网页授权演示', 'PicUrl' => 'http://discuz.comli.com/weixin/weather/icon/cartoon.jpg', 'Url' => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb33bef172a0860cf&redirect_uri=http://520.leunico.sinaapp.com/wechat/oauth.php&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect');
                     break;
                 default:
                     $contentStr[] = array('Title' => '默认菜单回复', 'Description' => '您正在使用的是Leunico测试帐号的自定义菜单测试接口', 'PicUrl' => 'http://discuz.comli.com/weixin/weather/icon/cartoon.jpg', 'Url' => 'http://520.leunico.sinaapp.com/');
                     break;
             }
             break;
         default:
             $contentStr = '未找到事件';
             break;
     }
     if (is_array($contentStr)) {
         $resultStr = $this->transmitNews($object, $contentStr);
     } else {
         $resultStr = $this->transmitText($object, $contentStr);
     }
     return $resultStr;
 }