Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

本地开发报错解决方案 #4

Closed
sunchenguang opened this issue Feb 20, 2019 · 1 comment
Closed

本地开发报错解决方案 #4

sunchenguang opened this issue Feb 20, 2019 · 1 comment

Comments

@sunchenguang
Copy link
Contributor

sunchenguang commented Feb 20, 2019

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

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

  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)
        }
      }
    })
  })
}


@ksky521
Copy link
Owner

ksky521 commented Mar 12, 2019

可以提交个pr啊~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants