本文主要是介绍discuzx3.4手机版个人中心添加自定义接口,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.前端在 discuz\upload\template\bigstyles\touch\static\src\home\uc.js 那里添加js
var uc_data = require('data/uc_data'); //加载js文件 usercenter_data = uc_data.getUserCenterData(); //获取接口数据
2.前端在 discuz\upload\template\bigstyles\touch\static\src\data 新建js文件 uc_data.js 内容如下:
/* 首页帖子数据 */ define(function(require){var ajax=require('ajax');var o={};// 获取发帖数、评论数、被赞数 o.getUserCenterData = function(fid) {var list = [];var api = 'version=4&module=usercenter';MWT.show_loading();ajax.post(api,{},function(res){MWT.hide_loading();list['posts'] = res['Variables']['usercenter']['member_count']['posts'] - res['Variables']['usercenter']['member_count']['threads'] > 0 ? res['Variables']['usercenter']['member_count']['posts'] - res['Variables']['usercenter']['member_count']['threads'] : 0;list['threads'] = res['Variables']['usercenter']['member_count']['threads'];list['recommend_add_count'] = res['Variables']['usercenter']['recommend']['recommend_add_count'];},true);return list;};return o; });
3. 修改 discuz\upload\forum.php 大概21行修改以下内容:
$modarray = array('ajax','announcement','attachment','forumdisplay', 'group','image','index','medal','misc','modcp','notice','post','redirect', 'rss','topicadmin','trade','viewthread','tag','collection','guide', //自定义接口 'usercenter' );
4. 修改 discuz\upload\source\plugin\mobile\mobile.php 大概 17行 修改以下内容:
$modules = array('extends', 'buyattachment', 'buythread', 'checkpost', 'connect', 'favforum', 'favthread', 'forumdisplay', 'forumindex', 'forumnav', 'forumupload', 'friend', 'hotforum', 'hotthread', 'login', 'myfavforum', 'myfavthread', 'mypm', 'mythread', 'newthread', 'profile', 'publicpm', 'register', 'seccode', 'secure', 'sendpm', 'sendreply', 'sub_checkpost', 'sublist', 'toplist', 'viewthread', 'uploadavatar', 'pollvote', 'mynotelist', 'credit', 'profiles', 'modcp', 'topicadmin', 'forumimage', 'newthreads', 'signin', 'smiley', 'threadrecommend', 'check', 'mobilesign', 'wsqindex', 'wsqsiteinfo', 'recommend', 'wechat', 'wechat_clearlogin', 'checkinfo', 'seccodehtml', 'showactivity', 'bestanswer', 'forummisc', 'checkcookie', 'checknewpm', 'viewcomment', 'plugin', //自定义接口 'usercenter' );
5.添加 discuz\upload\source\plugin\mobile\api\4 新建php文件 usercenter.php 内容如下:
<?php /** * [Discuz!] (C)2001-2099 Comsenz Inc. * This is NOT a freeware, use is subject to license terms * * $Id: forumdisplay.php 35213 2015-02-26 06:15:12Z nemohou $ */ if (!defined('IN_MOBILE_API')) { exit('Access Denied'); } $_GET['mod'] = 'usercenter'; include_once 'forum.php'; class mobile_api { function common() { } function output() { global $_G; $variable = array( "usercenter" =>$_G['usercenter'], ); mobile_core::result(mobile_core::variable($variable)); } } \mobile_api::output(); ?>
6.添加 discuz\upload\source\module\forum 新建php文件 forum_usercenter.php 内容如下:
<?php /** * [Discuz!] (C)2001-2099 Comsenz Inc. * This is NOT a freeware, use is subject to license terms * * $Id: forum_forumdisplay.php 36328 2016-12-26 00:38:47Z nemohou $ */ if(!defined('IN_DISCUZ')) { exit('Access Denied'); } $member_count = array(); if($_G['uid']){ $member_count = C::t('common_member_count')->fetch_all($_G['uid']); //获取发帖数和回复数 $recommend = C::t('forum_thread')->fetch_all_recommend_add($_G['uid']); //获取点赞数 } $_G['usercenter']['member_count'] = $member_count[$_G['uid']]; $_G['usercenter']['recommend'] = $recommend[0]; ?>
至此完成
这篇关于discuzx3.4手机版个人中心添加自定义接口的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!