业务逻辑如下:
1 云函数A获取客户名称列表;
2 云函数B通过调用腾讯地图WebService API实现地址解析(地址转坐标),试图实现输入“客户名称”,返回客户名称所在地的经纬度坐标(X,Y)。
https://lbs.qq.com/webservice_v1/guide-geocoder.html
// 云函数入口文件 const cloud = require( 'wx-server-sdk' ) //const request = require('request') const rp = require( 'request-promise' ) //const soap = require('soap') cloud.init() // 云函数入口函数 exports.main = async (event, context) => { const wxContext = cloud.getWXContext() var latitudeAndLongitude = null //request.get() var options = { uri: 'https://apis.map.qq.com/ws/geocoder/v1/?address=' + event.address + '&key=' + event.developerKey, method: 'GET' , json: true } latitudeAndLongitude = await rp(options).then( function (res) { return res }). catch ( function (err) { return err }) return { event, openid: wxContext.OPENID, appid: wxContext.APPID, unionid: wxContext.UNIONID, latitudeAndLongitude: latitudeAndLongitude } } |
报错情况:
云函数B代码如下:
// 云函数入口文件
const cloud = require(‘wx-server-sdk’)
const rp = require(‘request-promise’)
//const soap = require(‘soap’)
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
var latitudeAndLongitude = null
var options = {
uri: ‘https://apis.map.qq.com/ws/geocoder/v1/?address=’ + event.address + ‘&key=’ + event.developerKey,
method: ‘GET’,
json: true
}
latitudeAndLongitude = await rp(options).then(function (res) {
return res
}).catch(function (err) {
return err
})
return {
event,
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
latitudeAndLongitude: latitudeAndLongitude
}
}