How to use wx-server-sdk - 10 common examples

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 anpeier / lesson_shuidi / wxapp / yun_book / cloudfunctions / login / index.js View on Github external
exports.main = (event, context) => {
  console.log(event)
  console.log(context)

  // 可执行其他自定义逻辑
  // console.log 的内容可以在云开发云函数调用日志查看

  // 获取 WX Context (微信调用上下文),包括 OPENID、APPID、及 UNIONID(需满足 UNIONID 获取条件)等信息
  const wxContext = cloud.getWXContext()

  return {
    event,
    openid: wxContext.OPENID,
    appid: wxContext.APPID,
    unionid: wxContext.UNIONID,
    env: wxContext.ENV,
  }
}
github poyiding / bookshelfMiniApp / cloudfunctions / login / index.js View on Github external
exports.main = (event, context) => {
  // 可执行其他自定义逻辑
  // console.log 的内容可以在云开发云函数调用日志查看

  // 获取 WX Context (微信调用上下文),包括 OPENID、APPID、及 UNIONID(需满足 UNIONID 获取条件)
  const wxContext = cloud.getWXContext()

  return {
    event,
    openid: wxContext.OPENID,
    appid: wxContext.APPID,
    unionid: wxContext.UNIONID,
  }
}
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(),                   //小时   

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