|
@@ -11,6 +11,7 @@ using System.Text;
|
|
using System.IO;
|
|
using System.IO;
|
|
using Library;
|
|
using Library;
|
|
using LitJson;
|
|
using LitJson;
|
|
|
|
+using MySystem.Models;
|
|
|
|
|
|
namespace MySystem.Areas.Api.Controllers
|
|
namespace MySystem.Areas.Api.Controllers
|
|
{
|
|
{
|
|
@@ -30,9 +31,19 @@ namespace MySystem.Areas.Api.Controllers
|
|
JsonData data = JsonMapper.ToObject(value);
|
|
JsonData data = JsonMapper.ToObject(value);
|
|
string AppId = data["appId"].ToString(); //小程序AppId
|
|
string AppId = data["appId"].ToString(); //小程序AppId
|
|
string AuthCode = data["authCode"].ToString(); //小程序授权码
|
|
string AuthCode = data["authCode"].ToString(); //小程序授权码
|
|
|
|
+ Projects pro = db.Projects.FirstOrDefault(m => m.AppId == AppId);
|
|
|
|
+ if(pro == null)
|
|
|
|
+ {
|
|
|
|
+ return Json(new AppResultJson() { Status = "-1", Info = "appid不存在" });
|
|
|
|
+ }
|
|
|
|
+ pro = db.Projects.FirstOrDefault(m => m.AppId == AppId && m.AuthCode == AuthCode);
|
|
|
|
+ if(pro == null)
|
|
|
|
+ {
|
|
|
|
+ return Json(new AppResultJson() { Status = "-1", Info = "授权码不正确" });
|
|
|
|
+ }
|
|
Dictionary<string, object> Obj = new Dictionary<string, object>();
|
|
Dictionary<string, object> Obj = new Dictionary<string, object>();
|
|
- Obj.Add("appSecret", "QJHQJ45G6FPFDAG66JBA5XXX2VTT9APT"); //小程序密钥
|
|
|
|
- Obj.Add("appSalt", "12345678"); //小程序IV
|
|
|
|
|
|
+ Obj.Add("appSecret", pro.AppSecret); //小程序密钥
|
|
|
|
+ Obj.Add("appSalt", pro.AppIv); //小程序IV
|
|
return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
|
|
return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
|
|
}
|
|
}
|
|
|
|
|
|
@@ -46,10 +57,48 @@ namespace MySystem.Areas.Api.Controllers
|
|
JsonData data = JsonMapper.ToObject(value);
|
|
JsonData data = JsonMapper.ToObject(value);
|
|
string AppId = data["appId"].ToString(); //小程序AppId
|
|
string AppId = data["appId"].ToString(); //小程序AppId
|
|
string Code = data["code"].ToString(); //加密Code
|
|
string Code = data["code"].ToString(); //加密Code
|
|
- // string Data = AppDesDecrypt(Code, "fghfghghjghjghfghjfgfgh", "12345678");
|
|
|
|
|
|
+ Projects pro = db.Projects.FirstOrDefault(m => m.AppId == AppId);
|
|
|
|
+ if(pro == null)
|
|
|
|
+ {
|
|
|
|
+ return Json(new AppResultJson() { Status = "-1", Info = "appid不存在" });
|
|
|
|
+ }
|
|
|
|
+ string Data = AppDesDecrypt(Code, pro.AppSecret, pro.AppIv);
|
|
|
|
+ if(string.IsNullOrEmpty(Data))
|
|
|
|
+ {
|
|
|
|
+ return Json(new AppResultJson() { Status = "-1", Info = "授权失败" });
|
|
|
|
+ }
|
|
|
|
+ string CheckAppId = Data.Substring(0, 16);
|
|
|
|
+ if(CheckAppId != AppId)
|
|
|
|
+ {
|
|
|
|
+ return Json(new AppResultJson() { Status = "-1", Info = "授权失败" });
|
|
|
|
+ }
|
|
|
|
+ string UserId = Data.Substring(16);
|
|
|
|
+ int PlateformUserId = int.Parse(UserId);
|
|
|
|
+ string OpenId = "kxsmp_" + function.MD5_16(UserId).GetHashCode().ToString().Replace("-", "");
|
|
|
|
+ string Token = function.MD532(Guid.NewGuid().ToString() + "948576");
|
|
|
|
+ UserForProject userFor = db.UserForProject.FirstOrDefault(m => m.PlateformUserId == PlateformUserId && m.AppId == AppId);
|
|
|
|
+ if(userFor == null)
|
|
|
|
+ {
|
|
|
|
+ userFor = db.UserForProject.Add(new UserForProject()
|
|
|
|
+ {
|
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
|
+ UpdateDate = DateTime.Now.AddHours(1),
|
|
|
|
+ PlateformUserId = PlateformUserId,
|
|
|
|
+ AppId = AppId,
|
|
|
|
+ OpenId = OpenId,
|
|
|
|
+ Token = Token,
|
|
|
|
+ }).Entity;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ userFor.UpdateDate = DateTime.Now.AddHours(1);
|
|
|
|
+ userFor.OpenId = OpenId;
|
|
|
|
+ userFor.Token = Token;
|
|
|
|
+ }
|
|
|
|
+ db.SaveChanges();
|
|
Dictionary<string, object> Obj = new Dictionary<string, object>();
|
|
Dictionary<string, object> Obj = new Dictionary<string, object>();
|
|
- Obj.Add("appToken", "77V3ULHBCE5PV9KXPWL5P7346HJPHUR3"); //小程序获取用户信息的Token
|
|
|
|
- Obj.Add("openId", "wnjasnjdjjghjhjn"); //小程序openId
|
|
|
|
|
|
+ Obj.Add("appToken", Token); //小程序获取用户信息的Token
|
|
|
|
+ Obj.Add("openId", OpenId); //小程序openId
|
|
return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
|
|
return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
|
|
}
|
|
}
|
|
|
|
|
|
@@ -63,13 +112,30 @@ namespace MySystem.Areas.Api.Controllers
|
|
JsonData data = JsonMapper.ToObject(value);
|
|
JsonData data = JsonMapper.ToObject(value);
|
|
string AppToken = data["appToken"].ToString(); //小程序获取用户信息的Token
|
|
string AppToken = data["appToken"].ToString(); //小程序获取用户信息的Token
|
|
string OpenId = data["openId"].ToString(); //小程序openId
|
|
string OpenId = data["openId"].ToString(); //小程序openId
|
|
|
|
+ DateTime now = DateTime.Now;
|
|
Dictionary<string, object> Obj = new Dictionary<string, object>();
|
|
Dictionary<string, object> Obj = new Dictionary<string, object>();
|
|
- // Models.Users user = db.Users.FirstOrDefault(m => m.Id == 1) ?? new Models.Users();
|
|
|
|
- Obj.Add("mobile", "138xxxxxxxx");
|
|
|
|
- Obj.Add("nickName", "测试昵称"); //昵称
|
|
|
|
- Obj.Add("headPhoto", SourceHost + "/xxx/xxx.jpg"); //头像
|
|
|
|
- Obj.Add("province", "四川省"); //省
|
|
|
|
- Obj.Add("city", "成都市"); //市
|
|
|
|
|
|
+ UserForProject userFor = db.UserForProject.FirstOrDefault(m => m.Token == AppToken && m.OpenId == OpenId && m.UpdateDate > now);
|
|
|
|
+ if(userFor == null)
|
|
|
|
+ {
|
|
|
|
+ return Json(new AppResultJson() { Status = "-1", Info = "获取用户信息失败" });
|
|
|
|
+ }
|
|
|
|
+ PlateformModels.Users user = pdb.Users.FirstOrDefault(m => m.Id == userFor.PlateformUserId) ?? new PlateformModels.Users();
|
|
|
|
+ Obj.Add("mobile", user.Mobile);
|
|
|
|
+ Obj.Add("nickName", user.RealName); //昵称
|
|
|
|
+ Obj.Add("headPhoto", SourceHost + user.HeadPhoto); //头像
|
|
|
|
+ string province = "";
|
|
|
|
+ string city = "";
|
|
|
|
+ string district = "";
|
|
|
|
+ if(!string.IsNullOrEmpty(user.Areas))
|
|
|
|
+ {
|
|
|
|
+ string[] AreaList = user.Areas.Split(',');
|
|
|
|
+ if(AreaList.Length > 0) province = AreaList[0];
|
|
|
|
+ if(AreaList.Length > 1) province = AreaList[1];
|
|
|
|
+ if(AreaList.Length > 2) province = AreaList[2];
|
|
|
|
+ }
|
|
|
|
+ Obj.Add("province", province); //省
|
|
|
|
+ Obj.Add("city", city); //市
|
|
|
|
+ Obj.Add("district", district); //区
|
|
return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
|
|
return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
|
|
}
|
|
}
|
|
|
|
|
|
@@ -82,33 +148,40 @@ namespace MySystem.Areas.Api.Controllers
|
|
|
|
|
|
private string AppDesDecrypt(string encryptedText, string key, string iv)
|
|
private string AppDesDecrypt(string encryptedText, string key, string iv)
|
|
{
|
|
{
|
|
- byte[] keyArray;
|
|
|
|
- byte[] ivArray;
|
|
|
|
- byte[] encryptedTextArray;
|
|
|
|
- byte[] decryptedTextArray;
|
|
|
|
- TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
|
|
|
|
|
|
+ string decryptedText = "";
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ byte[] keyArray;
|
|
|
|
+ byte[] ivArray;
|
|
|
|
+ byte[] encryptedTextArray;
|
|
|
|
+ byte[] decryptedTextArray;
|
|
|
|
+ TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
|
|
|
|
|
|
- keyArray = UTF8Encoding.UTF8.GetBytes(key.Substring(0, 24));
|
|
|
|
- ivArray = UTF8Encoding.UTF8.GetBytes(iv);
|
|
|
|
- encryptedTextArray = Convert.FromBase64String(encryptedText);
|
|
|
|
|
|
+ keyArray = UTF8Encoding.UTF8.GetBytes(key.Substring(0, 24));
|
|
|
|
+ ivArray = UTF8Encoding.UTF8.GetBytes(iv);
|
|
|
|
+ encryptedTextArray = Convert.FromBase64String(encryptedText);
|
|
|
|
|
|
- tripleDES.Key = keyArray;
|
|
|
|
- tripleDES.IV = ivArray;
|
|
|
|
|
|
+ tripleDES.Key = keyArray;
|
|
|
|
+ tripleDES.IV = ivArray;
|
|
|
|
|
|
- ICryptoTransform decryptor = tripleDES.CreateDecryptor(tripleDES.Key, tripleDES.IV);
|
|
|
|
|
|
+ ICryptoTransform decryptor = tripleDES.CreateDecryptor(tripleDES.Key, tripleDES.IV);
|
|
|
|
|
|
- using (MemoryStream ms = new MemoryStream(encryptedTextArray))
|
|
|
|
- {
|
|
|
|
- using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
|
|
|
|
|
|
+ using (MemoryStream ms = new MemoryStream(encryptedTextArray))
|
|
{
|
|
{
|
|
- using (StreamReader sr = new StreamReader(cs))
|
|
|
|
|
|
+ using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
|
|
{
|
|
{
|
|
- decryptedTextArray = Encoding.UTF8.GetBytes(sr.ReadToEnd());
|
|
|
|
|
|
+ using (StreamReader sr = new StreamReader(cs))
|
|
|
|
+ {
|
|
|
|
+ decryptedTextArray = Encoding.UTF8.GetBytes(sr.ReadToEnd());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ decryptedText = Encoding.UTF8.GetString(decryptedTextArray);
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex)
|
|
|
|
+ {
|
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "3DES解密异常");
|
|
}
|
|
}
|
|
-
|
|
|
|
- string decryptedText = Encoding.UTF8.GetString(decryptedTextArray);
|
|
|
|
return decryptedText;
|
|
return decryptedText;
|
|
}
|
|
}
|
|
|
|
|