public async Task TestGetReGeoCode() { ReGeoParameter reGeoParameter = new ReGeoParameter() { Location = "116.481488,39.990464", Batch = false, Output = "JSON", Radius = 1000, RoadLevel = 0, Extensions = "base", Poitype = string.Empty }; IAmapWebApi jobsManager = _serviceProvider.GetService <IAmapWebApi>(); var jobs = await jobsManager.GetRegeoAsync(reGeoParameter); Assert.True(jobs.ReGeoCode.AddressComponent.Country == "中国"); }
protected override async Task <APIGatewayProxyResponseEvent> Handler(SCFContext context, APIGatewayProxyRequestEvent requestEvent) { if (requestEvent != null && requestEvent.RequestContext == null) { return(new APIGatewayProxyResponseEvent() { ErrorCode = 410, ErrorMessage = "event is not come from api gateway", }); } if (requestEvent != null) { if (requestEvent.Path != "/api/jobs/getjobs" && requestEvent.Path != "/api/jobs/getdetailsinfo" && requestEvent.Path != "/api/geocode/regeo") { return(new APIGatewayProxyResponseEvent() { ErrorCode = 411, ErrorMessage = "request is not from setting api path" }); } if (requestEvent.Path == "/api/jobs/getjobs" && requestEvent.HttpMethod.ToUpper() == "GET") { string sources = requestEvent.QueryString["sources"]; string city = requestEvent.QueryString["city"]; string searchKey = requestEvent.QueryString["searchkey"]; string pageIndex = requestEvent.QueryString["pageindex"]; var jobs = await jobsManager.GetJobsAsync(sources.Split('-').ToList(), city, searchKey, int.Parse(pageIndex)); var response = new APIGatewayProxyResponseEvent() { StatusCode = 200, ErrorCode = 0, ErrorMessage = "", Body = JsonConvert.SerializeObject(jobs), IsBase64Encoded = false, Headers = new Dictionary <string, string>() }; response.Headers.Add("Content-Type", "application/json"); response.Headers.Add("Access-Control-Allow-Origin", "*"); return(response); } if (requestEvent.Path == "/api/jobs/getdetailsinfo" && requestEvent.HttpMethod.ToUpper() == "GET") { string source = requestEvent.QueryString["source"]; string url = requestEvent.QueryString["url"]; var jobs = await jobsManager.GetDetailsInfo(source, url); var response = new APIGatewayProxyResponseEvent() { StatusCode = 200, IsBase64Encoded = false, Headers = new Dictionary <string, string>() }; if (jobs == null) { response.ErrorCode = -1; response.ErrorMessage = "user code exception caught"; } else { response.ErrorCode = 0; response.ErrorMessage = ""; response.Body = JsonConvert.SerializeObject(jobs); } response.Headers.Add("Content-Type", "application/json"); response.Headers.Add("Access-Control-Allow-Origin", "*"); return(response); } if (requestEvent.Path == "/api/geocode/regeo" && requestEvent.HttpMethod.ToUpper() == "GET") { string location = requestEvent.QueryString["location"]; ReGeoParameter reGeoParameter = new ReGeoParameter() { Location = location, Batch = false, Output = "JSON", Radius = 1000, RoadLevel = 0, Extensions = "base", Poitype = string.Empty }; var regeo = await amapWebApi.GetRegeoAsync(reGeoParameter); var response = new APIGatewayProxyResponseEvent() { StatusCode = 200, IsBase64Encoded = false, Headers = new Dictionary <string, string>() }; if (regeo == null) { response.ErrorCode = -1; response.ErrorMessage = "user code exception caught"; } else { response.ErrorCode = 0; response.ErrorMessage = ""; response.Body = string.IsNullOrEmpty(regeo.ReGeoCode.AddressComponent.City) ? regeo.ReGeoCode.AddressComponent.Province : regeo.ReGeoCode.AddressComponent.City; } response.Headers.Add("Content-Type", "application/json"); response.Headers.Add("Access-Control-Allow-Origin", "*"); return(response); } } return(new APIGatewayProxyResponseEvent() { ErrorCode = 413, ErrorMessage = "request is not correctly execute" }); }