qingqiu chegngong
This commit is contained in:
145
yinmeng-ios/Base/Hud/HUDTool.swift
Normal file
145
yinmeng-ios/Base/Hud/HUDTool.swift
Normal file
@@ -0,0 +1,145 @@
|
||||
//
|
||||
// HUDTool.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by MaiMang on 2024/2/23.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import MBProgressHUD
|
||||
|
||||
class HUDTool: NSObject {
|
||||
|
||||
static var currentHud : MBProgressHUD?
|
||||
|
||||
private static let kDelayTime: TimeInterval = 2
|
||||
|
||||
/** 隐藏HUD*/
|
||||
class func hidden(_ time:TimeInterval = 0){
|
||||
guard let HUD = currentHud else {
|
||||
return
|
||||
}
|
||||
HUD.hide(animated: false)
|
||||
currentHud = nil
|
||||
}
|
||||
|
||||
/**
|
||||
显示成功message
|
||||
|
||||
- Parameter message: 文字
|
||||
- Parameter view: 显示在哪个view上
|
||||
- Parameter afterDelay: 延迟消失时间
|
||||
- Parameter enabled: 是否可以拦截事件 no:不拦截 yes:拦截
|
||||
*/
|
||||
class func showSuccess(with message: String, in view: UIView? = YMRequestX.topViewController()?.view, delay afterDelay: TimeInterval = kDelayTime, enabled: Bool = true, icon:String = "") {
|
||||
if message.isEmpty { return }
|
||||
|
||||
DispatchQueue.main.async {
|
||||
hidden(0)
|
||||
var view = view
|
||||
if view == nil {
|
||||
view = YMRequestX.topViewController()?.view ?? YMRequestX.keyWindow()
|
||||
}
|
||||
if let view = view {
|
||||
let hud = normalProgressHUD(in: view)
|
||||
currentHud = hud
|
||||
hud.isUserInteractionEnabled = enabled
|
||||
hud.mode = .customView
|
||||
hud.bezelView.style = .solidColor
|
||||
hud.margin = 8
|
||||
hud.backgroundColor = .clear
|
||||
hud.removeFromSuperViewOnHide = true
|
||||
|
||||
let messageView = HudMessageView()
|
||||
messageView.titleLb.text = message
|
||||
|
||||
let maxWidth = 242.0
|
||||
let size = message.boundingRect(with: CGSize(width: maxWidth, height: CGFLOAT_MAX), font: UIFont.systemFont(ofSize: 14, weight: .medium), lineSpacing: 6)
|
||||
var width = size.width + 5
|
||||
var height = size.height
|
||||
if icon.count > 0 {
|
||||
messageView.logoImgView.image = UIImage(named: icon)
|
||||
messageView.logoImgView.isHidden = false
|
||||
width += 22.0
|
||||
} else {
|
||||
messageView.logoImgView.isHidden = true
|
||||
}
|
||||
|
||||
hud.bezelView.backgroundColor = ThemeColor(hexStr: "#000000", alpha: 0.7)
|
||||
hud.bezelView.layer.cornerRadius = 8
|
||||
hud.bezelView.layer.masksToBounds = true
|
||||
hud.bezelView.addSubview(messageView)
|
||||
|
||||
messageView.snp.makeConstraints { make in
|
||||
make.height.equalTo(height)
|
||||
make.width.equalTo(width)
|
||||
make.center.equalTo(hud.bezelView)
|
||||
}
|
||||
hud.minSize = CGSize(width: width + 40, height: height + 24)
|
||||
hud.show(animated: true)
|
||||
hud.hide(animated: false, afterDelay: kDelayTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class func normalProgressHUD(in view: UIView) -> MBProgressHUD {
|
||||
let hud = MBProgressHUD.showAdded(to: view, animated: true)
|
||||
hud.mode = .indeterminate
|
||||
hud.bezelView.style = .solidColor
|
||||
hud.margin = 8
|
||||
// 方框背景颜色
|
||||
hud.bezelView.color = UIColor.black.withAlphaComponent(0.8)
|
||||
return hud
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class HudMessageView: UIView {
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
self.addSubview(stackView)
|
||||
stackView.addArrangedSubview(logoImgView)
|
||||
stackView.addArrangedSubview(titleLb)
|
||||
|
||||
stackView.snp.makeConstraints { make in
|
||||
make.edges.equalTo(self)
|
||||
}
|
||||
|
||||
logoImgView.snp.makeConstraints { make in
|
||||
make.size.equalTo(CGSize(width: 20, height: 20))
|
||||
}
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
private lazy var stackView: UIStackView = {
|
||||
let stackView = UIStackView()
|
||||
stackView.distribution = .fill
|
||||
stackView.axis = .horizontal
|
||||
stackView.alignment = .top
|
||||
stackView.spacing = 2
|
||||
return stackView
|
||||
}()
|
||||
|
||||
lazy var logoImgView: UIImageView = {
|
||||
let imageView = UIImageView()
|
||||
imageView.isUserInteractionEnabled = true
|
||||
imageView.layer.masksToBounds = true
|
||||
imageView.contentMode = .scaleAspectFill
|
||||
return imageView
|
||||
}()
|
||||
|
||||
lazy var titleLb: UILabel = {
|
||||
let label = UILabel()
|
||||
label.textColor = UIColor.white
|
||||
label.font = UIFont.systemFont(ofSize: 14, weight: .medium)
|
||||
label.textAlignment = .center
|
||||
label.numberOfLines = 0
|
||||
return label
|
||||
}()
|
||||
|
||||
|
||||
}
|
37
yinmeng-ios/Base/Request/Deserialized.swift
Normal file
37
yinmeng-ios/Base/Request/Deserialized.swift
Normal file
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// Deserialized.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by MaiMang on 2024/2/22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@_exported import HandyJSON
|
||||
|
||||
/// Deserialized json converts to Model or Array.
|
||||
public struct Deserialized<H> where H: HandyJSON {
|
||||
|
||||
public static func toModel(with element: Any?) -> H? {
|
||||
if let string = element as? String, let model = H.deserialize(from: string) {
|
||||
return model
|
||||
}
|
||||
if let dictionary = element as? Dictionary<String, Any>, let model = H.deserialize(from: dictionary) {
|
||||
return model
|
||||
}
|
||||
if let dictionary = element as? [String : Any], let model = H.deserialize(from: dictionary) {
|
||||
return model
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
public static func toArray(with element: Any?) -> [H]? {
|
||||
if let string = element as? String, let array = [H].deserialize(from: string) as? [H] {
|
||||
return array
|
||||
}
|
||||
if let array = [H].deserialize(from: element as? [Any]) as? [H] {
|
||||
return array
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
134
yinmeng-ios/Base/Request/YMNetworkHelper.swift
Normal file
134
yinmeng-ios/Base/Request/YMNetworkHelper.swift
Normal file
@@ -0,0 +1,134 @@
|
||||
//
|
||||
// YMNetworkAPI.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by MaiMang on 2024/2/24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
import HandyJSON
|
||||
import DeviceKit
|
||||
typealias SessionCallSucceed = (Any) -> Void
|
||||
typealias SessionCallFail = (Int,String) -> Void
|
||||
|
||||
class YMNetworkHelper: NSObject {
|
||||
|
||||
var baseParameters: [String: Any] {
|
||||
var parameters: [String: Any] = Dictionary()
|
||||
parameters["os"] = "iOS"
|
||||
parameters["osVersion"] = Device.current.systemVersion
|
||||
parameters["model"] = "iPhone14,7"
|
||||
parameters["ispType"] = "1"
|
||||
parameters["channel"] = APPUtils.currentChannle
|
||||
parameters["netType"] = "2"
|
||||
parameters["app"] = "yinmeng"
|
||||
parameters["appVersion"] = APPUtils.appVersion
|
||||
parameters["deviceId"] = APPUtils.currentDeveiceId
|
||||
return parameters
|
||||
}
|
||||
|
||||
var sessionNetMana :Session!
|
||||
public static let share = YMNetworkHelper.init()
|
||||
var headersSet: HTTPHeaders = [
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": ""
|
||||
]
|
||||
|
||||
func requestSend(type:HTTPMethod,path:String,params:Dictionary<String, Any>, succeed:SessionCallSucceed?,fail:SessionCallFail?) -> Void {
|
||||
getHttpRequestHeaders()
|
||||
requestSend(type: type,host: "http://beta.api.ymlive.fun/", path: path, params: params, encoding: URLEncoding.queryString, header: headersSet, succeed: succeed, fail: fail)
|
||||
}
|
||||
|
||||
func requestSend(type:HTTPMethod,
|
||||
host:String,
|
||||
path:String,
|
||||
params:[String: Any],
|
||||
encoding:ParameterEncoding,
|
||||
header:HTTPHeaders,
|
||||
succeed:SessionCallSucceed?,
|
||||
fail:SessionCallFail?) -> Void {
|
||||
let encrypteChonParma = baseParameters.merging(params) {$1}
|
||||
sessionNetMana.request(host+path, method: type, parameters: encrypteChonParma,encoding: encoding,headers: header)
|
||||
.validate(contentType: ["application/json"])
|
||||
.responseJSON { [weak self] (response) in
|
||||
self?.analyzeThe(response1: response, succeed2: succeed, fail3: fail,uuid4:"")
|
||||
}
|
||||
}
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
let configCo = AF.sessionConfiguration
|
||||
configCo.httpShouldSetCookies = false
|
||||
configCo.timeoutIntervalForRequest = 30
|
||||
sessionNetMana = Session(configuration: configCo)
|
||||
}
|
||||
|
||||
private func getHttpRequestHeaders() {
|
||||
headersSet["pub_uid"] = "\(AuthManager.userUid)"
|
||||
headersSet["pub_ticket"] = AuthManager.ticket
|
||||
|
||||
}
|
||||
|
||||
|
||||
func analyzeThe(response1:AFDataResponse<Any>,
|
||||
succeed2:SessionCallSucceed?,
|
||||
fail3: SessionCallFail?,uuid4:String) -> Void {
|
||||
let maiUrlSss = response1.request?.url?.absoluteString ?? "unkown"
|
||||
switch response1.result {
|
||||
case .success:
|
||||
let maiResponNk :Dictionary = response1.value as? Dictionary<String, Any> ?? Dictionary.init()
|
||||
let maiResultMo = maiResponNk
|
||||
if maiResultMo.keys.contains("code") {
|
||||
let maicodeNum :Int = maiResultMo["code"] as? Int ?? 0
|
||||
if maicodeNum == 200 {
|
||||
if maiResultMo.keys.contains("data") {
|
||||
let maiDDD = maiResultMo["data"] as Any
|
||||
succeed2?(maiDDD)
|
||||
}else{
|
||||
succeed2?(Dictionary<String, Any>.init())
|
||||
}
|
||||
}else{
|
||||
if maicodeNum == 401 && maiUrlSss.contains("auth-center/sso/logout") == false {
|
||||
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "MAISessionTickValid"), object: nil)
|
||||
sessionNetMana.cancelAllRequests()
|
||||
}
|
||||
var messageIn = response1.error.debugDescription
|
||||
if maiResultMo.keys.contains("message") { messageIn = maiResultMo["message"] as? String ?? "" }
|
||||
fail3?(maicodeNum,messageIn)
|
||||
}
|
||||
} else if maiResultMo.keys.contains("errno") {
|
||||
let maiCodeNum :Int = maiResultMo["errno"] as? Int ?? 0
|
||||
if maiCodeNum == 0 {
|
||||
if maiResultMo.keys.contains("data") {
|
||||
let dataSc = maiResultMo["data"] as Any
|
||||
succeed2?(dataSc)
|
||||
}else{
|
||||
succeed2?(Dictionary<String, Any>.init())
|
||||
}
|
||||
}else{
|
||||
var majmessageStr = response1.error.debugDescription
|
||||
if maiResultMo.keys.contains("errmsg") { majmessageStr = maiResultMo["errmsg"] as? String ?? ""}
|
||||
fail3?(maiCodeNum,majmessageStr)
|
||||
}
|
||||
} else {
|
||||
fail3?(10000,"请求失败")
|
||||
}
|
||||
case let .failure(error):
|
||||
var maiErrorMssg = response1.error?.errorDescription ?? ""
|
||||
var maicodeNum = response1.error?.responseCode ?? 0
|
||||
fail3?(maicodeNum,maiErrorMssg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
struct ResponseModel: HandyJSON {
|
||||
var code:Int? = 0
|
||||
var message:String? = ""
|
||||
var data:Any?
|
||||
}
|
||||
|
||||
|
99
yinmeng-ios/Base/Request/YMRequestX.swift
Normal file
99
yinmeng-ios/Base/Request/YMRequestX.swift
Normal file
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// YMRequestX.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by MaiMang on 2024/2/2.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct YMRequestX {
|
||||
/// Maps data received from the signal into a JSON object.
|
||||
public static func mapJSON<T>(_ type: T.Type, named: String, forResource: String = "RxNetworks") -> T? {
|
||||
guard let data = jsonData(named, forResource: forResource) else {
|
||||
return nil
|
||||
}
|
||||
let json = try? JSONSerialization.jsonObject(with: data, options: .allowFragments)
|
||||
return json as? T
|
||||
}
|
||||
|
||||
/// Read json data
|
||||
public static func jsonData(_ named: String, forResource: String = "RxNetworks") -> Data? {
|
||||
let bundle: Bundle?
|
||||
if let bundlePath = Bundle.main.path(forResource: forResource, ofType: "bundle") {
|
||||
bundle = Bundle.init(path: bundlePath)
|
||||
} else {
|
||||
bundle = Bundle.main
|
||||
}
|
||||
guard let path = ["json", "JSON", "Json"].compactMap({
|
||||
bundle?.path(forResource: named, ofType: $0)
|
||||
}).first else {
|
||||
return nil
|
||||
}
|
||||
let contentURL = URL(fileURLWithPath: path)
|
||||
return try? Data(contentsOf: contentURL)
|
||||
}
|
||||
|
||||
public static func toJSON(form value: Any, prettyPrint: Bool = false) -> String? {
|
||||
guard JSONSerialization.isValidJSONObject(value) else {
|
||||
return nil
|
||||
}
|
||||
var jsonData: Data? = nil
|
||||
if prettyPrint {
|
||||
jsonData = try? JSONSerialization.data(withJSONObject: value, options: [.prettyPrinted])
|
||||
} else {
|
||||
jsonData = try? JSONSerialization.data(withJSONObject: value, options: [])
|
||||
}
|
||||
guard let data = jsonData else { return nil }
|
||||
return String(data: data ,encoding: .utf8)
|
||||
}
|
||||
|
||||
public static func toDictionary(form json: String) -> [String : Any]? {
|
||||
guard let jsonData = json.data(using: .utf8),
|
||||
let object = try? JSONSerialization.jsonObject(with: jsonData, options: []),
|
||||
let result = object as? [String : Any] else {
|
||||
return nil
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public static func keyWindow() -> UIWindow? {
|
||||
if #available(iOS 13.0, *) {
|
||||
return UIApplication.shared.connectedScenes
|
||||
.filter { $0.activationState == .foregroundActive }
|
||||
.first(where: { $0 is UIWindowScene })
|
||||
.flatMap({ $0 as? UIWindowScene })?.windows
|
||||
.first(where: \.isKeyWindow)
|
||||
} else {
|
||||
return UIApplication.shared.keyWindow
|
||||
}
|
||||
}
|
||||
|
||||
public static func topViewController() -> UIViewController? {
|
||||
let window = UIApplication.shared.delegate?.window
|
||||
guard window != nil, let rootViewController = window?!.rootViewController else {
|
||||
return nil
|
||||
}
|
||||
return self.getTopViewController(controller: rootViewController)
|
||||
}
|
||||
|
||||
public static func getTopViewController(controller: UIViewController) -> UIViewController {
|
||||
if let presentedViewController = controller.presentedViewController {
|
||||
return self.getTopViewController(controller: presentedViewController)
|
||||
} else if let navigationController = controller as? UINavigationController {
|
||||
if let topViewController = navigationController.topViewController {
|
||||
return self.getTopViewController(controller: topViewController)
|
||||
}
|
||||
return navigationController
|
||||
} else if let tabbarController = controller as? UITabBarController {
|
||||
if let selectedViewController = tabbarController.selectedViewController {
|
||||
return self.getTopViewController(controller: selectedViewController)
|
||||
}
|
||||
return tabbarController
|
||||
} else {
|
||||
return controller
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
16
yinmeng-ios/Base/Security/Base64.h
Executable file
16
yinmeng-ios/Base/Security/Base64.h
Executable file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Base64.h
|
||||
// BellFramework
|
||||
//
|
||||
// Created by 罗兴志 on 2017/5/4.
|
||||
// Copyright © 2017年 罗兴志. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface Base64 : NSObject
|
||||
|
||||
+(NSString *)encode:(NSData *)data;
|
||||
+(NSData *)decode:(NSString *)dataString;
|
||||
|
||||
@end
|
133
yinmeng-ios/Base/Security/Base64.m
Executable file
133
yinmeng-ios/Base/Security/Base64.m
Executable file
@@ -0,0 +1,133 @@
|
||||
//
|
||||
// Base64.m
|
||||
// BellFramework
|
||||
//
|
||||
// Created by 罗兴志 on 2017/5/4.
|
||||
// Copyright © 2017年 罗兴志. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Base64.h"
|
||||
|
||||
@interface Base64()
|
||||
+(int)char2Int:(char)c;
|
||||
@end
|
||||
|
||||
@implementation Base64
|
||||
|
||||
static const char encodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
+(NSString *)encode:(NSData *)data
|
||||
{
|
||||
if (data.length == 0)
|
||||
return nil;
|
||||
|
||||
char *characters = malloc(data.length * 3 / 2);
|
||||
|
||||
if (characters == NULL)
|
||||
return nil;
|
||||
|
||||
int end = data.length - 3;
|
||||
int index = 0;
|
||||
int charCount = 0;
|
||||
int n = 0;
|
||||
|
||||
while (index <= end) {
|
||||
int d = (((int)(((char *)[data bytes])[index]) & 0x0ff) << 16)
|
||||
| (((int)(((char *)[data bytes])[index + 1]) & 0x0ff) << 8)
|
||||
| ((int)(((char *)[data bytes])[index + 2]) & 0x0ff);
|
||||
|
||||
characters[charCount++] = encodingTable[(d >> 18) & 63];
|
||||
characters[charCount++] = encodingTable[(d >> 12) & 63];
|
||||
characters[charCount++] = encodingTable[(d >> 6) & 63];
|
||||
characters[charCount++] = encodingTable[d & 63];
|
||||
|
||||
index += 3;
|
||||
|
||||
if(n++ >= 14)
|
||||
{
|
||||
n = 0;
|
||||
characters[charCount++] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
if(index == data.length - 2)
|
||||
{
|
||||
int d = (((int)(((char *)[data bytes])[index]) & 0x0ff) << 16)
|
||||
| (((int)(((char *)[data bytes])[index + 1]) & 255) << 8);
|
||||
characters[charCount++] = encodingTable[(d >> 18) & 63];
|
||||
characters[charCount++] = encodingTable[(d >> 12) & 63];
|
||||
characters[charCount++] = encodingTable[(d >> 6) & 63];
|
||||
characters[charCount++] = '=';
|
||||
}
|
||||
else if(index == data.length - 1)
|
||||
{
|
||||
int d = ((int)(((char *)[data bytes])[index]) & 0x0ff) << 16;
|
||||
characters[charCount++] = encodingTable[(d >> 18) & 63];
|
||||
characters[charCount++] = encodingTable[(d >> 12) & 63];
|
||||
characters[charCount++] = '=';
|
||||
characters[charCount++] = '=';
|
||||
}
|
||||
NSString * rtnStr = [[NSString alloc] initWithBytesNoCopy:characters length:charCount encoding:NSUTF8StringEncoding freeWhenDone:YES];
|
||||
return rtnStr;
|
||||
|
||||
}
|
||||
|
||||
+(NSData *)decode:(NSString *)data
|
||||
{
|
||||
if(data == nil || data.length <= 0) {
|
||||
return nil;
|
||||
}
|
||||
NSMutableData *rtnData = [[NSMutableData alloc]init];
|
||||
int slen = data.length;
|
||||
int index = 0;
|
||||
while (true) {
|
||||
while (index < slen && [data characterAtIndex:index] <= ' ') {
|
||||
index++;
|
||||
}
|
||||
if (index >= slen || index + 3 >= slen) {
|
||||
break;
|
||||
}
|
||||
|
||||
int byte = ([self char2Int:[data characterAtIndex:index]] << 18) + ([self char2Int:[data characterAtIndex:index + 1]] << 12) + ([self char2Int:[data characterAtIndex:index + 2]] << 6) + [self char2Int:[data characterAtIndex:index + 3]];
|
||||
Byte temp1 = (byte >> 16) & 255;
|
||||
[rtnData appendBytes:&temp1 length:1];
|
||||
if([data characterAtIndex:index + 2] == '=') {
|
||||
break;
|
||||
}
|
||||
Byte temp2 = (byte >> 8) & 255;
|
||||
[rtnData appendBytes:&temp2 length:1];
|
||||
if([data characterAtIndex:index + 3] == '=') {
|
||||
break;
|
||||
}
|
||||
Byte temp3 = byte & 255;
|
||||
[rtnData appendBytes:&temp3 length:1];
|
||||
index += 4;
|
||||
|
||||
}
|
||||
return rtnData;
|
||||
}
|
||||
|
||||
+(int)char2Int:(char)c
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z') {
|
||||
return c - 65;
|
||||
} else if (c >= 'a' && c <= 'z') {
|
||||
return c - 97 + 26;
|
||||
} else if (c >= '0' && c <= '9') {
|
||||
return c - 48 + 26 + 26;
|
||||
} else {
|
||||
switch(c) {
|
||||
case '+':
|
||||
return 62;
|
||||
case '/':
|
||||
return 63;
|
||||
case '=':
|
||||
return 0;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
16
yinmeng-ios/Base/Security/MAIDESEncryptTool.h
Executable file
16
yinmeng-ios/Base/Security/MAIDESEncryptTool.h
Executable file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// MAIDESEncryptTool.h
|
||||
// BellFramework
|
||||
//
|
||||
// Created by 罗兴志 on 2017/5/4.
|
||||
// Copyright © 2017年 罗兴志. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface MAIDESEncryptTool : NSObject
|
||||
//加密方法
|
||||
+(NSString *)encryptUseDES:(NSString *)plainText key:(NSString *)key;
|
||||
//解密方法
|
||||
+(NSString *)decryptUseDES:(NSString *)cipherText key:(NSString *)key;
|
||||
@end
|
63
yinmeng-ios/Base/Security/MAIDESEncryptTool.m
Executable file
63
yinmeng-ios/Base/Security/MAIDESEncryptTool.m
Executable file
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// MAIDESEncryptTool.m
|
||||
// BellFramework
|
||||
//
|
||||
// Created by 罗兴志 on 2017/5/4.
|
||||
// Copyright © 2017年 罗兴志. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MAIDESEncryptTool.h"
|
||||
#import <CommonCrypto/CommonCrypto.h>
|
||||
#import "Base64.h"
|
||||
|
||||
@implementation MAIDESEncryptTool : NSObject
|
||||
|
||||
const Byte iv[] = {1,2,3,4,5,6,7,8};
|
||||
|
||||
#pragma mark- 加密算法
|
||||
+(NSString *) encryptUseDES:(NSString *)plainText key:(NSString *)key
|
||||
{
|
||||
NSString *ciphertext = nil;
|
||||
NSData *textData = [plainText dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSUInteger dataLength = [textData length];
|
||||
unsigned char buffer[20000];
|
||||
memset(buffer, 0, sizeof(char));
|
||||
size_t numBytesEncrypted = 0;
|
||||
CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmDES,
|
||||
kCCOptionPKCS7Padding|kCCOptionECBMode,
|
||||
[key UTF8String], kCCKeySizeDES,
|
||||
iv,
|
||||
[textData bytes], dataLength,
|
||||
buffer, 20000,
|
||||
&numBytesEncrypted);
|
||||
if (cryptStatus == kCCSuccess) {
|
||||
NSData *data = [NSData dataWithBytes:buffer length:(NSUInteger)numBytesEncrypted];
|
||||
ciphertext = [Base64 encode:data];
|
||||
}
|
||||
return ciphertext;
|
||||
}
|
||||
|
||||
#pragma mark- 解密算法
|
||||
+(NSString *)decryptUseDES:(NSString *)cipherText key:(NSString *)key
|
||||
{
|
||||
NSString *plaintext = nil;
|
||||
NSData *cipherdata = [Base64 decode:cipherText];
|
||||
unsigned char buffer[20000];
|
||||
memset(buffer, 0, sizeof(char));
|
||||
size_t numBytesDecrypted = 0;
|
||||
// kCCOptionPKCS7Padding|kCCOptionECBMode 最主要在这步
|
||||
CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmDES,
|
||||
kCCOptionPKCS7Padding|kCCOptionECBMode,
|
||||
[key UTF8String], kCCKeySizeDES,
|
||||
iv,
|
||||
[cipherdata bytes], [cipherdata length],
|
||||
buffer, 20000,
|
||||
&numBytesDecrypted);
|
||||
if(cryptStatus == kCCSuccess) {
|
||||
NSData *plaindata = [NSData dataWithBytes:buffer length:(NSUInteger)numBytesDecrypted];
|
||||
plaintext = [[NSString alloc]initWithData:plaindata encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
return plaintext;
|
||||
}
|
||||
@end
|
||||
|
5
yinmeng-ios/Base/Security/yinmeng-ios-Bridging-Header.h
Normal file
5
yinmeng-ios/Base/Security/yinmeng-ios-Bridging-Header.h
Normal file
@@ -0,0 +1,5 @@
|
||||
//
|
||||
// Use this file to import your target's public headers that you would like to expose to Swift.
|
||||
//
|
||||
|
||||
#import "MAIDESEncryptTool.h"
|
47
yinmeng-ios/Base/Utils/APPUtils.swift
Normal file
47
yinmeng-ios/Base/Utils/APPUtils.swift
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// APPUtils.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by MaiMang on 2024/2/22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreTelephony
|
||||
import DeviceKit
|
||||
enum TelephonyType: String{
|
||||
case Unknow = "0"
|
||||
case Mobile = "1"
|
||||
case Unicom = "2"
|
||||
case Telecom = "3"
|
||||
}
|
||||
|
||||
|
||||
public struct APPUtils {
|
||||
static var currentCarrierName: String {
|
||||
getCurrentCarrierName()
|
||||
}
|
||||
|
||||
static var currentChannle: String {
|
||||
getCurrentChannle()
|
||||
}
|
||||
|
||||
static var appVersion: String {
|
||||
return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
|
||||
}
|
||||
|
||||
static var currentDeveiceId: String {
|
||||
var udid = UIDevice.current.identifierForVendor?.uuidString
|
||||
udid = udid?.replacingOccurrences(of: "-", with: "")
|
||||
udid = udid?.lowercased()
|
||||
return udid ?? ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private extension APPUtils {
|
||||
static func getCurrentCarrierName() -> String {
|
||||
return TelephonyType.Unicom.rawValue
|
||||
}
|
||||
|
||||
static func getCurrentChannle() -> String { return "yinmeng_appstore"}
|
||||
}
|
@@ -27,3 +27,6 @@ let SafeAraeBottomHeight = isSafeScreen ? 34.0 : 0.0
|
||||
let SafeAraeTopmHeight = isSafeScreen ? 24.0 : 0.0
|
||||
let NavHeight = (StatusBarHeight + 44)
|
||||
let TabHeight = (49)
|
||||
|
||||
|
||||
let DesKey = "1ea53d260ecf11e7b56e00163e046a26"
|
||||
|
@@ -6,7 +6,6 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
/// 遵循这个协议,可以隐藏导航栏
|
||||
protocol HiddenNavigationBarProtocol where Self: UIViewController {}
|
||||
|
||||
|
Reference in New Issue
Block a user