乐淘资源 干货福利 uni-app 139发布朋友圈api开发(一)

uni-app 139发布朋友圈api开发(一)

广告位

/app/controller/moment.js

'use strict';

const Controller = require('egg').Controller;

class MomentController extends Controller {
// 发布朋友圈
async create() {
const { ctx, app } = this;
let current_user_id = ctx.authUser.id;
// 参数验证
ctx.validate({
content: {
type: 'string',
required: false,
desc: '内容'
},
image: {
type: 'string',
required: false,
desc: '图片'
},
video: {
type: 'string',
required: false,
desc: '视频'
},
type: {
type: 'string',
required: true,
range: {
in: ['content', 'image', 'video'] },
desc: '朋友圈类型'
},
location: {
type: 'string',
required: false,
desc: '位置'
},
remind: {
type: 'string',
required: false,
defValue: "",
desc: '提醒谁看'
},
see: {
type: 'string',
required: false,
defValue: "all",
desc: '谁可以看'
}
});

let { content, image, video, type, location, remind, see } = ctx.request.body;

if (!ctx.request.body[type]) {
return ctx.apiFail(`${type} 不能为空`);
}

let moment = await app.model.Moment.create({
content, image, video, location, remind, see,
user_id: current_user_id
});

if (!moment) {
return ctx.apiFail('发布失败');
}

// 推送到好友的时间轴
this.toTimeline(moment);

ctx.apiSuccess('ok');
}

// 推送到好友的时间轴
async toTimeline(moment) {
const { ctx, app } = this;
let current_user_id = ctx.authUser.id;
// 获取当前用户所有好友
let friends = await app.model.Friend.findAll({
where: {
user_id: current_user_id,
isblack: 0
},
attributes: ['friend_id'] });
// 谁可以看
/**
all 全部人可看
only:1,2,3 指定人可见
except:1,2,3 谁不可看
none 仅自己可见
*/
let sees = moment.see.split(':');
let o = {
only: [],
except: [] }
let oType = sees[0];
if ((sees[0] === 'only' || sees[0] === 'except') && sees[1]) {
o[sees[0]] = (sees[1].split(',')).map(v => parseInt(v));
}


}



}

module.exports = MomentController;

感谢大家观看,我们下次见

本文来自网络,不代表乐淘资源立场,转载请注明出处,如有侵权问题需要处理,请联系站长删除。联系QQ 917118162

作者: admin

上一篇
下一篇
广告位
联系我们

联系我们

在线咨询: QQ交谈

邮箱: 917118162@qq.com

工作时间:周一至周五,9:00-17:30
关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部