Пример #1
0
 private function status_bind($id, $text, $pic_id)
 {
     include_once ROOT_DIR . 'lib/user/user.class.php';
     $this->mUser = new user();
     $bind_info = $this->mUser->get_bind_info();
     //获取绑定信息
     include_once ROOT_PATH . 'lib/class/status.class.php';
     $status = new status();
     if (!$bind_info) {
         //do nothing!
     } else {
         //file_put_contents('d:/show.txt', '用户绑定了' , FILE_APPEND);
         $bind_info = $bind_info[0];
         if ($bind_info['state'] == 1 && $bind_info['last_key']) {
             //file_put_contents('d:/show.txt', '用户开启同步了' , FILE_APPEND);
             include_once ROOT_PATH . 'lib/class/weibooauth.class.php';
             $last_key = unserialize($bind_info['last_key']);
             $oauth = new WeiboClient(WB_AKEY, WB_SKEY, $last_key['oauth_token'], $last_key['oauth_token_secret']);
             //$oauth = new WeiboOAuth( WB_AKEY , WB_SKEY , 'e9b1d743a687550cec725e65fd204b6c' , '119934aabf1632d426533505c0f02e70' );
             //判断是否发送了图片
             if ($pic_id) {
                 //file_put_contents('d:/show.txt', '用户发送了图片' , FILE_APPEND);
                 //取出该图片的路径
                 //获取媒体信息
                 $pic_url = $status->getPicById($pic_id);
                 $url = $pic_url[0];
                 //$url = 'http://127.0.0.1/3.jpg';
                 $content = $oauth->upload($text, $url);
             } else {
                 $content = $text;
                 $pattern = "/#([\\x{4e00}-\\x{9fa5}0-9A-Za-z_-\\s‘’“”'\"!\\?\$%&:;!?¥×\\*\\<\\>》《]+)[\\s#]/iu";
                 if (preg_match_all($pattern, $content, $topic)) {
                     include_once ROOT_PATH . 'lib/class/shorturl.class.php';
                     $shorturl = new shorturl();
                     $link = '';
                     $tmp_url = '';
                     $topic_name = array();
                     foreach ($topic[1] as $key => $value) {
                         $tmp_url = SNS_MBLOG . 'k.php?q=' . urlencode($value);
                         $short_url = $shorturl->shorturl($tmp_url);
                         $link .= $short_url;
                     }
                     $content = $content . $link;
                 }
                 //			    	$content = $oauth->post( $oauth->updateURL() , array( 'status' =>  $content) );
                 $content = $oauth->update($content);
                 //同步发送
             }
             $syn_id = $content['id'];
             //返回点滴的ID
             $type = $bind_info['type'];
             //绑定类型
             /**
              * 记录同步发送的点滴id
              */
             $status->syn_relation($id, $syn_id, $type);
         }
     }
 }