作者 景龙
1 个管道 的构建 通过 耗费 1 秒

修改微博登录后分享

@@ -463,23 +463,28 @@ class LoginController extends HomeBaseController @@ -463,23 +463,28 @@ class LoginController extends HomeBaseController
463 463
464 //微博分享 464 //微博分享
465 public function wb_share(){ 465 public function wb_share(){
466 - $token = session('token');  
467 - $title = $this->request->post('title');//分享标题  
468 - $share_url = $this->request->post('share_url');//分享url  
469 - $article_id = $this->request->post('id');//分享文章id  
470 - $url = 'https://api.weibo.com/2/statuses/share.json';  
471 - $data = [  
472 - 'access_token' => $token,  
473 - 'status' => $title." ".$share_url  
474 - ];  
475 - $res = $this->http_post($url,$data);  
476 - $json_arr = json_decode($res,true);  
477 - if(isset($json_arr['error_code'])&&!empty($json_arr['error_code'])){  
478 - $this->apiResponse(0,$json_arr['error']); 466 + $login = cmf_is_user_login();
  467 + if($login) {
  468 + $token = session('token');
  469 + $title = $this->request->post('title');//分享标题
  470 + $share_url = $this->request->post('share_url');//分享url
  471 + $article_id = $this->request->post('id');//分享文章id
  472 + $url = 'https://api.weibo.com/2/statuses/share.json';
  473 + $data = [
  474 + 'access_token' => $token,
  475 + 'status' => $title . " " . $share_url
  476 + ];
  477 + $res = $this->http_post($url, $data);
  478 + $json_arr = json_decode($res, true);
  479 + if (isset($json_arr['error_code']) && !empty($json_arr['error_code'])) {
  480 + $this->apiResponse(0, $json_arr['error']);
  481 + }
  482 + $postModel = new PortalPostModel();
  483 + $postModel->where('id', $article_id)->setInc('post_share_wb', 1);
  484 + $this->apiResponse(1, '分享成功!');
  485 + }else{
  486 + $this->apiResponse(0, '请使用微博登录后操作!');
479 } 487 }
480 - $postModel = new PortalPostModel();  
481 - $postModel->where('id',$article_id)->setInc('post_share_wb',1);  
482 - $this->apiResponse(1,'分享成功!');  
483 } 488 }
484 489
485 //取消授权 490 //取消授权