Commit c3e7ca4e authored by Steven杜宇's avatar Steven杜宇

// 阿里云日志

parent 644fd013
......@@ -11,10 +11,7 @@ import AliyunLogProducer
enum YHAliYunLogKey: String {
case moduleNameNetworkDataType = "moduleName-networkDataType" // 网络数据
case moduleNameH5InteractionType = "moduleName-h5InteractionType" // 与H5交互相关
case moduleNameClickType = "moduleName-clickType" // 用户点点击事件
case moduleName = "moduleName" // 模块名
case mobile = "mobile" // 当前登录用户的手机号码
case remark = "remark" // 可以随意上传内容
case timestamp = "timestamp" // 时间戳
......@@ -25,6 +22,12 @@ enum YHAliYunLogKey: String {
case os_version_name = "os_version_name" // 操作系统版本号
}
enum YHModuleNameValue: String {
case networkDataType = "networkDataType" // 网络数据
case h5InteractionType = "h5InteractionType" // 与H5交互相关
case clickType = "clickType" // 用户点点击事件
}
class YHAliYunLogManager {
static let SLS_ENDPOINT = "cn-shenzhen.log.aliyuncs.com"
......@@ -57,11 +60,11 @@ class YHAliYunLogManager {
accessKeyID: SLS_KEY,
accessKeySecret: SLS_SECRET)
// 设置日志主题
config?.setTopic("example_topic")
// config?.setTopic("example_topic")
// 设置日志来源。
config?.setSource("your new-source")
// config?.setSource("your new-source")
// 设置tag信息,此tag信息将被附加在每条日志上。
config?.addTag("example", value: "example_tag")
// config?.addTag("example", value: "example_tag")
// 是否丢弃过期日志。0表示不丢弃,把日志时间修改为当前时间; 1表示丢弃。默认值为1。
config?.setDropDelayLog(1)
// 是否丢弃鉴权失败的日志,0表示不丢弃,1表示丢弃。默认值为0。
......@@ -85,4 +88,40 @@ class YHAliYunLogManager {
log.putContent("银河移动开发组效忠宣言", value: "坚决拥护龙的领导,团结在龙的周围,凡是龙的决策,我们都坚决维护,凡是龙的指示,我们都始终不渝地遵循")
client?.add(log)
}
func addModuleName(_ moduleName: YHModuleNameValue, remark: String) {
let log = Log()
addCommonInfoLog(log)
log.putContent(YHAliYunLogKey.moduleName.rawValue, value: moduleName.rawValue)
log.putContent(YHAliYunLogKey.remark.rawValue, value: remark)
client?.add(log)
}
func addModuleName(_ moduleName: YHModuleNameValue, remark: [AnyHashable:Any]) {
let log = Log()
addCommonInfoLog(log)
log.putContent(YHAliYunLogKey.moduleName.rawValue, value: moduleName.rawValue)
log.putContent(YHAliYunLogKey.remark.rawValue, dictValue: remark)
client?.add(log)
}
private func addCommonInfoLog(_ log: Log) {
// 当前登录用户的手机号码
if YHLoginManager.shared.isLogin(), let mobile = YHLoginManager.shared.userModel?.mobile, !mobile.isEmpty {
log.putContent(YHAliYunLogKey.mobile.rawValue, value: mobile)
}
// 系统、平台
log.putContent(YHAliYunLogKey.app_platform.rawValue, value: "iOS")
// app版本号
log.putContent(YHAliYunLogKey.app_version.rawValue, value: UIDevice.appVersion())
// app渠道号
log.putContent(YHAliYunLogKey.app_channel.rawValue, value: "appStore")
// 手机型号
log.putContent(YHAliYunLogKey.app_phoneModel.rawValue, value: UIDevice.iPhoneModelName())
// 操作系统版本号
log.putContent(YHAliYunLogKey.os_version_name.rawValue, value: UIDevice.iPhoneVersion())
// 当前时间戳
log.putContent(YHAliYunLogKey.timestamp.rawValue, value: String(Date().timeIntervalSince1970))
}
}
......@@ -30,6 +30,9 @@ class YHAppleLoginViewModel: NSObject {
//数据保存到本地
YHLoginManager.shared.saveLocalUserInfo()
let newDic = dic.merging(["op_type": "login"]) { (current, _) in current }
YHAliYunLogManager.shared.addModuleName(.networkDataType, remark: newDic)
NotificationCenter.default.post(name: YhConstant.YhNotification.didLoginSuccessNotifiction, object: nil)
callBackBlock(true,nil)
......
......@@ -55,6 +55,9 @@ class YHOneKeyLoginViewModel {
//数据保存到本地
YHLoginManager.shared.saveLocalUserInfo()
let newDic = dic.merging(["op_type": "login"]) { (current, _) in current }
YHAliYunLogManager.shared.addModuleName(.networkDataType, remark: newDic)
NotificationCenter.default.post(name: YhConstant.YhNotification.didLoginSuccessNotifiction, object: nil)
//回调
......
......@@ -57,6 +57,8 @@ class YHHomeHoldViewPageViewController: YHBaseViewController {
var needReloadDataFlag : Bool = false
let loginViewModel = YHLoginViewModel()
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
......@@ -361,6 +363,18 @@ extension YHHomeHoldViewPageViewController {
self.segmentedView.selectItemAt(index: itemIndex)
self.listContainerView.didClickSelectedItem(at: itemIndex)
}
func getCurrentUserInfo() {
if !YHLoginManager.shared.isLogin() {
return
}
guard let mobile = YHLoginManager.shared.userModel?.mobile else {
return
}
self.loginViewModel.getUserInfo { success, error in
}
}
}
//MARK: - JXSegmentedViewDelegate
......
......@@ -74,6 +74,9 @@ extension YHLoginViewModel {
//数据保存到本地
YHLoginManager.shared.saveLocalUserInfo()
let newDic = dic.merging(["op_type": "login"]) { (current, _) in current }
YHAliYunLogManager.shared.addModuleName(.networkDataType, remark: newDic)
NotificationCenter.default.post(name: YhConstant.YhNotification.didLoginSuccessNotifiction, object: nil)
//回调
......@@ -165,6 +168,9 @@ extension YHLoginViewModel {
//数据保存到本地
YHLoginManager.shared.saveLocalUserInfo()
let newDic = dic.merging(["op_type": "login"]) { (current, _) in current }
YHAliYunLogManager.shared.addModuleName(.networkDataType, remark: newDic)
NotificationCenter.default.post(name: YhConstant.YhNotification.didLoginSuccessNotifiction, object: nil)
//回调
......@@ -202,4 +208,29 @@ extension YHLoginViewModel {
callBack?("")
}
}
func getUserInfo(callBackBlock: @escaping (_ success: Bool,_ error:YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.User.verifyCode
let _ = YHNetRequest.postRequest(url: strUrl) {[weak self] json, code in
guard self != nil else { return }
//1. json字符串 转 对象
if json.code == 200 {
if let dic = json.data?.peel as? [AnyHashable : Any] {
if let mobile = dic["mobile"] as? String {
YHLoginManager.shared.userModel?.mobile = mobile
}
}
callBackBlock(true, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code),errorMsg: json.msg)
callBackBlock(false, error)
}
} failBlock: { error in
callBackBlock(false, error)
}
}
}
......@@ -173,6 +173,7 @@ class YHMySettingViewController: YHBaseViewController, ConstraintRelatableTarget
if success {
DispatchQueue.main.async {
YHHUD.flash(message: "退出成功")
YHAliYunLogManager.shared.addModuleName(.networkDataType, remark: "logout")
YHLoginManager.shared.clearUserInfo()
NotificationCenter.default.post(name: YhConstant.YhNotification.didLogoutSuccessNotifiction, object: nil)
// 发送清空所有未读消息通知
......
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