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

cloud.init({
  env: "productapp-hsk0o"
})
const rp = require('request-promise')
// 云函数入口函数
exports.main = async (event, context) => {
 

  // return await rp(encodeURI('http://111.198.10.15:11604/appDeviceLog/listPage?devcode='+ event.devcode+'&devtype='+event.devtype
  // +'&installtimeFmt='+event.installtimeFmt
  // +'&project='+event.project)).then(res => {
  //   console.log(res);
  //   return res;
  // }).catch(err => {
  //   console.log(err);
  // });


  var formData = {
    devcode: event.devcode==undefined?"":event.devcode,
    devtype:event.devtype==undefined?"":event.devtype,
    installtimeFmt:event.installtimeFmt==undefined?"":event.installtimeFmt,
    project:event.project==undefined?"":event.project,
    installPerson:event.installPerson==undefined?"":event.installPerson,
    limit:event.limit,
    offset:event.offset
  }
  return await new Promise((resolve, reject) => {
    rp({
      url: event.url,
      method: "POST",
      json: true,
      formData: formData,
      headers: {
        // "content-type": "application/json",
        "content-Type": "application/x-www-form-urlencoded",
        // 'User-Agent': 'Request-Promise'
        // "token": event.token
      },
    }, function (error, response, body) {
      console.log("响应" + body)
      resolve(body)
      if (!error && response.statusCode == 200) {
        try {
        } catch (e) {
          reject()
        }
      }
    })
  })

}