74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
using Nancy;
|
|||
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using Nancy.ModelBinding;
|
||
|
|
using Newtonsoft.Json;
|
||
|
|
|
||
|
|
namespace HxBusiness
|
||
|
|
{
|
||
|
|
public class APIContainer : NancyModule
|
||
|
|
{
|
||
|
|
public APIContainer()
|
||
|
|
{
|
||
|
|
var tasks = new Dictionary<int, string>();
|
||
|
|
//Get["api/get"] = GetStr;
|
||
|
|
Get("api/get", parameters => GetStr(parameters));
|
||
|
|
//更新任务
|
||
|
|
//Post("api/sendpermission") = UpdateTraffic;
|
||
|
|
Post("api/sendpermission", parameters => UpdateTraffic(parameters));
|
||
|
|
|
||
|
|
}
|
||
|
|
private object GetStr(dynamic o)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
string str = Request.Query["id"];
|
||
|
|
return "test Api" + str;
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
return ex.ToString();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/// <summary>
|
||
|
|
/// 更新任务
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="o"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
private object UpdateTraffic(dynamic o)
|
||
|
|
{
|
||
|
|
ResponseModel resultmodel = new ResponseModel();
|
||
|
|
try
|
||
|
|
{
|
||
|
|
string[] tagPoint = { "280", "282" };
|
||
|
|
SendModel parmmodel = this.Bind<SendModel>();
|
||
|
|
string str = JsonConvert.SerializeObject(parmmodel);
|
||
|
|
WriteTxt.SaveLog1("接收到授权请求!" + str, "api日志");
|
||
|
|
if (parmmodel.interchangePointCode.Equals(tagPoint[0]) || parmmodel.interchangePointCode.Equals(tagPoint[1]))
|
||
|
|
{
|
||
|
|
|
||
|
|
resultmodel.code = 0;
|
||
|
|
resultmodel.msg = "成功";
|
||
|
|
resultmodel.data = "";
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
resultmodel.code = -2;
|
||
|
|
resultmodel.msg = "交汇点地标不存在!";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
resultmodel.code = -1;
|
||
|
|
resultmodel.data = "服务器错误:" + ex.ToString();
|
||
|
|
}
|
||
|
|
return JsonConvert.SerializeObject(resultmodel);
|
||
|
|
}
|
||
|
|
|
||
|
|
public object Root(dynamic o)
|
||
|
|
{
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|