我如何在另一个函数中使用retailId(来自flatMapLatest)
Posted
技术标签:
【中文标题】我如何在另一个函数中使用retailId(来自flatMapLatest)【英文标题】:how i can use retailId(from flatMapLatest) in another func 【发布时间】:2019-05-24 11:00:26 【问题描述】:视图模型:
searchButtonInDidTapSubject.withLatestFrom(retailIdSubject.map text in return text).flatMapLatest [unowned self] retailId in
return service.searchRetailPayCashBack(retailId: retailId, createdAt: self.createdDates, sig: self.sig).materialize();
.subscribe(onNext: [weak self] event in
switch (event)
case .next(_):
self?.checkResultSubject.onNext(true)
break;
case .error(let error):
self?.errorSubject.onNext(error as! ErrorResponse);
break;
default:
break;
).disposed(by: disposeBag);
//这里我需要转换retailId、currentTime和accessToken 之后我发送请求 api
private var sig: String
get
let accessToken = self.keychain.get(Constants.accessToken)
// ???
let newAccessToken = String((accessToken?.substring(with: 11..<21))!)
let retailid = ???
let newSig = "\(newAccessToken)\(self.createdDates)\(retailid)"
let md5Base64 = newSig.base64Encoded()
let md5Data = self.MD5(md5Base64!)
return String(md5Data!)
retailId 需要等于retailid
【问题讨论】:
【参考方案1】:不确定您要达到什么目的,但听起来每次点击按钮时都应该生成sig
,因为retailId 可能不同。
searchButtonInDidTapSubject
.withLatestFrom(retailIdSubject.map text in return text )
.flatMapLatest [unowned self] retailId in
return service
.searchRetailPayCashBack(
retailId: retailId,
createdAt: self.createdDates,
sig: self.sig(withRetailId: retailId, createdDate: self.createdDates)
)
.materialize()
.subscribe(onNext: [weak self] event in
switch (event)
case .next(_):
self?.checkResultSubject.onNext(true)
break;
case .error(let error):
self?.errorSubject.onNext(error as! ErrorResponse);
break;
default:
break;
)
.disposed(by: disposeBag)
func sig(withRetailId retailId: String, createdDate: String) -> String
let accessToken = self.keychain.get(Constants.accessToken)
// ???
let newAccessToken = String((accessToken?.substring(with: 11..<21))!)
let newSig = "\(newAccessToken)\(createdDate)\(retailId)"
let md5Base64 = newSig.base64Encoded()
let md5Data = self.MD5(md5Base64!)
return String(md5Data!)
【讨论】:
以上是关于我如何在另一个函数中使用retailId(来自flatMapLatest)的主要内容,如果未能解决你的问题,请参考以下文章
无法在另一个 python 脚本中使用来自 python 函数的属性