Skip to content

Commit

Permalink
提交修改
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanjiayou committed Apr 17, 2024
1 parent 73caab5 commit 116fdc8
Show file tree
Hide file tree
Showing 23 changed files with 1,233 additions and 47 deletions.
6 changes: 5 additions & 1 deletion .md/charles.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
- `curl -x 127.0.0.1:8888 https://www.sogou.com`
- 龟速可以在proxy的throttle菜单设置具体数值
- android7开始不信任用户安装的证书了,除非安装的包修改配置的安全参数
- ios: 电脑安装根证书(过期了需要重置)=>信任=>允许proxy的macOS proxy=> 配置HTTPS端口=> ios配置代理=> 访问chls.pro/ssl安装证书=>vpn和证书里安装(改为设置里查看安装描述文件)=> 手机关于里的通用里设置信任=>
- ios: 电脑安装根证书(过期了需要重置)=>信任=>允许proxy的macOS proxy=> 配置HTTPS端口=> ios配置代理=> 访问chls.pro/ssl安装证书=>vpn和证书里安装(改为设置里查看安装描述文件)=> 手机关于里的通用里设置信任=>
### charles安装的证书过期抓不了 https
- 打开 charles -> Help -> SSL Proxying -> reset root ca,
- SSL Proxying -> 重新安装根证书 -> 钥匙串里设置信任
- 手机设置代理 -> 访问 chls.pro/ssl 下载并安装 -> 信任,关于本机 -> 证书信任设置 -> 信任
77 changes: 77 additions & 0 deletions SwiftUI/1.webview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# webview
```swift
//
// ContentView.swift
// content-pwa
//
// Created by jiayou on 2024/03/25.
//

import SwiftUI
import WebKit
import UIKit
import Dispatch

struct WebViewContainer: UIViewRepresentable {
@Binding var urlString: String
@Binding var showAddressBar: Bool
@Binding var progress: Float
let configuration: WKWebViewConfiguration

func makeUIView(context: Context) -> WKWebView {
let webview = WKWebView(frame: .zero,configuration: configuration)
webview.navigationDelegate = context.coordinator
return webview;
}
func updateUIView (_ uiView: WKWebView, context: Context){
if let url = URL(string: urlString) {
let request = URLRequest(url: url);
uiView.load(request);
uiView.allowsBackForwardNavigationGestures = true
}
}
func makeCoordinator() -> Coordinator {
return Coordinator(parent: self)
}

class Coordinator: NSObject, WKNavigationDelegate {
var parent: WebViewContainer

init(parent: WebViewContainer) {
self.parent = parent
}

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
self.parent.urlString = webView.url?.absoluteString ?? ""
}
}

}

struct ContentView: View {
@State private var realURL: String = "http://max.local:3000/novel"
@State private var urlString: String = "http://ios.nat300.top/novel"
@State private var showAddressBar: Bool = true
@State private var progress: Float = 0
var body: some View {
// https://7ce0-27-38-191-148.ngrok-free.app
WebViewContainer(urlString: $realURL, showAddressBar: $showAddressBar, progress: $progress, configuration: createConfiguration())
.edgesIgnoringSafeArea(.all)
}

func createConfiguration() -> WKWebViewConfiguration {
let configuration = WKWebViewConfiguration()
configuration.allowsInlineMediaPlayback = true;
// 添加自定义偏好设置
let preferences = WKPreferences()
return configuration;
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

```
157 changes: 157 additions & 0 deletions SwiftUI/2.shttp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# shttp 库

```swift
//
// shttp.swift
// content-pwa
//
// Created by jiayou on 2024/04/17.
//

import Foundation
import SwiftyJSON

// 添加 SwiftyJSON 库
// 使用示例
// SHttp
// .get("https://u67631x482.vicp.fun/gw/novel/v1/public/boot")
// .send { result in
// switch result {
// case .success(let data):
// // 处理返回的数据
// let code = data["code"].int
// guard let data = try? data["data"].rawData() else {
// return
// }
// do {
// self.data = try JSONDecoder().decode(BootData.self, from: data)
// } catch{
// print("fail")
// }
// print("Received data: code: \(code ?? 0)")
// case .failure(let error):
// // 处理错误
// print("Network request failed with error: \(error)")
// }
//
// }
//}
enum NetworkError: Error {
case invalidURL
case requestFailed
case invalidResponse
case invalidData
case bizError
}

enum JSONResult {
case dictionary([String: Any])
case swiftyJSON(JSON)
case NetworkError
}

class SHttp {
static func head (_ url: String) -> Request {
return Request(url).setMethod("HEAD")
}
static func get (_ url: String) -> Request {
return Request(url).setMethod("GET")
}
static func post (_ url: String) -> Request {
return Request(url).setMethod("POST")
}
static func put (_ url: String) -> Request {
return Request(url).setMethod("PUT")
}
static func delete (_ url: String) -> Request {
return Request(url).setMethod("DELETE")
}
static func patch (_ url: String) -> Request {
return Request(url).setMethod("PATCH")
}

}

class Request {

private var url: URL?
private var method: String = "GET"
private var query: [URLQueryItem]?
private var body: Data?
private var headers: [String: String]?

init(_ url: String) {
self.url = URL(string: url)
}

func setMethod(_ method: String) -> Request {
self.method = method
return self
}

func setQuery(_ query: [URLQueryItem]) -> Request {
self.query = query
return self
}

func setBody(_ body: Data) -> Request {
self.body = body
return self
}

func setHeaders(_ headers: [String: String]) -> Request {
self.headers = headers
return self
}

func send(completion: @escaping (Result<JSON, NetworkError>) -> Void) {
guard let url = self.url else {
completion(.failure(.invalidURL))
return
}

var components = URLComponents(url: url, resolvingAgainstBaseURL: false)
components?.queryItems = self.query

guard let finalURL = components?.url else {
completion(.failure(.invalidURL))
return
}

var request = URLRequest(url: finalURL)
request.httpMethod = method
request.httpBody = body

if let headers = headers {
for (key, value) in headers {
request.setValue(value, forHTTPHeaderField: key)
}
}

let session = URLSession.shared
let task = session.dataTask(with: request) { data, response, error in
guard error == nil else {
completion(.failure(.requestFailed))
return
}

guard let httpResponse = response as? HTTPURLResponse, (200...299).contains(httpResponse.statusCode) else {
completion(.failure(.invalidResponse))
return
}

guard let data = data else {
completion(.failure(.invalidData))
return
}

// 将数据转换为 JSON 对象
let json = JSON(data)
completion(.success(json))
return
}
task.resume()
}
}

```
Loading

0 comments on commit 116fdc8

Please sign in to comment.