Commit 8fe5b418 by 1391696987

优化代码

parent 35c049ae
......@@ -107,31 +107,54 @@ public ApiResponse WechatLogin(string code)
InterfaceRequest interfaceRequest = new InterfaceRequest()
{
Url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken",
Url = _wechat.Value.Access_Token,
Function = "GatAccess_token"
};
var getAccess_tokenDic = _userService.AccessInterface(interfaceRequest, out string content);
string access_token = "";
if (getAccess_tokenDic.ContainsKey("access_token"))
access_token = getAccess_tokenDic["access_token"].ToString();
string access_token = getAccess_tokenDic.GetValue("access_token","");
interfaceRequest.Url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo";
interfaceRequest.Url = _wechat.Value.GetUserInfo;
interfaceRequest.Function = "GetUserId";
interfaceRequest.Access_token = access_token;
interfaceRequest.Code = code;
var getUserIdDic = _userService.AccessInterface(interfaceRequest, out string conten);
string userId = "";
if (getUserIdDic.ContainsKey("UserId"))
userId = getUserIdDic["UserId"].ToString();
string userId = getUserIdDic.GetValue("userid","");
var empCode = _userService.GetWxUserEmpCode(userId);
return new ApiResponse(ResponseType.OK, new { userId, empCode });
}
/// <summary>
/// 微信获取Access_token假接口
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("GetAccess_token")]
[AllowAnonymous]
public dynamic GetUserId()
{
string json = "{\"errcode\":0,\"errmsg\":\"ok\",\"access_token\":\"UEmj20gO_efJs-nlQ_fY-iimJ8ZSBI315maQAmtMMGcHb_Fyqci9v1L5bFL14b-GqdnNXUwuOkX_RkrCDcmHl6qyLIkwBOw1_9_A_uXoAg_D1mMB9wbIoavL1zOzCy1CvL6elbf8Gf7CyV2dpykaC7C1Ju07s4jVXJch4GNFeYr6AQMwCg6KmWrJrgKTn6nms2Xc2qPYXWTobyqCImNElg\",\"expires_in\":7200}";
var dic = JsonHelper.Deserialize<Dictionary<string, object>>(json);
return dic;
}
/// <summary>
/// 微信获取UserId假接口
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("GetUserId")]
[AllowAnonymous]
public dynamic GetUserId(string code)
{
string json = "{\"UserId\":\"" + code + "\",\"DeviceId\":\"526fda7a-d269-44df-a7e1-376e8a0efbe3\",\"errcode\":0,\"errmsg\":\"ok\"}";
var dic = JsonHelper.Deserialize<Dictionary<string, object>>(json);
return dic;
}
/// <summary>
/// 梧州Token假接口
/// </summary>
......@@ -141,8 +164,8 @@ public ApiResponse WechatLogin(string code)
[AllowAnonymous]
public dynamic WuzhouToken()
{
string json1 = "{\"success\":true,\"status\":{\"code\":0,\"msg\":\"处理成功。\"},\"extraMsg\":\"\",\"item\":{\"id\":\"9f1e83f1-6a9d-4bc4-8e93-611cb41991ba\",\"timeout\":7200000,\"startTimestamp\":\"2022-06-01 16:47:42.049\"}}";
var dic = JsonHelper.Deserialize<Dictionary<string, object>>(json1);
string json = "{\"success\":true,\"status\":{\"code\":0,\"msg\":\"处理成功。\"},\"extraMsg\":\"\",\"item\":{\"id\":\"9f1e83f1-6a9d-4bc4-8e93-611cb41991ba\",\"timeout\":7200000,\"startTimestamp\":\"2022-06-01 16:47:42.049\"}}";
var dic = JsonHelper.Deserialize<Dictionary<string, object>>(json);
return dic;
}
/// <summary>
......@@ -154,8 +177,8 @@ public dynamic WuzhouToken()
[AllowAnonymous]
public dynamic WuzhouValidPass()
{
string json1 = "{\"success\":true,\"status\":{\"code\":0,\"msg\":\"处理成功。\"},\"extraMsg\":\"\",\"item\":true}";
var dic = JsonHelper.Deserialize<Dictionary<string, object>>(json1);
string json = "{\"success\":true,\"status\":{\"code\":0,\"msg\":\"处理成功。\"},\"extraMsg\":\"\",\"item\":true}";
var dic = JsonHelper.Deserialize<Dictionary<string, object>>(json);
return dic;
}
/// <summary>
......@@ -186,9 +209,9 @@ public dynamic WuzhouLogin([FromBody] WuzhouLoginRequest request)
string token = "";
if (getTokenDic.GetValue("success", false) == true)
{
var item = getTokenDic["item"];
var itemdic = JsonHelper.Deserialize<Dictionary<string, object>>(item.ToString());
token = itemdic["id"].ToString();
var item = getTokenDic.GetValue("item", "");
var itemdic = JsonHelper.Deserialize<Dictionary<string, object>>(item);
interfaceRequest.X_Token = itemdic.GetValue("id", "");
}
else
{
......
......@@ -7,6 +7,10 @@
}
},
"Wechat": {
"Access_token": "https://qyapi.weixin.qq.com/cgi-bin/gettoken",
"GetUserInfo": "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo",
//"Access_token": "http://localhost:5001/api/Account/GetAccess_token",
//"GetUserInfo": "http://localhost:5001/api/Account/GetUserId",
"CorpId": "ww58ec167201a95da7",
"CorpSecret": "1rgWzgJBIZ3r0Q2sW1trVw5QdXOHmgUhepk90ecI2rk"
},
......
......@@ -6,6 +6,10 @@
}
},
"Wechat": {
"Access_token": "https://qyapi.weixin.qq.com/cgi-bin/gettoken",
"GetUserInfo": "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo",
//"Access_token": "http://localhost:5001/api/Account/GetAccess_token",
//"GetUserInfo": "http://localhost:5001/api/Account/GetUserId",
"CorpId": "ww58ec167201a95da7",
"CorpSecret": "1rgWzgJBIZ3r0Q2sW1trVw5QdXOHmgUhepk90ecI2rk"
},
......
......@@ -5,6 +5,10 @@
}
},
"Wechat": {
"Access_token": "https://qyapi.weixin.qq.com/cgi-bin/gettoken",
"GetUserInfo": "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo",
//"Access_token": "http://localhost:5001/api/Account/GetAccess_token",
//"GetUserInfo": "http://localhost:5001/api/Account/GetUserId",
"CorpId": "ww58ec167201a95da7",
"CorpSecret": "1rgWzgJBIZ3r0Q2sW1trVw5QdXOHmgUhepk90ecI2rk"
},
......
......@@ -31,6 +31,18 @@
<param name="code"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.GetUserId">
<summary>
微信获取Access_token假接口
</summary>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.GetUserId(System.String)">
<summary>
微信获取UserId假接口
</summary>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.WuzhouToken">
<summary>
梧州Token假接口
......
......@@ -8,6 +8,8 @@ namespace Performance.DtoModels.AppSettings
{
public class Wechat
{
public string Access_Token { get; set; }
public string GetUserInfo { get; set; }
public string CorpId { get; set; }
public string CorpSecret { get; set; }
......
......@@ -106,8 +106,8 @@ public class UserService : IAutoInjection
request.AddQueryParameter("code", interfaceRequest.Code);
break;
case "GetX_Token":
request.AddQueryParameter("Code", _wzOAuth.Value.Code);
request.AddQueryParameter("Token", _wzOAuth.Value.Token);
request.AddQueryParameter("user", _wzOAuth.Value.Code);
request.AddQueryParameter("pwd", _wzOAuth.Value.Token);
break;
case "ValidPass":
request.AddHeader("x-token", interfaceRequest.X_Token);
......@@ -117,19 +117,24 @@ public class UserService : IAutoInjection
request.AddQueryParameter("mobile", interfaceRequest.wuzhouLoginRequest.Mobile);
break;
}
logger.LogInformation($"开始请求第三方接口:{interfaceRequest.Url}");
IRestResponse response = restClient.Execute(request);
content = response.Content;
if (response.StatusCode == System.Net.HttpStatusCode.OK)
logger.LogInformation($"第三方接口请求结束:{JsonHelper.Serialize(new { interfaceRequest.Url, response.StatusCode, content })}");
try
{
return JsonHelper.Deserialize<Dictionary<string, object>>(response.Content);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
return JsonHelper.Deserialize<Dictionary<string, object>>(response.Content);
}
}
else
catch (Exception ex)
{
logger.LogError($"接口请求错误:{response.StatusCode},{response.Content}");
return null;
logger.LogError($"接口请求错误:{ex}");
}
return null;
}
/// <summary>
/// 获取微信绑定用户的工号
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment