Sign in
Sign up
Explore
Enterprise
Education
Search
Help
Terms of use
About Us
Explore
Enterprise
Education
Gitee Premium
Gitee AI
AI teammates
Sign in
Sign up
Fetch the repository succeeded.
Open Source
>
Wechat Projects
>
Wechat Development Package
&&
Donate
Please sign in before you donate.
Cancel
Sign in
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
Watch
Unwatch
Watching
Releases Only
Ignoring
177
Star
1.5K
Fork
424
RHQYZ
/
DotNetCore.SKIT.FlurlHttpClient.Wechat
Code
Issues
2
Pull Requests
0
Insights
Pipelines
Service
Quality Analysis
Jenkins for Gitee
Tencent CloudBase
Tencent Cloud Serverless
悬镜安全
Aliyun SAE
Codeblitz
SBOM
DevLens
Don’t show this again
Update failed. Please try again later!
Remove this flag
Content Risk Flag
This task is identified by
as the content contains sensitive information such as code security bugs, privacy leaks, etc., so it is only accessible to contributors of this repository.
ReflectionUtility 优化建议
Done
#I4K40Y
刘宏伟
Opened this issue
2021-11-28 01:24
> **⚠⚠ 请注意:不符合格式要求的 Issue 可能会被直接关闭。** --- **问题类型** 请在此选择你的问题类型: - [*] 报告缺陷:发现源代码中的漏洞、运行发生的异常、或文档里的错误。 - [ ] 请求新功能:需要某些新功能,或对现有实现提出更好的建议。 - [ ] 其他类型 Issue:遇到了问题,需要帮助。 --- **关于问题或建议的简单描述** CreateProfitSharingOrderRequest,子类的敏感数据,没能自动加密。 --- **与问题或建议相关的源代码** SKIT.FlurlHttpClient.Wechat.TenpayV3\Utilities\Internal\ReflectionUtility.cs,函数InnerReplacePropertyStringValue 需要优化。 private static void InnerReplacePropertyStringValue<T>(ref T obj, ReplacePropertyStringValueReplacement replacement, PropertyInfo? currentProp) { if (obj == null) throw new ArgumentNullException(nameof(obj)); if (replacement == null) throw new ArgumentNullException(nameof(replacement)); Type objType = obj.GetType(); if (!objType.IsClass) throw new NotSupportedException(); if (objType.IsArray || obj is IList || obj is IDictionary) { InnerReplacePropertyStringValue1(ref obj, objType, replacement, null); } else { foreach (var childProp in objType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (!childProp.CanWrite) continue; Type propType = childProp.PropertyType; if (propType == typeof(string)) { string oldValue = (string)childProp.GetValue(obj, null)!; string newValue = replacement(obj, childProp, oldValue); childProp.SetValue(obj, newValue); } else if (propType.IsClass) { object? value = childProp.GetValue(obj, null); if (value is null) continue; InnerReplacePropertyStringValue(ref value, replacement, childProp); childProp.SetValue(obj, value); } else { object? value = childProp.GetValue(obj, null); if (value is null) continue; InnerReplacePropertyStringValue1(ref value, propType, replacement, childProp); } } } } private static void InnerReplacePropertyStringValue1<T>(ref T obj, Type objType, ReplacePropertyStringValueReplacement replacement, PropertyInfo? currentProp) { if (objType.IsArray) { var array = (obj as Array)!; for (int i = 0, len = array.Length; i < len; i++) { object? element = array.GetValue(i); if (element is null) continue; Type elementType = element.GetType(); if (elementType == typeof(string)) { if (currentProp == null) continue; string oldValue = (string)element!; string newValue = replacement(obj, currentProp, oldValue); array.SetValue(newValue, i); } else if (elementType.IsClass) { InnerReplacePropertyStringValue(ref element, replacement, currentProp); array.SetValue(element, i); } else { continue; } } } else if (obj is IList list) { for (int i = 0, len = list.Count; i < len; i++) { object? element = list[i]; if (element is null) continue; Type elementType = element.GetType(); if (elementType == typeof(string)) { if (currentProp == null) continue; string oldValue = (string)element!; string newValue = replacement(obj, currentProp, oldValue); list[i] = newValue; } else if (elementType.IsClass) { InnerReplacePropertyStringValue(ref element, replacement, currentProp); list[i] = element; } else { continue; } } } else if (obj is IDictionary dict) { foreach (DictionaryEntry entry in dict) { object? entryValue = entry.Value; if (entryValue is null) continue; Type entryValueType = entryValue.GetType(); if (entryValueType == typeof(string)) { if (currentProp == null) continue; string oldValue = (string)entryValue!; string newValue = replacement(obj, currentProp, oldValue); dict[entry.Key] = newValue; } else if (entryValueType.IsClass) { InnerReplacePropertyStringValue(ref entryValue, replacement, currentProp); dict[entry.Key] = entryValue; } else { continue; } } } } **补充说明** 随意完善了一下,目前ExecuteCreateProfitSharingOrderAsync发起请求前调用EncryptRequestSensitiveProperty,能完成属性的自动加密
> **⚠⚠ 请注意:不符合格式要求的 Issue 可能会被直接关闭。** --- **问题类型** 请在此选择你的问题类型: - [*] 报告缺陷:发现源代码中的漏洞、运行发生的异常、或文档里的错误。 - [ ] 请求新功能:需要某些新功能,或对现有实现提出更好的建议。 - [ ] 其他类型 Issue:遇到了问题,需要帮助。 --- **关于问题或建议的简单描述** CreateProfitSharingOrderRequest,子类的敏感数据,没能自动加密。 --- **与问题或建议相关的源代码** SKIT.FlurlHttpClient.Wechat.TenpayV3\Utilities\Internal\ReflectionUtility.cs,函数InnerReplacePropertyStringValue 需要优化。 private static void InnerReplacePropertyStringValue<T>(ref T obj, ReplacePropertyStringValueReplacement replacement, PropertyInfo? currentProp) { if (obj == null) throw new ArgumentNullException(nameof(obj)); if (replacement == null) throw new ArgumentNullException(nameof(replacement)); Type objType = obj.GetType(); if (!objType.IsClass) throw new NotSupportedException(); if (objType.IsArray || obj is IList || obj is IDictionary) { InnerReplacePropertyStringValue1(ref obj, objType, replacement, null); } else { foreach (var childProp in objType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (!childProp.CanWrite) continue; Type propType = childProp.PropertyType; if (propType == typeof(string)) { string oldValue = (string)childProp.GetValue(obj, null)!; string newValue = replacement(obj, childProp, oldValue); childProp.SetValue(obj, newValue); } else if (propType.IsClass) { object? value = childProp.GetValue(obj, null); if (value is null) continue; InnerReplacePropertyStringValue(ref value, replacement, childProp); childProp.SetValue(obj, value); } else { object? value = childProp.GetValue(obj, null); if (value is null) continue; InnerReplacePropertyStringValue1(ref value, propType, replacement, childProp); } } } } private static void InnerReplacePropertyStringValue1<T>(ref T obj, Type objType, ReplacePropertyStringValueReplacement replacement, PropertyInfo? currentProp) { if (objType.IsArray) { var array = (obj as Array)!; for (int i = 0, len = array.Length; i < len; i++) { object? element = array.GetValue(i); if (element is null) continue; Type elementType = element.GetType(); if (elementType == typeof(string)) { if (currentProp == null) continue; string oldValue = (string)element!; string newValue = replacement(obj, currentProp, oldValue); array.SetValue(newValue, i); } else if (elementType.IsClass) { InnerReplacePropertyStringValue(ref element, replacement, currentProp); array.SetValue(element, i); } else { continue; } } } else if (obj is IList list) { for (int i = 0, len = list.Count; i < len; i++) { object? element = list[i]; if (element is null) continue; Type elementType = element.GetType(); if (elementType == typeof(string)) { if (currentProp == null) continue; string oldValue = (string)element!; string newValue = replacement(obj, currentProp, oldValue); list[i] = newValue; } else if (elementType.IsClass) { InnerReplacePropertyStringValue(ref element, replacement, currentProp); list[i] = element; } else { continue; } } } else if (obj is IDictionary dict) { foreach (DictionaryEntry entry in dict) { object? entryValue = entry.Value; if (entryValue is null) continue; Type entryValueType = entryValue.GetType(); if (entryValueType == typeof(string)) { if (currentProp == null) continue; string oldValue = (string)entryValue!; string newValue = replacement(obj, currentProp, oldValue); dict[entry.Key] = newValue; } else if (entryValueType.IsClass) { InnerReplacePropertyStringValue(ref entryValue, replacement, currentProp); dict[entry.Key] = entryValue; } else { continue; } } } } **补充说明** 随意完善了一下,目前ExecuteCreateProfitSharingOrderAsync发起请求前调用EncryptRequestSensitiveProperty,能完成属性的自动加密
Comments (
2
)
Sign in
to comment
Status
Done
Backlog
Doing
Done
Closed
Assignees
Not set
Labels
enhancement
Not set
Label settings
Milestones
No related milestones
No related milestones
Pull Requests
None yet
None yet
Successfully merging a pull request will close this issue.
Branches
No related branch
Branches (
-
)
Tags (
-
)
Planed to start   -   Planed to end
-
Top level
Not Top
Top Level: High
Top Level: Medium
Top Level: Low
Priority
Not specified
Serious
Main
Secondary
Unimportant
参与者(2)
C#
1
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
git@gitee.com:fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
fudiwei
DotNetCore.SKIT.FlurlHttpClient.Wechat
DotNetCore.SKIT.FlurlHttpClient.Wechat
Going to Help Center
Search
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register