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

cloud.init({
  // API 调用都保持和云函数当前所在环境一致
  env: 'productapp-hsk0o'
})

var rp = require('request-promise');

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

    // var formData =event.device;
    var formData = {
      devcode:event.device.devcode,
      devicetype:event.device.devicetype,
      description:event.device.description,
      factory:event.device.factory,
      installheigt:event.device.installheigt,
      installperson:event.device.installperson,
      installtimeFmt:event.device.installtimeFmt,
      latitude:event.device.latitude,
      longitude:event.device.longitude,
      latitude84:event.device.latitude84,
      longitude84:event.device.longitude84,
      position:event.device.position,
      wellcode:event.device.wellcode,
      welldepth:event.device.welldepth,
      welltype:event.device.welltype,
      project:event.device.project,
      area:event.device.area,
      street:event.device.street,
      wellname:event.device.wellname,
      // workmsg:event.device.workmsg,
      photopath1:event.photopath1,
      photopath2:event.photopath2,
      photopath3:event.photopath3,
    }

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