时间:2021-07-01 10:21:17 帮助过:22人阅读
// 微博同步function post_to_sina_weibo($post_ID) { if( wp_is_post_revision($post_ID) ) return; $get_post_info = get_post($post_ID); $get_post_centent = get_post($post_ID)->post_content; //去掉文章内的html编码的空格、换行、tab等符号(如果你文章的编码格式是这样子,可以将下面的"//"去掉即开启此功能) //$get_post_centent = str_replace("\t", " ", str_replace("\n", " ", str_replace(" ", " ", $get_post_centent))); $get_post_title = get_post($post_ID)->post_title; if ( $get_post_info->post_status == 'publish' && $_POST['original_post_status'] != 'publish' ) { $request = new WP_Http; $status = '【' . strip_tags( $get_post_title ) . '】 ' . mb_strimwidth(strip_tags( apply_filters('the_content', $get_post_centent)),0, 132,'...') . ' 全文地址:' . get_permalink($post_ID) ; $api_url = 'https://api.weibo.com/2/statuses/update.json'; $body = array( 'status' => $status, 'source'=>'4135063399'); $headers = array( 'Authorization' => 'Basic ' . '1fFjYc3uQHZpcF32fS5jb146MxFeY19DYF53aWfzNA==' ); /* 如果你使用改方法,请注释掉上面$headers = array( 'Authorization' => 'Basic ' . '1fFjYc3uQHZpcF32fS5jb146MxFeY19DYF53aWfzNA==' ); 换成如下代码 //你的新浪微博登陆名 $username = '' ; //你的新浪微博登陆密码 $password = '' ; $headers = array( 'Authorization' => 'Basic ' . base64_encode('$username:$password')); */ $result = $request->post( $api_url , array( 'body' => $body, 'headers' => $headers ) ); }}add_action('publish_post', 'post_to_sina_weibo', 0);
$status, 'source'=>'这里appkey');$headers = array( 'Authorization' => 'Basic ' .'这里64位编码后的用户名和密码' );$result = $r->post( $api_url , array('body' => $body, 'headers' => $headers ) );print_r($result);?>
还是看这个博客吧,,,http://zhangge.net/4947.html