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

测试微博

@@ -15,6 +15,7 @@ use cmf\lib\Storage; @@ -15,6 +15,7 @@ use cmf\lib\Storage;
15 use think\Db; 15 use think\Db;
16 use anerg\OAuth2\OAuth; 16 use anerg\OAuth2\OAuth;
17 use think\Config; 17 use think\Config;
  18 +use app\portal\model\PortalPostModel;
18 19
19 class LoginController extends HomeBaseController 20 class LoginController extends HomeBaseController
20 { 21 {
@@ -450,6 +451,7 @@ class LoginController extends HomeBaseController @@ -450,6 +451,7 @@ class LoginController extends HomeBaseController
450 $token = session('token'); 451 $token = session('token');
451 $title = $this->request->post('title');//分享标题 452 $title = $this->request->post('title');//分享标题
452 $share_url = $this->request->post('share_url');//分享url 453 $share_url = $this->request->post('share_url');//分享url
  454 + $article_id = $this->request->post('article_id');//分享文章id
453 $url = 'https://api.weibo.com/2/statuses/share.json'; 455 $url = 'https://api.weibo.com/2/statuses/share.json';
454 $data = [ 456 $data = [
455 'access_token' => $token, 457 'access_token' => $token,
@@ -460,6 +462,8 @@ class LoginController extends HomeBaseController @@ -460,6 +462,8 @@ class LoginController extends HomeBaseController
460 if(isset($json_arr['error_code'])&&!empty($json_arr['error_code'])){ 462 if(isset($json_arr['error_code'])&&!empty($json_arr['error_code'])){
461 $this->apiResponse(0,$json_arr['error']); 463 $this->apiResponse(0,$json_arr['error']);
462 } 464 }
  465 + $postModel = new PortalPostModel();
  466 + $postModel->where('id',$article_id)->setInc('post_share_wb',1);
463 $this->apiResponse(1,'分享成功!'); 467 $this->apiResponse(1,'分享成功!');
464 } 468 }
465 469
@@ -113,7 +113,7 @@ @@ -113,7 +113,7 @@
113 <input type="hidden" class="collection" value=""> 113 <input type="hidden" class="collection" value="">
114 <input type="hidden" class="like" value=""> 114 <input type="hidden" class="like" value="">
115 <img src="__TMPL__/public/assets/starImg/aicon_89.png" alt=""> 115 <img src="__TMPL__/public/assets/starImg/aicon_89.png" alt="">
116 - <img src="__TMPL__/public/assets/starImg/aicon_90.png" alt=""> 116 + <img src="__TMPL__/public/assets/starImg/aicon_90.png" alt="" class="wb_share">
117 <img id="collections" src="__TMPL__/public/assets/starImg/bicon_02.png" alt=""> 117 <img id="collections" src="__TMPL__/public/assets/starImg/bicon_02.png" alt="">
118 <img id="likes" src="__TMPL__/public/assets/starImg/bicon_031.png" alt=""> 118 <img id="likes" src="__TMPL__/public/assets/starImg/bicon_031.png" alt="">
119 </div> 119 </div>
@@ -198,7 +198,7 @@ $(function() { @@ -198,7 +198,7 @@ $(function() {
198 }); 198 });
199 199
200 //微博分享 200 //微博分享
201 - $('#wb_share').click(function() { 201 + $('.wb_share').click(function() {
202 thirdShare('/portal/login/wb_share'); 202 thirdShare('/portal/login/wb_share');
203 }); 203 });
204 204
@@ -212,10 +212,12 @@ $(function() { @@ -212,10 +212,12 @@ $(function() {
212 function thirdShare(url){ 212 function thirdShare(url){
213 var title = $(document).attr("title"); 213 var title = $(document).attr("title");
214 var share_url = window.location.href; 214 var share_url = window.location.href;
  215 + var article_id = getUrlParam('id');
215 $.ajax({ 216 $.ajax({
216 type: 'POST', 217 type: 'POST',
217 url: url, 218 url: url,
218 data: { 219 data: {
  220 + 'id': article_id,
219 'title': title, 221 'title': title,
220 'share_url': share_url 222 'share_url': share_url
221 }, 223 },
@@ -19,11 +19,11 @@ @@ -19,11 +19,11 @@
19 <!-- wx分享 --> 19 <!-- wx分享 -->
20 <div class="wx_go weixin"> 20 <div class="wx_go weixin">
21 <img src="__TMPL__/public/assets/starImg/bicon_04.png" alt=""> 21 <img src="__TMPL__/public/assets/starImg/bicon_04.png" alt="">
22 - <p>168</p> 22 + <p>{$share.post_share_wx}</p>
23 </div> 23 </div>
24 <!-- wb分享 --> 24 <!-- wb分享 -->
25 - <div class="wb_go weibo_share" id="wb_share"> 25 + <div class="wb_go wb_share">
26 <img src="__TMPL__/public/assets/starImg/bicon_05.png" alt=""> 26 <img src="__TMPL__/public/assets/starImg/bicon_05.png" alt="">
27 - <p>168</p> 27 + <p>{$share.post_share_wx}</p>
28 </div> 28 </div>
29 </div> 29 </div>
@@ -138,7 +138,7 @@ @@ -138,7 +138,7 @@
138 <img src="__TMPL__/public/assets/images/cicon_71@2x.png" alt="" /> 138 <img src="__TMPL__/public/assets/images/cicon_71@2x.png" alt="" />
139 </div> 139 </div>
140 <div class="index_seventh_bottom_img1"> 140 <div class="index_seventh_bottom_img1">
141 - <img src="__TMPL__/public/assets/images/cicon_72@2x.png" alt="" /> 141 + <img src="__TMPL__/public/assets/images/cicon_72@2x.png" alt="" class="wb_share"/>
142 </div> 142 </div>
143 <div class="index_seventh_bottom_img2" style="margin-left:0.3rem;"> 143 <div class="index_seventh_bottom_img2" style="margin-left:0.3rem;">
144 <img id="collections" src="__TMPL__/public/assets/images/bicon_02.png" alt=""> 144 <img id="collections" src="__TMPL__/public/assets/images/bicon_02.png" alt="">
@@ -231,19 +231,40 @@ $(function() { @@ -231,19 +231,40 @@ $(function() {
231 } 231 }
232 window.open('http://v.t.sina.com.cn/share/share.php?' + temp.join('&')); 232 window.open('http://v.t.sina.com.cn/share/share.php?' + temp.join('&'));
233 }); 233 });
  234 + //微博分享
  235 + $('.wb_share').click(function() {
  236 + thirdShare('/portal/login/wb_share');
  237 + });
234 238
235 //微博登录 239 //微博登录
236 $('#wb_login').click(function(){ 240 $('#wb_login').click(function(){
237 $('#wb_form').submit(); 241 $('#wb_form').submit();
238 }); 242 });
239 -  
240 - //分享到微信  
241 - // $('.weixin').click(function(){  
242 - // var target_url = "http://qr.liantu.com/api.php?text="+share_url;  
243 - // window.open(target_url, 'weixin', 'height=320, width=320');  
244 - // });  
245 }); 243 });
246 - 244 +//第三方分享
  245 +function thirdShare(url){
  246 + var title = $(document).attr("title");
  247 + var share_url = window.location.href;
  248 + var article_id = getUrlParam('id');
  249 + $.ajax({
  250 + type: 'POST',
  251 + url: url,
  252 + data: {
  253 + 'id': article_id,
  254 + 'title': title,
  255 + 'share_url': share_url
  256 + },
  257 + dataType: 'json',
  258 + async: false,
  259 + success: function(data) {
  260 + if (data.code == 1) {
  261 + mask(data.msg);
  262 + } else {
  263 + mask(data.msg);
  264 + }
  265 + }
  266 + });
  267 +}
247 //弹框 268 //弹框
248 function mask(msg) { 269 function mask(msg) {
249 $('.mask').text(msg); 270 $('.mask').text(msg);
@@ -4,13 +4,13 @@ @@ -4,13 +4,13 @@
4 <div class="share1_Img weixin"> 4 <div class="share1_Img weixin">
5 <img src="__TMPL__/public/assets/images/bicon_04.png" alt="" /> 5 <img src="__TMPL__/public/assets/images/bicon_04.png" alt="" />
6 </div> 6 </div>
7 - <p class="share1_Txt">3.6k</p> 7 + <p class="share1_Txt">{$share.post_share_wx}</p>
8 </li> 8 </li>
9 <li class="share1"> 9 <li class="share1">
10 - <div class="share1_Img weibo"> 10 + <div class="share1_Img wb_share">
11 <img src="__TMPL__/public/assets/images/bicon_05.png" alt="" /> 11 <img src="__TMPL__/public/assets/images/bicon_05.png" alt="" />
12 </div> 12 </div>
13 - <p class="share1_Txt">168</p> 13 + <p class="share1_Txt">{$share.post_share_wx}</p>
14 </li> 14 </li>
15 <!--收藏--> 15 <!--收藏-->
16 <li class="share2"> 16 <li class="share2">
@@ -15,6 +15,7 @@ use app\admin\model\ThemeModel; @@ -15,6 +15,7 @@ use app\admin\model\ThemeModel;
15 use think\View; 15 use think\View;
16 use app\portal\model\CollectionModel; 16 use app\portal\model\CollectionModel;
17 use app\portal\model\LikeModel; 17 use app\portal\model\LikeModel;
  18 +use app\portal\model\PortalPostModel;
18 use think\Session; 19 use think\Session;
19 20
20 class HomeBaseController extends BaseController 21 class HomeBaseController extends BaseController
@@ -34,6 +35,7 @@ class HomeBaseController extends BaseController @@ -34,6 +35,7 @@ class HomeBaseController extends BaseController
34 $this->getComment(); 35 $this->getComment();
35 $this->is_collection(); 36 $this->is_collection();
36 $this->is_like(); 37 $this->is_like();
  38 + $this->getShareCount();
37 $keyword = $this->request->param('keyword'); 39 $keyword = $this->request->param('keyword');
38 $this->assign('keyword',$keyword); 40 $this->assign('keyword',$keyword);
39 } 41 }
@@ -385,4 +387,12 @@ hello; @@ -385,4 +387,12 @@ hello;
385 } 387 }
386 } 388 }
387 389
  390 + //获取微信微博分享数量
  391 + public function getShareCount(){
  392 + $article_id = $this->request->param('id');//文章id
  393 + $postModel = new PortalPostModel();
  394 + $share = $postModel->where(['id'=>$article_id])->field('id,post_share_wx,post_share_wb')->find();
  395 + $this->assign('share',$share);
  396 + }
  397 +
388 } 398 }