How to use the wx-server-sdk.database function in wx-server-sdk

To help you get started, we’ve selected a few wx-server-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github winrey / BJUTHelper_WechatApp / cloud-functions / shareScore / index.js View on Github external
// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database({
  env: process.env.DATABASE_ENV_ID
})
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {

  // 这里获取到的 openId、 appId 和 unionId 是可信的,注意 unionId 仅在满足 unionId 获取条件时返回
  let { OPENID, APPID, UNIONID } = cloud.getWXContext()

  console.log(event.userDetailInfo)

  try{
    

    res = await db.collection('shared_score_results').add({
github ZhuPeng / mp-githubtrending / cloud-functions / triggerpub / index.js View on Github external
const cloud = require('wx-server-sdk')
var rp = require('request-promise');
cloud.init()
const db = cloud.database()
const _ = db.command

exports.main = async (event, context) => {
  const {OPENID} = cloud.getWXContext()
  const {type, openid} = event;
  console.log('trigger:', event, context)
  // 方糖推送
  await pubcontent()

  if (type == 'all' && OPENID != 'ooqTr4hMz05xwBHOU8VgokLyyoU0') {
    console.log("非法的全局推送 openid: ", OPENID)
    return 
  }
  var publist = []
  var content = await pubSimpleContent()
  var trending = await trendingContent()
github GzhiYi / accounting-together / cloudfunctions / deleteGroup / index.js View on Github external
// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
  await db.collection('group').doc(event.groupId).update({
    data: {
      deleted: true
    }
  })
}
github GzhiYi / accounting-together / cloudfunctions / deleteBill / index.js View on Github external
// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
  await db.collection('bill').doc(event.billId).update({
    data: {
      deleted: true
    },
    success() {
    }
  })
}
github lxljl / cloudFns / src / getUserInfo / index.js View on Github external
exports.main = async(event, context) => {
    let {
        OPENID,
        APPID,
        UNIONID
    } = cloud.getWXContext()
    const db = cloud.database()
    return new Promise(async(resolve, reject) => {
        try {
            // 获取数据
            let {
                data
            } = await db.collection('user').where({
                openid: event.openid || OPENID
            }).get()
            if(data.length == 0) throw {code: 7402, data: [], info: '用户不存在!'} 
            resolve({
                code: 0,
                data,
                info: '操作成功!'
            })
        } catch (error) {
            console.log(error)
github eyson / wechat-solita / cloudfunctions / post / index.js View on Github external
* @author: eysonyou
 * @create: 2019-05-16
 */

// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
    // 1.release - 正式
    // 2.test    - 测试
    // env: 'test'
    env: 'release'
});

// 初始化数据库连接
const db = cloud.database();
const _ = db.command;

// 云函数入口函数
exports.main = async(event, context) => {
    // 获取微信上下文
    const wxContext = cloud.getWXContext();

    // 参数
    let params = {
        // 标题
        title: event.title,
        // 内容
        content: event.content,
        // 图片
        fileID: event.fileID,
        // 场景
github ZhuPeng / mp-githubtrending / cloud-functions / cronclean / index.js View on Github external
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  var d = new Date()
  d.setDate(d.getDate() - 3);
  db.collection('history').where({
    requesttime: _.lt(d.toISOString()),
  }).remove()

  await db.collection('gcache').where({
    time: _.lt(d.toISOString()),
  }).remove()

  var d7 = new Date()
github ZhuPeng / mp-githubtrending / cloud-functions / github / index.js View on Github external
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const octokit = require('@octokit/rest')()
const db = cloud.database()
const _ = db.command
db.collection("admin").where({website: "github", type: "token"}).get().then(res => {
  octokit.authenticate({
    type: 'oauth',
    token: res[0].value
  })
})
const per_page = 30;
const page = 1;

function dateFtt(fmt, date) { //author: meizz   
  var o = {
    "M+": date.getMonth() + 1,                 //月份   
    "d+": date.getDate(),                    //日   
    "h+": date.getHours(),                   //小时   
    "H+": date.getHours(),                   //小时   
github lxljl / cloudFns / src / sendMsg / index.js View on Github external
exports.main = async(event, context) => {
    let {
        OPENID,
        APPID,
        UNIONID
    } = cloud.getWXContext()
    const db = cloud.database()
    return new Promise(async(resolve, reject) => {
        try {
            if(!event.formId) throw {code: 7406, data: [], info: 'formId不能为空!'}
            let page = event.page || '',
                touser = OPENID,
                formId = event.formId,
                name = event.name,
                amount = event.amount,
                payAmount = event.payAmount,
                templateId = 'xxxxxxx', // 模板id
                date = getTime(new Date().getTime() + 28800 * 1000) // 因服务器是格林时间 所以要加8小时
            // 发送模板消息
            const result = await cloud.openapi.templateMessage.send({
                touser, 
                page,
                data: {
github lxljl / cloudFns / src / getWXACodeUnlimit / index.js View on Github external
exports.main = async(event, context) => {
    const db = cloud.database()
    return new Promise(async (resolve, reject) => {
        try {
            if(!event.scene) throw {code: 7400, data: [], info: '场景信息不能为空!'}
            // 一维码信息
            let scene = event.scene,
                page = event.page,
                width = event.width || 430,
                auto_color = event.auto_color || false,
                line_color = event.line_color || {"r":0,"g":0,"b":0},
                is_hyaline = event.is_hyaline || false
            // 请求微信获取图像
            let {
                buffer,
                errcode,
                contentType
            } = await cloud.openapi.wxacode.getUnlimited({

wx-server-sdk

mini program cloud server sdk

MIT
Latest version published 8 months ago

Package Health Score

47 / 100
Full package analysis

Popular wx-server-sdk functions

Similar packages