public async Task <IActionResult> OnLogin([FromBody] JObject param) { // 不设置权限访问可以不做以下验证 if (!await _authorizationService.AuthorizeAsync(User, MiniProgramPermission.WeCharMiniProgramAccess)) { return(Unauthorized(new { success = false, msg = "未授权访问" })); } try { var jsonResult = await SnsApi.JsCode2JsonAsync(_miniProgramSetting.WxOpenAppId, _miniProgramSetting.WxOpenAppSecret, param["code"].Value <string>()); if (jsonResult.errcode == ReturnCode.请求成功) { var unionId = ""; // 定义sessionId为openid var sessionBag = await SessionContainer.UpdateSessionAsync(jsonResult.openid, jsonResult.openid, jsonResult.session_key, unionId); // 返回 sessionId return(Json(new { success = true, msg = "OK", sessionId = sessionBag.Key })); } else { return(Json(new { success = false, msg = jsonResult.errmsg })); } } catch (Exception ex) { return(Json(new { success = false, msg = ex.Message })); } }