Giter Site home page Giter Site logo

ksky521 / fresh-weather Goto Github PK

View Code? Open in Web Editor NEW
331.0 10.0 78.0 428 KB

新鲜天气:使用小程序·云开发的小程序

Home Page: https://juejin.im/book/5b70f101e51d456669381803/

JavaScript 97.94% CSS 2.06%
wechat-mini-program mini-program miniprogram wechat weather tcb tencent-cloud

fresh-weather's Issues

本地开发报错解决方案

按书籍中做了各种配置后,本地跑起来后报错,加载失败,请稍后再试

经排查,需要进入一下几步操作

  1. client/project.config.json 文件中需要添加 appid, 否则会报appid missing 的错误
  2. server/cloud-functions/he-weather/index.js 文件需要修改为如下。key替换为自己的密钥。
    否则会拿不到天气数据。因为和风天气的接口改了。
    接口是https://www.heweather.com/documents/api/s6/weather-all。
    返回的数据结构和以前一样。
const API_URL = 'https://free-api.heweather.net/s6/weather'
const request = require('request')

/*<jdists import="../../inline/utils.js" />*/

/*<remove>*/
const $ = require('../../inline/utils')
/*</remove>*/

exports.main = async (event) => {
  const {lat,lon} = event
  let location = `${lat},${lon}`
  let params = {
    location,
    key: '-----------------'  //替换为密钥
    // t: Math.floor(Date.now() / 1e3),
    // unit: 'm'
  }
  // 生成签名
  // params.sign = $.generateSignature(params)
  let query = []
  for (let i in params) {
    query.push(`${i}=${encodeURIComponent(params[i])}`)
  }
  let url = API_URL + '?' + query.join('&')
  console.log(url)

  return new Promise((resolve, reject) => {
    request.get(url, (error, response, body) => {
      console.log(body)
      if (error || response.statusCode !== 200) {
        reject(error)
      } else {
        try {
          let rs = $.handlerData(JSON.parse(body))
          console.log(rs)

          resolve(rs)
        } catch (e) {
          reject(e)
        }
      }
    })
  })
}


vscode 本地调试 云函数出错

1 代码中有从数据库获取数据;在 vscode 中 报错
Error: errCode: -1 unknown error \| errMsg: document.get:fail Error: missing secretId or secretKey of tencent cloud; at document.get api;
不知道接下来该如何进行了;

2 在控制台的日志中,makeImage 函数中的 console.log 打印不出来

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.